diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c index d209962a7f3d16b0c751409af916e11cba402a17..03e92f413796247713b790013e30435b0715d9e8 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -237,6 +237,15 @@ void volt_exp_stop(void){ #endif } +void pot_exp_start(void){ + /** + * All switches open. + */ + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 + arch_ioport_set_port_level(IOPORT_PORTB, PIN2_bm|PIN3_bm|PIN4_bm|PIN5_bm, 0); + #endif +} + void precond(int16_t v1, uint16_t t1, int16_t v2, uint16_t t2){ //assumes potentiostat switches are already set /** * Performs experiment preconditioning. @@ -564,6 +573,67 @@ static void lsv_cca_callback(void){ return; } +#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 + +void pot_experiment(uint16_t time_seconds){ + /** + * Performs a potentiometry experiment. Assumes either pot_exp_start() or ocp_exp_start() has been called and appropriate switches are set. + * + * @param time_seconds Time until automatic stop. If 0, can only be cancelled by abort signal. + */ + while (RTC.STATUS & RTC_SYNCBUSY_bm); + RTC.PER = 999; + while (RTC.STATUS & RTC_SYNCBUSY_bm); + RTC.CTRL = RTC_PRESCALER_DIV1_gc; //1ms tick + RTC.CNT = 0; + + EVSYS.CH0MUX = EVSYS_CHMUX_RTC_OVF_gc; //EV CH0 -- RTC overflow 1s + + portd_int0_callback = portd_int0_ca; //ADC interrupt + + tc_enable(&TCC0); + + ads1255_mux(ADS_MUX_POT); + ads1255_rdatac(); + ads1255_wakeup(); + + tc_write_period(&TCC0,0xffff); + tc_write_clock_source(&TCC0, TC_CLKSEL_EVCH0_gc); + tc_set_direction(&TCC0, TC_UP); + TCC0.CNT = 0; + + up = 1; + if (time_seconds >= 1){ //only enable interrupt if non-zero timeout specified + tc_set_cca_interrupt_callback(&TCC0, ca_cca_callback); + tc_write_cc(&TCC0, TC_CCA, time_seconds-1); + tc_enable_cc_channels(&TCC0, TC_CCAEN); + tc_set_cca_interrupt_level(&TCC0, TC_INT_LVL_MED); + } + + RTC.CNT=0; + PORTD.INTCTRL = PORT_INT0LVL_LO_gc; + + while (up !=0){ + if (udi_cdc_is_rx_ready()){ + if (getchar() == 'a'){ + ca_cca_callback(); + printf("##ABORT\n\r"); + goto aborting; + } + } + } + + aborting: + tc_set_cca_interrupt_level(&TCC0, TC_INT_LVL_OFF); + tc_write_clock_source(&TCC0, TC_CLKSEL_OFF_gc); + tc_disable(&TCC0); + volt_exp_stop(); + ads1255_standby(); + + return; +} +#endif + void ca_experiment(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]){ /** * Performs a chronoamperometry experiment. diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h index 943d15a42ae10169f3aa2e27fe94b1949f3274cc..a8a00f6ccf5e05922c5c26228e0fe1595cf3f937 100644 --- a/DSTAT-temp/src/experiment.h +++ b/DSTAT-temp/src/experiment.h @@ -78,9 +78,15 @@ void pot_init(void); void pot_set_gain(void); void volt_exp_start(void); void volt_exp_stop(void); +void pot_exp_start(void); void precond(int16_t v1, uint16_t t1, int16_t v2, uint16_t t2); void cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_t slope); uint8_t lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run); + +#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 + void pot_experiment(uint16_t time_seconds); +#endif + 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, uint16_t scans); void dpv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_height, uint16_t pulse_period, uint16_t pulse_width); diff --git a/DSTAT1.atsuo b/DSTAT1.atsuo index bc336d114d679c8f911ab15af332082573992a49..7e2408b7311fdb99ece7cd1647659109e2be695c 100644 Binary files a/DSTAT1.atsuo and b/DSTAT1.atsuo differ