diff --git a/DSTAT-temp/src/ads1255.c b/DSTAT-temp/src/ads1255.c index 739c80bef78ffbdb87311395092d77b216e5ae34..7d6f7f2894be567258410085496b78ff79444b4d 100644 --- a/DSTAT-temp/src/ads1255.c +++ b/DSTAT-temp/src/ads1255.c @@ -10,6 +10,10 @@ uint8_t buffer_iter = 0; +//Public variable definitions +int32_t overcurrent_threshold = ADS_DEFAULT_OVERCURRENT_THRESHOLD; +int32_t undercurrent_threshold = ADS_DEFAULT_UNDERCURRENT_THRESHOLD; + struct usart_spi_device spi_device_conf = { .id = IOPORT_CREATE_PIN(PORTE, 4) }; @@ -161,21 +165,21 @@ int32_t ads1255_single_read(void){ printf(logstr1, "ADS1255 result=%li\n\r",input_buffer.int32); #endif - if (input_buffer.int32 > ADS_OVERCURRENT_THRESHOLD || (-1*input_buffer.int32) > (ADS_OVERCURRENT_THRESHOLD)) + if (abs(input_buffer.int32) > overcurrent_threshold) { over_under[buffer_iter] = 1; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } - else if (input_buffer.int32 < ADS_UNDERCURRENT_THRESHOLD && (input_buffer.int32*-1) < (ADS_UNDERCURRENT_THRESHOLD)) + else if (abs(input_buffer.int32) < undercurrent_threshold) { over_under[buffer_iter] = -1; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } else { @@ -269,21 +273,21 @@ int32_t ads1255_read(void){ printf("ADS1255 result=%li\n\r", input_buffer.int32); #endif - if (input_buffer.int32 > ADS_OVERCURRENT_THRESHOLD || (-1*input_buffer.int32) > (ADS_OVERCURRENT_THRESHOLD)) + if (abs(input_buffer.int32) > overcurrent_threshold) { over_under[buffer_iter] = 1; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } - else if (input_buffer.int32 < ADS_UNDERCURRENT_THRESHOLD && (input_buffer.int32*-1) < (ADS_UNDERCURRENT_THRESHOLD)) + else if (abs(input_buffer.int32) < undercurrent_threshold) { over_under[buffer_iter] = -1; if (buffer_iter == (ADS_OVER_UNDER_SAMPLES - 1)) - buffer_iter = 0; + buffer_iter = 0; else - buffer_iter++; + buffer_iter++; } else { diff --git a/DSTAT-temp/src/ads1255.h b/DSTAT-temp/src/ads1255.h index 103a7f62e28930138642880a77da8dc902709c99..b07b46a2ab942e978aff939d97709560fa807191 100644 --- a/DSTAT-temp/src/ads1255.h +++ b/DSTAT-temp/src/ads1255.h @@ -59,12 +59,13 @@ #define ADS_BUFF_OFF 0b0000 //0x0 #define ADS_BUFF_ON 0b0010 //0x2 -#define ADS_OVERCURRENT_THRESHOLD 6000000L -#define ADS_UNDERCURRENT_THRESHOLD 200000L +#define ADS_DEFAULT_OVERCURRENT_THRESHOLD 6000000L +#define ADS_DEFAULT_UNDERCURRENT_THRESHOLD 200000L #define ADS_OVER_UNDER_SAMPLES 3 - int8_t over_under[ADS_OVER_UNDER_SAMPLES]; +extern int32_t overcurrent_threshold; +extern int32_t undercurrent_threshold; void ads1255_sync(void); void ads1255_init_pins(void); diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c index 09911d4c8fa1a777ae634016c08e593565e25b21..0bbd7c298c3b5f453ac854de03231697afd33b07 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -17,6 +17,10 @@ #include "experiment.h" +//Public variable definitions +uint8_t g_gain = POT_GAIN_30k; +uint8_t autogain_enable = 1; + //Private variables volatile int32_t voltage = 0; volatile uint16_t dacindex = 0; @@ -63,12 +67,15 @@ int8_t autogainswitch(void){ * 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; diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h index ab8843745da02697ee4cf7c9025db06332acc4e9..67174c8c7fb3224ef0d3f0b0c1a669722cf3527d 100644 --- a/DSTAT-temp/src/experiment.h +++ b/DSTAT-temp/src/experiment.h @@ -53,7 +53,8 @@ #define SIN_IMP_CYCLEPTS 50 -uint8_t g_gain; +extern uint8_t g_gain; +extern uint8_t autogain_enable; void pot_init(void); int8_t autogainswitch(void); diff --git a/DSTAT-temp/src/main.c b/DSTAT-temp/src/main.c index c5f8e6c47a4e265cea3a2f1d257c47de4c4d1a82..3a40ee85aebe9447f9c143067e9c7e6b6e35aed0 100644 --- a/DSTAT-temp/src/main.c +++ b/DSTAT-temp/src/main.c @@ -23,7 +23,9 @@ int8_t command_handler(char command){ //Sanity check goes here ads1255_setup(o1, o2, o3); break; - case 'G': //Gain - start gain, autogain on/off, min gain, max, gain, low/high switch thresholds + case 'G': //Gain - start gain, autogain on/off, (min gain, max gain), low/high switch thresholds + //scanf("%1u%1u%7li%7li",&g_gain,&autogain_enable,&overcurrent_threshold,&undercurrent_threshold); + pot_set_gain(); break; case 'L': //LSV - start, stop, slope scanf("%5i%5i%5i",&p1,&p2,&u1); @@ -67,6 +69,7 @@ int main(void){ ads1255_init_pins(); ads1255_init_module(); ads1255_setup(ADS_BUFF_ON,ADS_DR_60,ADS_PGA_2); + pot_set_gain(); PORTD.INT0MASK = PIN5_bm; PORTD.INT1MASK = PIN5_bm; PORTD.INTCTRL = PORT_INT0LVL_OFF_gc | PORT_INT1LVL_OFF_gc; diff --git a/DSTAT-temp/src/main.h b/DSTAT-temp/src/main.h index dfc827a905553f8b2300103d32b0645f25dc041f..928703f5c9e0aee8f04785352cf41b43b8a58af8 100644 --- a/DSTAT-temp/src/main.h +++ b/DSTAT-temp/src/main.h @@ -11,8 +11,8 @@ #include #include #include -#include "ads1255.h" -#include "max5443.h" +//#include "ads1255.h" +//#include "max5443.h" #include "experiment.h" int8_t autogainswitch(void); diff --git a/DSTAT1.atsuo b/DSTAT1.atsuo index 7483151d1e6db9eaf031b4df37c2b1ca1e945fd1..02c2c704de8eabe75a76f40eb2bfca7682b1b2c6 100644 Binary files a/DSTAT1.atsuo and b/DSTAT1.atsuo differ diff --git a/DSTAT1/src/ads1255.h b/DSTAT1/src/ads1255.h index 432219c6700c8bca68d458c644434592604332da..d9a4cb6d7f02f841656e31c87690adb6daced640 100644 --- a/DSTAT1/src/ads1255.h +++ b/DSTAT1/src/ads1255.h @@ -56,8 +56,8 @@ #define ADS_UNDERCURRENT_THRESHOLD 200000L #define ADS_OVER_UNDER_SAMPLES 3 - #include - #include +#include +#include int8_t over_under[ADS_OVER_UNDER_SAMPLES];