Greg Steiert
/
MAX_ADC
Maxim ADC Library Example
Fork of mbed-os-example-mbed5-blinky by
main.cpp@31:ddedcb0e4e9e, 2017-03-10 (annotated)
- Committer:
- switches
- Date:
- Fri Mar 10 21:48:49 2017 +0000
- Revision:
- 31:ddedcb0e4e9e
- Parent:
- 29:0b58d21e87d6
Maxim ADC Library Example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
0:2757d7abb7d9 | 1 | #include "mbed.h" |
switches | 31:ddedcb0e4e9e | 2 | #include "adc.h" |
Jonathan Austin |
0:2757d7abb7d9 | 3 | |
Jonathan Austin |
0:2757d7abb7d9 | 4 | DigitalOut led1(LED1); |
Jonathan Austin |
0:2757d7abb7d9 | 5 | |
Jonathan Austin |
1:846c97078558 | 6 | // main() runs in its own thread in the OS |
switches | 31:ddedcb0e4e9e | 7 | int main() |
switches | 31:ddedcb0e4e9e | 8 | { |
switches | 31:ddedcb0e4e9e | 9 | uint16_t adc_value; |
switches | 31:ddedcb0e4e9e | 10 | unsigned int overflow; |
switches | 31:ddedcb0e4e9e | 11 | |
switches | 31:ddedcb0e4e9e | 12 | /* Initialize ADC */ |
switches | 31:ddedcb0e4e9e | 13 | ADC_Init(); |
switches | 31:ddedcb0e4e9e | 14 | |
Jonathan Austin |
0:2757d7abb7d9 | 15 | while (true) { |
Jonathan Austin |
0:2757d7abb7d9 | 16 | led1 = !led1; |
switches | 31:ddedcb0e4e9e | 17 | ADC_StartConvert(ADC_CH_0, 0, 1); // AIN0 |
switches | 31:ddedcb0e4e9e | 18 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 19 | printf("AIN0: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 20 | ADC_StartConvert(ADC_CH_1, 0, 1); // AIN1 |
switches | 31:ddedcb0e4e9e | 21 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 22 | printf("AIN1: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 23 | ADC_StartConvert(ADC_CH_2, 0, 1); // AIN2 |
switches | 31:ddedcb0e4e9e | 24 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 25 | printf("AIN2: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 26 | ADC_StartConvert(ADC_CH_3, 0, 1); // AIN3 |
switches | 31:ddedcb0e4e9e | 27 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 28 | printf("AIN3: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 29 | ADC_StartConvert(ADC_CH_0_DIV_5, 0, 1); // AIN0 div 5 |
switches | 31:ddedcb0e4e9e | 30 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 31 | printf("AIN0/5: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 32 | ADC_StartConvert(ADC_CH_1_DIV_5, 0, 1); // AIN1 div 5 |
switches | 31:ddedcb0e4e9e | 33 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 34 | printf("AIN1/5: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 35 | ADC_StartConvert(ADC_CH_VDDB_DIV_4, 0, 1); // AIN2 |
switches | 31:ddedcb0e4e9e | 36 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 37 | printf("VDDB/4: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 38 | ADC_StartConvert(ADC_CH_VDD18, 0, 1); // AIN3 |
switches | 31:ddedcb0e4e9e | 39 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 40 | printf("VDD18: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 41 | ADC_StartConvert(ADC_CH_VDD12, 0, 1); // AIN3 |
switches | 31:ddedcb0e4e9e | 42 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 43 | printf("VDD12: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 44 | ADC_StartConvert(ADC_CH_VRTC_DIV_2, 0, 1); // AIN0 div 5 |
switches | 31:ddedcb0e4e9e | 45 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 46 | printf("VRTC/2: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
switches | 31:ddedcb0e4e9e | 47 | ADC_StartConvert(ADC_CH_TMON, 0, 1); // AIN1 div 5 |
switches | 31:ddedcb0e4e9e | 48 | overflow = (ADC_GetData(&adc_value) == E_OVERFLOW ? 1 : 0); |
switches | 31:ddedcb0e4e9e | 49 | printf("TMON: 0x%04x%s\n", adc_value, overflow ? "*" : " "); |
mbed_official | 22:af9dcf379926 | 50 | wait(0.5); |
Jonathan Austin |
0:2757d7abb7d9 | 51 | } |
Jonathan Austin |
0:2757d7abb7d9 | 52 | } |
Jonathan Austin |
1:846c97078558 | 53 |