diff --git a/DSTAT-temp/src/config/conf_usb.h b/DSTAT-temp/src/config/conf_usb.h index 03219f89eb9b34df5dbf39b277f978a3ceb4fee2..4a28c2eec24f809d57e30300cd7a43fdca2d0ef2 100644 --- a/DSTAT-temp/src/config/conf_usb.h +++ b/DSTAT-temp/src/config/conf_usb.h @@ -52,8 +52,8 @@ */ //! Device definition (mandatory) -#define USB_DEVICE_VENDOR_ID 0x0042 -#define USB_DEVICE_PRODUCT_ID 0x0002 +#define USB_DEVICE_VENDOR_ID 0x03EB +#define USB_DEVICE_PRODUCT_ID USB_PID_ATMEL_MEGA_CDC #define USB_DEVICE_MAJOR_VERSION 1 #define USB_DEVICE_MINOR_VERSION 1 #define USB_DEVICE_POWER 200 // Consumption on Vbus line (mA) diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c index 49b008912cf8010280f5eb3b77ea16582047659d..4044b93bc7cc045cf735465fa3d3e0204c45dfdb 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -245,20 +245,23 @@ void cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_ while(scans > 0){ if (start != v1){ - lsv_experiment(start,v1,slope,firstrun); + if (lsv_experiment(start,v1,slope,firstrun) == 1) + return; firstrun = 0; } if (start == v2 && scans == 1) firstrun = -1; - lsv_experiment(v1,v2,slope,firstrun); + if (lsv_experiment(v1,v2,slope,firstrun) == 1) + return; if (scans == 1) firstrun = -1; if (start != v2) - lsv_experiment(v2,start,slope,firstrun); + if(lsv_experiment(v2,start,slope,firstrun) == 1) + return; --scans; firstrun = 0; @@ -271,7 +274,7 @@ void cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_ return; } -void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run){ +uint8_t lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run){ /** * Perform a LSV experiment. * @@ -282,11 +285,13 @@ void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_ru * @param first_run Keeps track of number of scans so potentiostat isn't initialized twice or disconnected when doing CV. Set to 2 for normal LSV. */ + uint8_t ret = 0; + //check experiment limits if(start<-1500 || start>=1500 ||start==stop|| stop<-1500 || stop>=1500 || slope>7000) { printf("#ERR: Experiment parameters outside limits\n\r"); - return; + return ret; } uint16_t dacindex_start = ceil(start*(65536/(double)3000)+32768); @@ -294,6 +299,7 @@ void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_ru uint32_t timer_period; uint16_t temp_div; + max5443_set_voltage1(dacindex_start); if (first_run == 1 || first_run == 2){ @@ -344,7 +350,7 @@ void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_ru } else{ printf("ERR: Frequency/ADC rate is too low\n\r"); - return; + return ret; } //printf("Period:%lu\n\r", timer_period); @@ -376,18 +382,30 @@ void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_ru tc_write_clock_source(&TCC1, TC_CLKSEL_EVCH0_gc); - while (up != 0); //Experiment run with interrupts + //Experiment run with interrupts + while (up != 0){ + if (udi_cdc_is_rx_ready()){ + if (getchar()=='a'){ + tce1_ovf_callback_lsv(); + ret = 1; + goto aborting; + + } + } + } if (first_run == -1 || first_run == 2) { - tc_disable(&TCC0); - TCC0.CNT = 0x0; - tc_disable(&TCC1); - pot_exp_stop(); - ads1255_standby(); + aborting: + tc_disable(&TCC0); + TCC0.CNT = 0x0; + tc_disable(&TCC1); + pot_exp_stop(); + ads1255_standby(); + return ret; } - return; + return ret; } static void porte_int0_lsv(void){ @@ -468,16 +486,25 @@ void ca_experiment(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]) max5443_set_voltage1(step_dac[i]); printf("#DAC: %u\n\r", step_dac[i]); PORTD.INTCTRL = PORT_INT0LVL_LO_gc; - while (up !=0); + while (up !=0){ + if (udi_cdc_is_rx_ready()){ + if (getchar() == 'a'){ + ca_cca_callback(); + printf("##ABORT\n\r"); + goto aborting; + } + } + } } - tc_set_cca_interrupt_level(&TCC0, TC_INT_LVL_OFF); - tc_write_clock_source(&TCC0, TC_CLKSEL_OFF_gc); - tc_disable(&TCC0); - pot_exp_stop(); - ads1255_standby(); + aborting: + tc_set_cca_interrupt_level(&TCC0, TC_INT_LVL_OFF); + tc_write_clock_source(&TCC0, TC_CLKSEL_OFF_gc); + tc_disable(&TCC0); + pot_exp_stop(); + ads1255_standby(); - return; + return; } static void portd_int0_ca(void){ @@ -595,6 +622,10 @@ void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); //wait for next valid datum while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); forward = ads1255_read_fast24(); + if (udi_cdc_is_rx_ready()){ + if (getchar() == 'a') + goto aborting; + } } if (direction == 1) //switch voltage to other half of cycle @@ -613,6 +644,11 @@ void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); //wait for next valid datum while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); reverse = ads1255_read_fast24(); + + if (udi_cdc_is_rx_ready()){ + if (getchar() == 'a') + goto aborting; + } } //at new dacindex @@ -622,14 +658,14 @@ void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h max5443_set_voltage1(dacindex-dacindex_pulse_height); } + aborting: + pot_exp_stop(); + tc_write_clock_source(&TCF0, TC_CLKSEL_OFF_gc); + tc_disable(&TCF0); + TCF0.CNT = 0; + ads1255_standby(); - pot_exp_stop(); - tc_write_clock_source(&TCF0, TC_CLKSEL_OFF_gc); - tc_disable(&TCF0); - TCF0.CNT = 0; - ads1255_standby(); - - return; + return; } ISR(PORTD_INT0_vect){ diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h index 75c66d596511f8b0763eb85e606e1e9e89ca33f6..9903c1bce40d6155d7956e0308fb11d0db4bd2ce 100644 --- a/DSTAT-temp/src/experiment.h +++ b/DSTAT-temp/src/experiment.h @@ -64,7 +64,7 @@ void pot_set_gain(void); void pot_exp_start(void); void pot_exp_stop(void); void cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_t slope); -void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run); +uint8_t lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run); void ca_experiment(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]); void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_height, uint16_t frequency); diff --git a/DSTAT-temp/src/main.c b/DSTAT-temp/src/main.c index 8474af888e09a9274a3f754d0dd9d589a411cb9f..e792d10b708807145e7b4ab1ed8200b8f4a4b96a 100644 --- a/DSTAT-temp/src/main.c +++ b/DSTAT-temp/src/main.c @@ -11,6 +11,7 @@ int16_t p1, p2, p3, p4; uint16_t u1, u2, u3; uint8_t p5, o1, o2, o3; + //uint16_t step_dac[50], step_seconds[50]; //Internal function declarations @@ -39,7 +40,6 @@ int8_t command_handler(char command){ case 'L': //LSV - start, stop, slope scanf("%i%i%u",&p1,&p2,&u1); - //printf("%i,%i,%i",&p1,&p2,&u1); lsv_experiment(p1,p2,u1,2); break; @@ -94,7 +94,7 @@ int8_t command_handler(char command){ } int main(void){ - + board_init(); pot_init(); pmic_init(); @@ -135,54 +135,16 @@ int main(void){ break; printf("\n\r"); } - -// sine wave test -// #define DAC_PER_4 2 -// -// uint16_t i; -// uint16_t delta[DAC_PER_4]; -// -// for (i=0; i 0; i--) -// { -// max5443_set_voltage1(32768+delta[i]); -// //printf("%u \r\n",delta[i]); -// } -// for (i = 0; i < DAC_PER_4; i++) -// { -// max5443_set_voltage1(32768-delta[i]); -// //printf("%u \r\n",delta[i]); -// } -// -// for (i = DAC_PER_4-1; i > 0; i--) -// { -// max5443_set_voltage1(32768-delta[i]); -// //printf("%u \r\n",delta[i]); -// } -// } ads1255_setup(ADS_BUFF_ON,ADS_DR_60,ADS_PGA_2); autogain_enable = 0; g_gain = POT_GAIN_30k; pot_set_gain(); -// max5443_set_voltage1(-1000*(65536/(double)3000)+32768); -// step_dac[0] = 32768/*(double)3.8*(65536/(double)3000)+32768*/; -// step_seconds[0] = 10; - while (1){ + program_loop: while(getchar() != '!'); printf ("C\r\n"); command_handler(getchar()); - } + goto program_loop; } \ No newline at end of file diff --git a/DSTAT-temp/src/main.h b/DSTAT-temp/src/main.h index 928703f5c9e0aee8f04785352cf41b43b8a58af8..654991c56d78c904dc5a21cddc32fd5dfd74fcbd 100644 --- a/DSTAT-temp/src/main.h +++ b/DSTAT-temp/src/main.h @@ -19,15 +19,6 @@ int8_t autogainswitch(void); void menu(uint8_t selection); //void pot_set_gain(/*uint8_t*/ potgain_t gain); //void pot_LP(uint8_t lponoff); -void pot_exp_start(void); -void pot_exp_stop(void); -void sw_test(uint16_t frequency); -void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run); -void cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_t slope); -void chronoamp(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]); -void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_height, uint16_t frequency); -void eis_waveform(int16_t offset, int16_t amplitude, uint32_t freq, uint16_t cycles); - #define MENU_LSV 1 #define MENU_CV 2 diff --git a/DSTAT1.atsuo b/DSTAT1.atsuo index e7185ef389aa30a249f496141a96d58cc3d07d0d..02813580598e1c5edc3854b63fb51a19957f7435 100644 Binary files a/DSTAT1.atsuo and b/DSTAT1.atsuo differ