diff --git a/DSTAT-temp/src/ads1255.c b/DSTAT-temp/src/ads1255.c index d0ba56fef041a482fde4071443683bc1edcda589..745271fee42579e1564cc351ac045cc13f1e0a5a 100644 --- a/DSTAT-temp/src/ads1255.c +++ b/DSTAT-temp/src/ads1255.c @@ -86,7 +86,13 @@ void ads1255_reset(){ } void ads1255_setup(uint8_t buff, uint8_t rate, uint8_t pga){ - uint8_t command_buffer[6] = {0x50,0x03,buff,0x01,pga,rate}; + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 1 + uint8_t command_buffer[6] = {0x50,0x03,buff,0x01,pga,rate}; // write reg 0, write 4 registers, analog buffer, MUX AIN0-AIN1, pga, rate + #endif + + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 + uint8_t command_buffer[6] = {0x50,0x03,buff,0x08,pga,rate}; // write reg 0, write 4 registers, analog buffer, MUX AIN0-AINCOM, pga, rate + #endif usart_spi_select_device(&USARTE1, &spi_device_conf); usart_spi_transmit(&USARTE1, ADS_SDATAC); @@ -101,6 +107,24 @@ void ads1255_setup(uint8_t buff, uint8_t rate, uint8_t pga){ return; } +void ads1255_mux(uint8_t channel){ + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 + uint8_t command_buffer[6] = {0x51,0x0,channel}; // write reg 1, write 1 register, MUX AIN0 + + usart_spi_select_device(&USARTE1, &spi_device_conf); + usart_spi_transmit(&USARTE1, ADS_SDATAC); + usart_spi_write_packet(&USARTE1, (uint8_t*)&command_buffer, 3); + usart_spi_transmit(&USARTE1, ADS_SYNC); + usart_spi_transmit(&USARTE1, ADS_SELFCAL); + while (arch_ioport_get_pin_level(IOPORT_CREATE_PIN(PORTD, 5))) + ; + usart_spi_deselect_device(&USARTE1, &spi_device_conf); + + return; + #endif + +} + void ads1255_standby(void){ usart_spi_select_device(&USARTE1, &spi_device_conf); usart_spi_transmit(&USARTE1, ADS_STANDBY); diff --git a/DSTAT-temp/src/ads1255.h b/DSTAT-temp/src/ads1255.h index 7755d0aa416ee18822761d3b4e2c84748b473da1..f01d2d59895fd6a926af2332ffccf87d10a40f56 100644 --- a/DSTAT-temp/src/ads1255.h +++ b/DSTAT-temp/src/ads1255.h @@ -59,6 +59,9 @@ #define ADS_BUFF_OFF 0b0000 //0x0 #define ADS_BUFF_ON 0b0010 //0x2 +#define ADS_MUX_VOLT 0x08 +#define ADS_MUX_POT 0x18 + void ads1255_sync(void); void ads1255_init_pins(void); void ads1255_init_module(void); @@ -68,6 +71,7 @@ int32_t ads1255_read_fast24(void); void ads1255_reg_read(uint8_t address); void ads1255_reset(void); void ads1255_setup(uint8_t buff, uint8_t rate, uint8_t pga); +void ads1255_mux(uint8_t channel); void ads1255_standby(void); void ads1255_wakeup(void); void ads1255_rdatac(void); diff --git a/DSTAT-temp/src/config/conf_clock.h b/DSTAT-temp/src/config/conf_clock.h index 0f2eb959772f41744f53874643fd834ba4bec592..16e2e72cbdfb889406754f9785d7f3c68fc7bfd7 100644 --- a/DSTAT-temp/src/config/conf_clock.h +++ b/DSTAT-temp/src/config/conf_clock.h @@ -44,22 +44,22 @@ #define CONF_CLOCK_H_INCLUDED //#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RC2MHZ -#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RC32MHZ +//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RC32MHZ //#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RC32KHZ //#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_XOSC -//#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_PLL +#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_PLL /* Fbus = Fsys / (2 ^ BUS_div) */ #define CONFIG_SYSCLK_PSADIV SYSCLK_PSADIV_1 #define CONFIG_SYSCLK_PSBCDIV SYSCLK_PSBCDIV_1_1 //#define CONFIG_PLL0_SOURCE PLL_SRC_XOSC -//#define CONFIG_PLL0_SOURCE PLL_SRC_RC2MHZ +#define CONFIG_PLL0_SOURCE PLL_SRC_RC2MHZ //#define CONFIG_PLL0_SOURCE PLL_SRC_RC32MHZ /* Fpll = (Fclk * PLL_mul) / PLL_div */ -//#define CONFIG_PLL0_MUL (24000000UL / BOARD_XOSC_HZ) -//#define CONFIG_PLL0_DIV 1 +#define CONFIG_PLL0_MUL 16 +#define CONFIG_PLL0_DIV 1 /* External oscillator frequency range */ /** 0.4 to 2 MHz frequency range */ @@ -72,7 +72,7 @@ //#define CONFIG_XOSC_RANGE XOSC_RANGE_12TO16 /* DFLL autocalibration */ -//#define CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC OSC_ID_RC32KHZ +#define CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC OSC_ID_RC32KHZ //#define CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC OSC_ID_XOSC /* The following example clock configuration definitions can be used in XMEGA diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c index cfab49ed6e2eacacbb14a4c7a1997370e629517f..12648828539378ae0c2a6222bd8d940f9a8c1448 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -225,18 +225,35 @@ void volt_exp_start(void){ } -void pot_exp_stop(void){ +void volt_exp_stop(void){ /** - * Disconnects measurement cell and shorts RE and CE terminals. + * Disconnects measurement cell. */ #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 1 arch_ioport_set_port_level(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm, 0); #endif #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 - arch_ioport_set_port_level(IOPORT_PORTB, PIN2_bm|PIN3_bm|PIN4_bm|PIN5_bm, PIN3_bm); + arch_ioport_set_port_level(IOPORT_PORTB, PIN2_bm|PIN3_bm|PIN4_bm|PIN5_bm, 0); #endif } +#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR >= 2 +void pot_exp_start(void){ + /** + * All switches open. + */ + 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 /** * Performs experiment preconditioning. @@ -302,7 +319,7 @@ void precond(int16_t v1, uint16_t t1, int16_t v2, uint16_t t2){ //assumes potent } aborting: - pot_exp_stop(); + volt_exp_stop(); return; } @@ -518,7 +535,7 @@ uint8_t lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first tc_disable(&TCC0); TCC0.CNT = 0x0; tc_disable(&TCC1); - pot_exp_stop(); + volt_exp_stop(); ads1255_standby(); return ret; } @@ -564,6 +581,78 @@ static void lsv_cca_callback(void){ return; } +#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR >= 2 + +void pot_experiment(uint16_t time_seconds, uint8_t exp_type){ + /** + * Performs a potentiometry experiment. + * + * @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; + 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); + + 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()){ + 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. @@ -593,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]); @@ -621,7 +711,7 @@ void ca_experiment(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]) 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(); + volt_exp_stop(); ads1255_standby(); return; @@ -745,7 +835,7 @@ void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h printf("D\n\r"); //signal end of experiment aborting: - pot_exp_stop(); + volt_exp_stop(); tc_write_clock_source(&TCF0, TC_CLKSEL_OFF_gc); tc_disable(&TCF0); TCF0.CNT = 0; @@ -915,7 +1005,7 @@ void dpv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h printf("D\n\r"); //signal end of experiment aborting: - pot_exp_stop(); + volt_exp_stop(); tc_write_clock_source(&TCF0, TC_CLKSEL_OFF_gc); tc_disable(&TCF0); TCF0.CNT = 0; diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h index 2de19abb9d546b297ef8920c4a5a6da2925cc1b7..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 @@ -77,10 +80,17 @@ void send_data_int32(int32_t data); void pot_init(void); void pot_set_gain(void); void volt_exp_start(void); -void pot_exp_stop(void); +void volt_exp_stop(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 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[]); 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/DSTAT-temp/src/main.c b/DSTAT-temp/src/main.c index c1c5377f2a5c2b021dd4af378968c45005acff22..14c3156ea55c4eea725cc98e379ab3115f59dc60 100644 --- a/DSTAT-temp/src/main.c +++ b/DSTAT-temp/src/main.c @@ -66,6 +66,13 @@ int8_t command_handler(char command){ dpv_experiment(p1,p2,u1,u2,u3,u4); break; + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR >= 2 + case 'P': //potentiometry - time, OCP/poteniometry + scanf("%u%hhu",&pct1, &o1); + pot_experiment(pct1, o1); + break; + #endif + case 'R': //CA - steps, step_dac[], step_seconds[] scanf("%hhu",&p5); //get number of steps printf("#Steps: %u\n\r", p5); @@ -99,6 +106,11 @@ int8_t command_handler(char command){ free(step_seconds); break; + + case 'V': //check version + printf("V%u.%u\n", BOARD_VER_MAJOR, BOARD_VER_MINOR); + break; + default: printf("#ERR: Command %c not recognized\n\r", command); return 1; diff --git a/DSTAT1.atsuo b/DSTAT1.atsuo index d2d0d86415d040b474d80ff4fe0cfd171ad96fd8..4d502164b15ef896773355c66b2977e4db83774e 100644 Binary files a/DSTAT1.atsuo and b/DSTAT1.atsuo differ