diff --git a/DSTAT-temp/src/config/conf_board.h b/DSTAT-temp/src/config/conf_board.h index 80fd2f0ad653b066b9e3b54275f12239b2cd41b5..ca27c6d7183c7c61eff220cb2ed7a657bb9487f8 100644 --- a/DSTAT-temp/src/config/conf_board.h +++ b/DSTAT-temp/src/config/conf_board.h @@ -8,4 +8,7 @@ #ifndef CONF_BOARD_H #define CONF_BOARD_H +#define BOARD_VER_MAJOR 1 +#define BOARD_VER_MINOR 2 + #endif // CONF_BOARD_H diff --git a/DSTAT-temp/src/config/conf_usb.h b/DSTAT-temp/src/config/conf_usb.h index 4a28c2eec24f809d57e30300cd7a43fdca2d0ef2..61be98ec0c12a25663cfc0ae932d55b6d438690d 100644 --- a/DSTAT-temp/src/config/conf_usb.h +++ b/DSTAT-temp/src/config/conf_usb.h @@ -54,8 +54,8 @@ //! Device definition (mandatory) #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_MAJOR_VERSION BOARD_VER_MAJOR +#define USB_DEVICE_MINOR_VERSION BOARD_VER_MINOR #define USB_DEVICE_POWER 200 // Consumption on Vbus line (mA) #define USB_DEVICE_ATTR (USB_CONFIG_ATTR_BUS_POWERED) // (USB_CONFIG_ATTR_SELF_POWERED) diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c index 68f6b7891c08797371c9d7089650b58e52234eca..234e1abd6fc47492dd882c8ecaf563b33c4be471 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -81,74 +81,18 @@ void pot_init(void){ * * @return Nothing. */ - arch_ioport_set_port_dir(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm|PIN6_bm|PIN7_bm, IOPORT_DIR_OUTPUT); - arch_ioport_set_port_dir(IOPORT_PORTD, PIN4_bm, IOPORT_DIR_OUTPUT); - arch_ioport_set_port_level(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm|PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm); - arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); -} - -int8_t autogainswitch(void){ - /** - * Automatic gain switching. - * - * Reads last samples from over_under var from ads1255.h and changes gain if more than ADS_OVER_UNDER_SAMPLES off scale. - * Uses g_gain global variable. - * @return 0 when no switch occurs (due to hysteresis internal static var or if 500M resistor chosen). 1 if gain switch. - */ - //Need to change this to set variable max/min gains - extern int8_t over_under[ADS_OVER_UNDER_SAMPLES]; //from ads1255.h - int8_t overcurrent = 0; - static uint8_t hysteresis = 0; - static uint8_t last_return = 0; - - if (autogain_enable == 0) - return 0; - - if (g_gain == POT_GAIN_500M) - return 0; - - if (last_return==1){ - last_return=0; - return 1; - } - - if (hysteresis < ADS_OVER_UNDER_SAMPLES-1){ - ++hysteresis; - return 0; - } - - for (uint16_t i = 0; i < ADS_OVER_UNDER_SAMPLES; ++i) - overcurrent += over_under[i]; - - if (overcurrent == ADS_OVER_UNDER_SAMPLES && g_gain > POT_GAIN_100){ - --g_gain; - pot_set_gain(); - last_return=1; - hysteresis = 0; - for (uint16_t i = 0; i < ADS_OVER_UNDER_SAMPLES; ++i) - over_under[i]=0; - - return 1; - } - - if ((overcurrent*-1) == (ADS_OVER_UNDER_SAMPLES) && g_gain < POT_GAIN_3M){ - if (hysteresis < ADS_OVER_UNDER_SAMPLES+3){ - ++hysteresis; - return 0; - } - - ++g_gain; - pot_set_gain(); - last_return=1; - hysteresis = 0; - for (uint16_t i = 0; i < ADS_OVER_UNDER_SAMPLES; ++i) - over_under[i]=0; - - return 1; - } - - hysteresis = 0; - return 0; + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 1 + arch_ioport_set_port_dir(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm|PIN6_bm|PIN7_bm, IOPORT_DIR_OUTPUT); + arch_ioport_set_port_dir(IOPORT_PORTD, PIN4_bm, IOPORT_DIR_OUTPUT); + arch_ioport_set_port_level(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm|PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + #endif + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 + arch_ioport_set_port_dir(IOPORT_PORTB, PIN2_bm|PIN3_bm|PIN4_bm|PIN5_bm|PIN6_bm|PIN7_bm, IOPORT_DIR_OUTPUT); + arch_ioport_set_port_dir(IOPORT_PORTD, PIN4_bm, IOPORT_DIR_OUTPUT); + arch_ioport_set_port_level(IOPORT_PORTB, PIN2_bm|PIN3_bm|PIN4_bm|PIN5_bm|PIN6_bm|PIN7_bm, PIN3_bm|PIN6_bm|PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + #endif } void pot_set_gain(void){ @@ -158,74 +102,139 @@ void pot_set_gain(void){ * @return Nothing. */ switch (g_gain){ - case POT_GAIN_500M: - arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, 0); - arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); - printf("#INFO: 500M\n\r"); - break; + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 1 + case POT_GAIN_500M: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, 0); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); - case POT_GAIN_30M: - arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm); - arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); - printf("#INFO: 30M\n\r"); - break; + printf("#INFO: 500M\n\r"); + break; - case POT_GAIN_3M: - arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN7_bm); - arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); - printf("#INFO: 3M\n\r"); - break; + case POT_GAIN_30M: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); + printf("#INFO: 30M\n\r"); + break; - case POT_GAIN_300k: - arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm); - arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); - printf("#INFO: 300k\n\r"); - break; + case POT_GAIN_3M: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); + printf("#INFO: 3M\n\r"); + break; - case POT_GAIN_30k: - arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, 0); - arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); - printf("#INFO: 30k\n\r"); - break; + case POT_GAIN_300k: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); + printf("#INFO: 300k\n\r"); + break; - case POT_GAIN_3k: - arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm); - arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); - printf("#INFO: 3k\n\r"); - break; + case POT_GAIN_30k: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, 0); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + printf("#INFO: 30k\n\r"); + break; - case POT_GAIN_300: - arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN7_bm); - arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); - printf("#INFO: 300\n\r"); - break; + case POT_GAIN_3k: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + printf("#INFO: 3k\n\r"); + break; - case POT_GAIN_100: - arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm); - arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); - printf("#INFO: 100\n\r"); - break; + case POT_GAIN_300: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + printf("#INFO: 300\n\r"); + break; - default: - printf("#WAR: Invalid pot gain.\n\r"); - break; + case POT_GAIN_100: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + printf("#INFO: 100\n\r"); + break; + #endif + + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 + case POT_GAIN_100M: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, 0); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); + printf("#INFO: 100M\n\r"); + break; + + case POT_GAIN_30M: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); + printf("#INFO: 30M\n\r"); + break; + + case POT_GAIN_3M: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); + printf("#INFO: 3M\n\r"); + break; + + case POT_GAIN_300k: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, 0); + printf("#INFO: 300k\n\r"); + break; + + case POT_GAIN_30k: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, 0); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + printf("#INFO: 30k\n\r"); + break; + + case POT_GAIN_3k: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + printf("#INFO: 3k\n\r"); + break; + + case POT_GAIN_0: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + printf("#INFO: 0\n\r"); + break; + + case POT_GAIN_100: + arch_ioport_set_port_level(IOPORT_PORTB, PIN6_bm|PIN7_bm, PIN6_bm|PIN7_bm); + arch_ioport_set_port_level(IOPORT_PORTD, PIN4_bm, PIN4_bm); + printf("#INFO: 100\n\r"); + break; + #endif + + default: + printf("#WAR: Invalid pot gain.\n\r"); + break; return; } } -void pot_exp_start(void){ +void volt_exp_start(void){ /** * Connects measurement cell to rest of circuit. */ - arch_ioport_set_port_level(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm, PIN3_bm|PIN4_bm|PIN5_bm); + #if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 1 + arch_ioport_set_port_level(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm, PIN3_bm|PIN4_bm|PIN5_bm); + #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, PIN2_bm|PIN4_bm|PIN5_bm); + #endif + } void pot_exp_stop(void){ /** * Disconnects measurement cell and shorts RE and CE terminals. */ - arch_ioport_set_port_level(IOPORT_PORTB, PIN3_bm|PIN4_bm|PIN5_bm, 0); + #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); + #endif } void precond(int16_t v1, uint16_t t1, int16_t v2, uint16_t t2){ //assumes potentiostat switches are already set @@ -382,7 +391,7 @@ uint8_t lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first max5443_set_voltage1(dacindex_start); if (first_run == 1 || first_run == 2){ - pot_exp_start(); + volt_exp_start(); ads1255_rdatac(); tc_enable(&TCC1); @@ -587,7 +596,7 @@ void ca_experiment(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]) TCC0.CNT = 0; max5443_set_voltage1(step_dac[0]); - pot_exp_start(); + volt_exp_start(); for (uint8_t i = 0; i < steps; ++i) { @@ -668,7 +677,7 @@ void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h //calculate time to ADC trigger period = ceil((1/(double)frequency)*F_CPU); - uint8_t temp_div = ceil((double)period/65536); + uint16_t temp_div = ceil((double)period/65536); if (temp_div == 1) tc_write_clock_source(&TCF0,TC_CLKSEL_DIV1_gc); @@ -711,7 +720,8 @@ void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h ads1255_wakeup(); ads1255_rdatac(); ads1255_sync(); - pot_exp_start(); + + volt_exp_start(); do{ TCF0.CNT = 0; diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h index f9cea97c43afd7e35e29a65506269bac2ee9709e..2de19abb9d546b297ef8920c4a5a6da2925cc1b7 100644 --- a/DSTAT-temp/src/experiment.h +++ b/DSTAT-temp/src/experiment.h @@ -23,14 +23,27 @@ #include #include -#define POT_GAIN_100 0 -#define POT_GAIN_300 1 -#define POT_GAIN_3k 2 -#define POT_GAIN_30k 3 -#define POT_GAIN_300k 4 -#define POT_GAIN_3M 5 -#define POT_GAIN_30M 6 -#define POT_GAIN_500M 7 +#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 1 + #define POT_GAIN_100 0 + #define POT_GAIN_300 1 + #define POT_GAIN_3k 2 + #define POT_GAIN_30k 3 + #define POT_GAIN_300k 4 + #define POT_GAIN_3M 5 + #define POT_GAIN_30M 6 + #define POT_GAIN_500M 7 +#endif + +#if BOARD_VER_MAJOR == 1 && BOARD_VER_MINOR == 2 + #define POT_GAIN_0 0 + #define POT_GAIN_100 1 + #define POT_GAIN_3k 2 + #define POT_GAIN_30k 3 + #define POT_GAIN_300k 4 + #define POT_GAIN_3M 5 + #define POT_GAIN_30M 6 + #define POT_GAIN_100M 7 +#endif #define POT_LP_OFF 0 #define POT_LP_ON 1 @@ -62,9 +75,8 @@ extern uint8_t autogain_enable; void send_data_uint16(uint16_t data); void send_data_int32(int32_t data); void pot_init(void); -int8_t autogainswitch(void); void pot_set_gain(void); -void pot_exp_start(void); +void volt_exp_start(void); void pot_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);