ADC logging with demo drive board for calibration ADC read synchronised with heater on time
Dependencies: mbed MODSERIAL FastPWM ADS8568_ADC
Diff: main.cpp
- Revision:
- 28:63280fb5b938
- Parent:
- 27:505c1565c076
- Child:
- 29:06235c37746a
diff -r 505c1565c076 -r 63280fb5b938 main.cpp --- a/main.cpp Thu Oct 10 13:59:45 2019 +0000 +++ b/main.cpp Thu Oct 10 14:06:11 2019 +0000 @@ -7,7 +7,6 @@ #define LOG_INTERVAL 1000 // log file interval (ms) #define START_DELAY 1000 // pause for startup (ms) #define N_STEPS 100 -#define N_READ 1 #define BUFFER_SIZE 4096 //UID lookup address and pointer @@ -96,9 +95,6 @@ if (i_board != -1) pc.printf("Drive board: Board %d\n",drive_board_serial_number[i_board]); else pc.printf("Drive board UID match not found\n"); - pc.printf("MEAS_DELAY: %d\n",MEAS_DELAY); - pc.printf("N_READ: %d\n",N_READ); - pc.printf("iStep, eTime, I1, V1, R1_adc, R1_ohm, I2, V2, R2_adc, R2_ohm\n"); wait_ms(START_DELAY); @@ -109,44 +105,39 @@ eTime = timer.read_ms(); for (int iHeater=0; iHeater <2; iHeater++) { - //Average N_READ ADC cycles - curr[iHeater] = 0; - v[iHeater] = 0; - for (int iRead = 0; iRead<N_READ; iRead++) { - // turn on heater - if (iHeater==0) { - drive_1 = 1; - led_0 = 1; - led_1 = 0; - } - else { - drive_2 = 1; - led_0 = 0; - led_1 = 1; - } + // turn on heater + if (iHeater==0) { + drive_1 = 1; + led_0 = 1; + led_1 = 0; + } + else { + drive_2 = 1; + led_0 = 0; + led_1 = 1; + } - wait_us(MEAS_DELAY); - - //Start ADC conversion - adc.start_conversion(15); - - //Turn off heater - if (iHeater==0) - drive_1 = 0; - else - drive_2 = 0; + wait_us(MEAS_DELAY); + + //Start ADC conversion + adc.start_conversion(15); + + //Wait until ADC is free + while(adc_busy == 1) { + wait_us(1); + } - //Wait until ADC is free - while(adc_busy == 1) { - wait_us(1); - } + //Turn off heater + if (iHeater==0) + drive_1 = 0; + else + drive_2 = 0; - //Get ADC values - adc.read_channels(); - curr[iHeater] += adc.read_channel_result(i_port[iHeater]); - v[iHeater] += adc.read_channel_result(v_port[iHeater]); - } + //Get ADC values + adc.read_channels(); + curr[iHeater] = adc.read_channel_result(i_port[iHeater]); + v[iHeater] = adc.read_channel_result(v_port[iHeater]); wait_us(MEAS_DELAY);