SAADC differential input setup. With EPD display.
Dependencies: GDEP015OC1 acn_nrf52_saadc adc52832_common
main.cpp@7:4c999f20818c, 2017-10-06 (annotated)
- Committer:
- jurica238814
- Date:
- Fri Oct 06 13:13:58 2017 +0000
- Revision:
- 7:4c999f20818c
- Parent:
- 5:35f9fea8fe5b
Stable and working version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 0:04520242cfef | 1 | /* |
jurica238814 | 0:04520242cfef | 2 | * Example to demonstrate usage of the nrf52's SAADC in differential working\ |
jurica238814 | 0:04520242cfef | 3 | * mode. |
jurica238814 | 0:04520242cfef | 4 | * |
jurica238814 | 0:04520242cfef | 5 | * Made by Jurica Resetar @ aconno |
jurica238814 | 0:04520242cfef | 6 | * jurica_resetar@yahoo.com |
jurica238814 | 0:04520242cfef | 7 | * More info @ aconno.de |
jurica238814 | 0:04520242cfef | 8 | * |
jurica238814 | 0:04520242cfef | 9 | * All rights reserved |
jurica238814 | 0:04520242cfef | 10 | * |
jurica238814 | 0:04520242cfef | 11 | */ |
jurica238814 | 5:35f9fea8fe5b | 12 | |
jurica238814 | 0:04520242cfef | 13 | #include "mbed.h" |
jurica238814 | 0:04520242cfef | 14 | #include "acd_nrf52_saadc.h" |
jurica238814 | 2:49dab8d9637a | 15 | #include "GDEP015OC1.h" |
jurica238814 | 1:41e296b93414 | 16 | |
jurica238814 | 4:7dd2d8cc90ed | 17 | #define ANALOG_PIN_P (4) |
jurica238814 | 4:7dd2d8cc90ed | 18 | #define ANALOG_PIN_N (5) |
jurica238814 | 4:7dd2d8cc90ed | 19 | #define NUM_OF_DIFF_ADCs (4) |
jurica238814 | 0:04520242cfef | 20 | |
jurica238814 | 2:49dab8d9637a | 21 | SPI spi(p3, NC, p4); |
jurica238814 | 2:49dab8d9637a | 22 | GDEP015OC1 epd = GDEP015OC1(spi, p5, p6, p7, p8); |
jurica238814 | 0:04520242cfef | 23 | |
jurica238814 | 0:04520242cfef | 24 | int main(void){ |
jurica238814 | 4:7dd2d8cc90ed | 25 | NRF52_SAADC *diffADCs[NUM_OF_DIFF_ADCs]; |
jurica238814 | 4:7dd2d8cc90ed | 26 | /* Declare your ADCs here */ |
jurica238814 | 4:7dd2d8cc90ed | 27 | /* Change NUM_OF_DIFF_ADCs in the header */ |
jurica238814 | 4:7dd2d8cc90ed | 28 | diffADCs[0] = new NRF52_SAADC(ANALOG_PIN_P, ANALOG_PIN_N); |
jurica238814 | 4:7dd2d8cc90ed | 29 | diffADCs[1] = new NRF52_SAADC(ANALOG_PIN_N, ANALOG_PIN_P); |
jurica238814 | 2:49dab8d9637a | 30 | |
jurica238814 | 4:7dd2d8cc90ed | 31 | uint8_t i; |
jurica238814 | 4:7dd2d8cc90ed | 32 | float voltage[NUM_OF_DIFF_ADCs]; |
jurica238814 | 2:49dab8d9637a | 33 | char buffer[256]; |
jurica238814 | 1:41e296b93414 | 34 | |
jurica238814 | 2:49dab8d9637a | 35 | sprintf(buffer, "Differential ADC inputs:"); |
jurica238814 | 2:49dab8d9637a | 36 | epd.writeString(buffer, 30, 30, 0); |
jurica238814 | 2:49dab8d9637a | 37 | epd.writeFull(); |
jurica238814 | 2:49dab8d9637a | 38 | |
jurica238814 | 4:7dd2d8cc90ed | 39 | while(1){ |
jurica238814 | 4:7dd2d8cc90ed | 40 | for(i=0; i<NRF52_SAADC::channelCounter; i++){ |
jurica238814 | 5:35f9fea8fe5b | 41 | voltage[i] = ((float)(diffADCs[i]->read()))*(3.3f/8192); // Convert raw data into voltage |
jurica238814 | 4:7dd2d8cc90ed | 42 | sprintf(buffer, "ADC voltage is: %f", voltage[i]); |
jurica238814 | 4:7dd2d8cc90ed | 43 | epd.writeString(buffer, 30, 50+i*20, 0); |
jurica238814 | 4:7dd2d8cc90ed | 44 | } |
jurica238814 | 2:49dab8d9637a | 45 | epd.write(); |
jurica238814 | 4:7dd2d8cc90ed | 46 | for(i=0; i<NRF52_SAADC::channelCounter; i++){ |
jurica238814 | 4:7dd2d8cc90ed | 47 | sprintf(buffer, "ADC voltage is: %f", voltage[i]); |
jurica238814 | 4:7dd2d8cc90ed | 48 | epd.writeString(buffer, 30, 50+i*20, 1); |
jurica238814 | 4:7dd2d8cc90ed | 49 | } |
jurica238814 | 2:49dab8d9637a | 50 | epd.write(); |
jurica238814 | 0:04520242cfef | 51 | } |
jurica238814 | 0:04520242cfef | 52 | } |