![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
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:
- 27:505c1565c076
- Parent:
- 26:323238949f9d
- Child:
- 28:63280fb5b938
--- a/main.cpp Thu Oct 10 13:03:16 2019 +0000 +++ b/main.cpp Thu Oct 10 13:59:45 2019 +0000 @@ -7,7 +7,7 @@ #define LOG_INTERVAL 1000 // log file interval (ms) #define START_DELAY 1000 // pause for startup (ms) #define N_STEPS 100 -#define N_READ 4 +#define N_READ 1 #define BUFFER_SIZE 4096 //UID lookup address and pointer @@ -109,45 +109,45 @@ eTime = timer.read_ms(); for (int iHeater=0; iHeater <2; iHeater++) { - // measure 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); - //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; + } + + 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 until ADC is free while(adc_busy == 1) { wait_us(1); } - //Get ADC values + //Get ADC values adc.read_channels(); curr[iHeater] += adc.read_channel_result(i_port[iHeater]); v[iHeater] += adc.read_channel_result(v_port[iHeater]); } - - //Turn off heater - if (iHeater==0) - drive_1 = 0; - else - drive_2 = 0; - - + wait_us(MEAS_DELAY); //Calculate resistance