diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c index 03e92f413796247713b790013e30435b0715d9e8..6d7935bec22ac48450c2652df091e34c52f3e373 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -237,14 +237,22 @@ void volt_exp_stop(void){ #endif } +#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR >= 2 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 + arch_ioport_set_port_level(IOPORT_PORTB, PIN2_bm|PIN3_bm|PIN4_bm|PIN5_bm, 0); + +} + +void ocp_exp_start(void){ + /** + * U3C closed + */ + arch_ioport_set_port_level(IOPORT_PORTB, PIN2_bm|PIN3_bm|PIN4_bm|PIN5_bm, PIN4_bm); } +#endif void precond(int16_t v1, uint16_t t1, int16_t v2, uint16_t t2){ //assumes potentiostat switches are already set /** @@ -573,13 +581,14 @@ static void lsv_cca_callback(void){ return; } -#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 +#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR >= 2 -void pot_experiment(uint16_t time_seconds){ +void pot_experiment(uint16_t time_seconds, uint8_t exp_type){ /** - * Performs a potentiometry experiment. Assumes either pot_exp_start() or ocp_exp_start() has been called and appropriate switches are set. + * Performs a potentiometry experiment. * - * @param time_seconds Time until automatic stop. If 0, can only be cancelled by abort signal. + * @param time_seconds Time until automatic stop. If 0, can only be canceled by abort signal. + * @param exp_type Type of experiment, POT_OCP for OCP, POT_POTENT for potentiometry */ while (RTC.STATUS & RTC_SYNCBUSY_bm); RTC.PER = 999; @@ -600,18 +609,28 @@ void pot_experiment(uint16_t time_seconds){ 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_clear_cc_interrupt(&TCC0, TC_CCA); tc_set_cca_interrupt_level(&TCC0, TC_INT_LVL_MED); } + + if (exp_type == POT_OCP) + { + ocp_exp_start(); + } + else if (exp_type == POT_POTENT) + { + pot_exp_start(); + } RTC.CNT=0; PORTD.INTCTRL = PORT_INT0LVL_LO_gc; + TCC0.CNT = 0; while (up !=0){ if (udi_cdc_is_rx_ready()){ @@ -663,6 +682,7 @@ void ca_experiment(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]) tc_set_direction(&TCC0, TC_UP); tc_enable_cc_channels(&TCC0, TC_CCAEN); tc_set_cca_interrupt_level(&TCC0, TC_INT_LVL_MED); + TCC0.CNT = 0; max5443_set_voltage1(step_dac[0]); diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h index a8a00f6ccf5e05922c5c26228e0fe1595cf3f937..4d270407b4b530f8dda9ddbdbed926e7ff89602e 100644 --- a/DSTAT-temp/src/experiment.h +++ b/DSTAT-temp/src/experiment.h @@ -45,6 +45,9 @@ #define POT_GAIN_100M 7 #endif +#define POT_OCP 0 +#define POT_POTENT 1 + #define POT_LP_OFF 0 #define POT_LP_ON 1 @@ -78,13 +81,14 @@ 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); +#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR >= 2 +void ocp_exp_start(void); +void pot_exp_start(void); +void pot_experiment(uint16_t time_seconds, uint8_t exp_type); #endif void ca_experiment(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]);