From 129ba663996d1f1f5578c7853da7230ae7104949 Mon Sep 17 00:00:00 2001 From: Michael Dryden Date: Fri, 11 Apr 2014 17:39:32 -0400 Subject: [PATCH] Fixed dacindex for SWV. Removed SWV autogain. Changed data output format. --- DSTAT-temp/src/experiment.c | 79 +++++++++++++----------------------- DSTAT1.atsuo | Bin 47616 -> 47616 bytes 2 files changed, 28 insertions(+), 51 deletions(-) diff --git a/DSTAT-temp/src/experiment.c b/DSTAT-temp/src/experiment.c index 7e74243..8731343 100644 --- a/DSTAT-temp/src/experiment.c +++ b/DSTAT-temp/src/experiment.c @@ -520,16 +520,16 @@ void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h int32_t forward = 0; int32_t reverse = 0; - int32_t data_buffer; +// int32_t data_buffer; uint8_t direction; - uint16_t dacindex_start = ceil((start)*(65535/(double)3000))+32767; - uint16_t dacindex_stop = ceil(stop*(65535/(double)3000))+32767; - uint16_t dacindex_step = ceil(step*(65535/(double)3000)); - uint16_t dacindex_pulse_height = ceil(pulse_height*(65535/(double)3000)); + uint16_t dacindex_start = ceil((start)*(65536/(double)3000))+32768; + uint16_t dacindex_stop = ceil(stop*(65536/(double)3000))+32768; + uint16_t dacindex_step = ceil(step*(65536/(double)3000)); + uint16_t dacindex_pulse_height = ceil(pulse_height*(65536/(double)3000)); uint16_t dacindex = dacindex_start; uint32_t period; - int16_t fgain = -1; - int16_t rgain = -1; +// int16_t fgain = -1; +// int16_t rgain = -1; if (start < stop) @@ -543,7 +543,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/UINT16_MAX); + uint8_t temp_div = ceil((double)period/65536); if (temp_div == 1) tc_write_clock_source(&TCF0,TC_CLKSEL_DIV1_gc); @@ -572,7 +572,7 @@ void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h period /= 1024; } else{ - printf("Frequency/ADC rate is too low\n\r"); + printf("#Frequency/ADC rate is too low\n\r"); return; } @@ -596,70 +596,47 @@ void swv_experiment(int16_t start, int16_t stop, uint16_t step, uint16_t pulse_h while ((dacindex <= dacindex_stop && direction == 1) || (dacindex >= dacindex_stop && direction == 0)){ tc_clear_overflow(&TCF0); - if (fgain > -1) - //printf("%u, %li, %li\n\r", dacindex, forward*fgain, reverse*rgain); - printf("%u, %li%0*lu, %li%0*lu\n\r", dacindex, fgain, 0, forward, rgain, 0, reverse); - + printf("%u %ld %ld\n\r", dacindex, forward, reverse); //data output + forward = 0; reverse = 0; - while (!tc_is_overflow(&TCF0)){ - autogainswitch(); - if (g_gain <= POT_GAIN_30M) - fgain = 0; - else - fgain = g_gain-1; - - - while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); + while (!tc_is_overflow(&TCF0)){ //convert continuously until tc overflow - datum is last collected point + while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); //wait for next valid datum while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); - - // while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTE, 3))); - // while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3))); - // forward = ads1255_read_fast24(); - forward = ads1255_read(); + forward = ads1255_read_fast24(); } - - if (direction == 1) - max5443_set_voltage1(dacindex-dacindex_pulse_height); + if (direction == 1) //switch voltage to other half of cycle + max5443_set_voltage1(dacindex-dacindex_pulse_height); else - max5443_set_voltage1(dacindex+dacindex_pulse_height); + max5443_set_voltage1(dacindex+dacindex_pulse_height); + tc_clear_overflow(&TCF0); //reset timer OVF - tc_clear_overflow(&TCF0); - if (direction == 1) - dacindex += dacindex_step; + if (direction == 1) //increment dacindex + dacindex += dacindex_step; else - dacindex -= dacindex_step; + dacindex -= dacindex_step; - while (!tc_is_overflow(&TCF0)){ - autogainswitch(); - if (g_gain <= POT_GAIN_30M) - rgain = 0; - else - rgain = g_gain-1; - - while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); + while (!tc_is_overflow(&TCF0)){ //wait for tc overflow + while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTD, 5))); //wait for next valid datum while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTD, 5))); - - // while (ioport_pin_is_low(IOPORT_CREATE_PIN(PORTE, 3))); - // while (ioport_pin_is_high(IOPORT_CREATE_PIN(PORTE, 3))); - // reverse = ads1255_read_fast24(); - reverse = ads1255_read(); + reverse = ads1255_read_fast24(); } + //at new dacindex if (direction == 1) - max5443_set_voltage1(dacindex+dacindex_pulse_height); + max5443_set_voltage1(dacindex+dacindex_pulse_height); else - max5443_set_voltage1(dacindex-dacindex_pulse_height); + max5443_set_voltage1(dacindex-dacindex_pulse_height); } pot_exp_stop(); tc_write_clock_source(&TCF0, TC_CLKSEL_OFF_gc); tc_disable(&TCF0); - tc_write_count(&TCF0,0); + TCF0.CNT = 0; ads1255_standby(); return; diff --git a/DSTAT1.atsuo b/DSTAT1.atsuo index 24000e0c2147ce95fc226e40e7a827288f7f30d1..6a6fe5976d2f1b25dc8b3c479edbb9ae1a676dbb 100644 GIT binary patch delta 669 zcmY+A%}-N76vb!W8|izL(!S6SB@`b79t{|g1)#;RL`;ee=|D={K++H*8xj=XQezW$ zgapl5xs z4T>-+9hX4fggRM9A$AF2N;=(SL=98vRHH-mw2{7&?egY_7YvNhm(FnLgh2^k#RPO9odOwI!&Ko&*%n;}fgUa4PH;n2 z#|lvqv^i5J`HUD)h11<$pWYJi*P5 zob9q%>RMNFW!P5r%0td4F|k_9PI1PjNmohNNO{tA(lJGKtp2R-a=b2%V{^`{)z>(x zbNzU+mByR341&rN+}w6B``|CaCwg55*GK1-nz zQZ#AgZ8V7zzifj_N*wS3ZIX>JPg{vLJ;f0Ac@`=qMT(MkD}_n@5?usI3nN>!Sr6Vz zUuD;Zb^f}?v7Z@1H9hXJ1aW5&opk{wEyY!WkcC=hN+C=|Z^7IwVmzAFs=pM$AtxA= z;tCzjTsS@y^TTiGPS3%;`BlsmcJa2nxb=|Xq%4u2{;dBN-p7MXXXiIV7+br8-DMv~ zg@~>%ykcw+*~RUypi@K4aqd&)sPa^&WT&5=+|{Y21%|!K4VaaV?fNpqyYf0lYXY0k z_VA_rNIzI@dTz6cosBe}e&__7&f#dK-GA)TThB&?)?xgq{7w%4m!%iCpPy$mqyBXQ dV;eEu`?`OU#{xO;llorb5gQCahYjk-$A81jy@>z- -- GitLab