diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c index 19714f2f22f5ab9ae3d38c1ca9928f44e28b9d5b..ac1f305847ce53fae5eca3e486b55a1c71ba9b53 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -433,7 +433,7 @@ static void lsv_cca_callback(void){ return; } -void chronoamp(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]){ +void ca_experiment(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]){ /** * Performs a chronoamperometry experiment. * diff --git a/DSTAT-temp/src/experiment.h b/DSTAT-temp/src/experiment.h index 67174c8c7fb3224ef0d3f0b0c1a669722cf3527d..b0200a8bdc07dce2209576af0dcf3427d85bb297 100644 --- a/DSTAT-temp/src/experiment.h +++ b/DSTAT-temp/src/experiment.h @@ -63,7 +63,7 @@ void pot_exp_start(void); void pot_exp_stop(void); void cv_experiment(int16_t v1, int16_t v2, int16_t start, uint8_t scans, uint16_t slope); void lsv_experiment(int16_t start, int16_t stop, uint16_t slope, int8_t first_run); -void chronoamp(uint16_t steps, uint16_t step_dac[], uint16_t step_seconds[]); +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); #endif /* EXPERIMENT_H_ */ \ No newline at end of file diff --git a/DSTAT-temp/src/main.c b/DSTAT-temp/src/main.c index 906f954f184ee155f23fe7805083017fa5c85a68..ea697b02b6577031c68e7f96e647c6f9e4e9d2d1 100644 --- a/DSTAT-temp/src/main.c +++ b/DSTAT-temp/src/main.c @@ -9,44 +9,90 @@ //Internal global variables int16_t p1, p2, p3, p4; -uint16_t u1; +uint16_t u1, u2, u3; uint8_t p5, o1, o2, o3; -uint16_t step_dac[50], step_seconds[50]; +//uint16_t step_dac[50], step_seconds[50]; //Internal function declarations int8_t command_handler(char command); int8_t command_handler(char command){ + /** + * Deals with commands over USB + * + * Calls functions in + * @param command Command character input. + */ switch (command){ - case 'A': //ADS Buffer/rate/PGA - scanf("%1X%2X%1X",&o1,&o2,&o3); - //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 - //scanf("%1u%1u%7li%7li",&g_gain,&autogain_enable,&overcurrent_threshold,&undercurrent_threshold); - scanf("%1u",&g_gain); - pot_set_gain(); - break; - case 'L': //LSV - start, stop, slope - scanf("%5i%5i%5i",&p1,&p2,&u1); - printf("%i,%i,%i",&p1,&p2,&u1); - lsv_experiment(p1,p2,u1,2); - break; - case 'C': //CV - v1, v2, start, scans, slope - scanf("%5i%5i%5i%3i%5i",&p1,&p2,&p3,&p5,&u1); - cv_experiment(p1,p2,p3,p5,u1); - break; - case 'S': //SWV - break; - case 'R': //CA - break; - default: - printf("Ee"); - return 1; + case 'A': //ADS Buffer/rate/PGA values from ads1255.h + scanf("%1x%2x%1x",&o1,&o2,&o3); + //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 + //scanf("%1u%1u%7li%7li",&g_gain,&autogain_enable,&overcurrent_threshold,&undercurrent_threshold); + scanf("%1u",&g_gain); + pot_set_gain(); //uses global g_gain, so no params + break; + + case 'L': //LSV - start, stop, slope + scanf("%5i%5i%5u",&p1,&p2,&u1); + //printf("%i,%i,%i",&p1,&p2,&u1); + lsv_experiment(p1,p2,u1,2); + break; + + case 'C': //CV - v1, v2, start, scans, slope + scanf("%5i%5i%5i%3u%5u",&p1,&p2,&p3,&p5,&u1); + cv_experiment(p1,p2,p3,p5,u1); + break; + + case 'S': //SWV - start, stop, step size, pulse_height, frequency + scanf("%5i%5i%5u%3u%5u",&p1,&p2,&u1,&u2,&u3); + swv_experiment(p1,p2,u1,u2,u3); + break; + + case 'R': //CA - steps, step_dac[], step_seconds[] + scanf("%u",&p5); //get number of steps + + //allocate arrays for steps + printf("%u\n\r", p5*sizeof(uint16_t)); + uint16_t * step_dac = malloc(p5*sizeof(uint16_t)); + uint16_t * step_seconds = malloc(p5*sizeof(uint16_t)); + //check for successful allocation + if (!step_dac || !step_seconds){ + printf("#ERR: Could not allocate memory\n\r"); + break; + } + + uint8_t i; + + printf("#DAC:\n\r#"); + for (i=0; i