From a7c6e710c1813acef2759169d79d9a1dc0793be8 Mon Sep 17 00:00:00 2001 From: Michael Dryden Date: Fri, 31 Oct 2014 17:00:29 -0400 Subject: [PATCH] v1.2 board support. --- DSTAT-temp/src/config/conf_board.h | 3 + DSTAT-temp/src/config/conf_usb.h | 4 +- DSTAT-temp/src/experiment.c | 173 ++++++++++++++++++++--------- DSTAT-temp/src/experiment.h | 29 +++-- 4 files changed, 148 insertions(+), 61 deletions(-) diff --git a/DSTAT-temp/src/config/conf_board.h b/DSTAT-temp/src/config/conf_board.h index 80fd2f0..ca27c6d 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 03219f8..011d7bc 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 0x0042 #define USB_DEVICE_PRODUCT_ID 0x0002 -#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 19714f2..36d2f1c 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -53,12 +53,6 @@ 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. @@ -121,6 +115,18 @@ int8_t autogainswitch(void){ 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){ @@ -130,58 +136,111 @@ 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); + #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); - printf("#INFO: 500M\n\r"); - break; + printf("#INFO: 500M\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_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_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_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_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_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_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_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_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_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; + default: + printf("#WAR: Invalid pot gain.\n\r"); + break; return; } @@ -191,14 +250,26 @@ void pot_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 cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_t slope){ diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h index 67174c8..8f7acaf 100644 --- a/DSTAT-temp/src/experiment.h +++ b/DSTAT-temp/src/experiment.h @@ -22,14 +22,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 -- GitLab