A simple example for analog input and EPD usage.
Dependencies: GDEP015OC1 acn_nrf52_saadc aconno_bsp
Fork of acd52832_Car_battery_ch by
Diff: main.cpp
- Revision:
- 4:f6f94ef38e6a
- Parent:
- 3:4fb622e929d0
- Child:
- 5:6566725c8835
--- a/main.cpp Thu Jun 29 11:06:35 2017 +0000 +++ b/main.cpp Thu Jun 29 16:21:53 2017 +0000 @@ -9,8 +9,11 @@ #include "acd52832_bsp.h" #include "GDEP015OC1.h" -#define delay_time 1000 -#define ADC_MAX_VALUE 1023 +#define delay_time (1000) +#define ADC_MAX_VALUE (4092) +#define ADC_REF_VOLTAGE (3.6) +#define VOLTAGE_DIVIDER_RATION (130.0/30) +#define CURRENT_FACTOR (36.0) SPI spi(PIN_EPD_MOSI, NC, PIN_EPD_SCK, NC); GDEP015OC1 epd = GDEP015OC1(spi, PIN_EPD_CS, PIN_EPD_DC, PIN_EPD_RST, PIN_EPD_BUSY); @@ -21,25 +24,44 @@ int main(){ char buffer[25] = {0}; + float adc1_mean=0, adc2_mean=0, adc3_mean=0; + int count = 0; + wait_ms(100); - + NRF_SAADC->RESOLUTION = 0x00000002; // Set 12b resolution while(true){ - epd.empty(); - epd.writeFull(); - sprintf(buffer, "Battery: %4.0f", battery.read()*ADC_MAX_VALUE); // Create a string - epd.writeString(buffer,25,70,0); // Write new data to the buffer - epd.write(); // Write string to the EPD + adc1_mean += battery.read_u16(); + adc2_mean += usb1.read_u16(); + adc3_mean += usb2.read_u16(); + count ++; - - sprintf(buffer, "USB1: %4.0f", usb1.read()*ADC_MAX_VALUE); // Create a string - epd.writeString(buffer,25,90,0); // Write new data to the buffer - epd.write(); // Write string to the EPD - - sprintf(buffer, "USB2: %4.0f", usb2.read()*ADC_MAX_VALUE); // Create a string - epd.writeString(buffer,25,110,0); // Write new data to the buffer - epd.write(); // Write string to the EPD - - wait_ms(delay_time); + if (count == 10){ + + adc1_mean /= 10; + adc2_mean /= 10; + adc3_mean /= 10; + + count = 0; + epd.empty(); + epd.writeFull(); + + sprintf(buffer, "Battery: %5.5fV", adc1_mean*(ADC_REF_VOLTAGE/ADC_MAX_VALUE)*VOLTAGE_DIVIDER_RATION); // Create a string + epd.writeString(buffer,25,70,0); // Write new data to the buffer + epd.write(); // Write string to the EPD + + + sprintf(buffer, "USB1: %5.5fA", (CURRENT_FACTOR/ADC_MAX_VALUE)*adc2_mean); // Create a string + epd.writeString(buffer,25,90,0); // Write new data to the buffer + epd.write(); // Write string to the EPD + + sprintf(buffer, "USB1: %5.5fA", (CURRENT_FACTOR/ADC_MAX_VALUE)*adc3_mean); // Create a string + epd.writeString(buffer,25,110,0); // Write new data to the buffer + epd.write(); // Write string to the EPD + + adc1_mean = 0; + adc2_mean = 0; + adc3_mean = 0; + } } } \ No newline at end of file