Joel Pallent
/
Elec241-adc
c
TEST.cpp@0:7088bc4c9949, 2018-05-31 (annotated)
- Committer:
- Joelpallent
- Date:
- Thu May 31 19:30:01 2018 +0000
- Revision:
- 0:7088bc4c9949
c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Joelpallent | 0:7088bc4c9949 | 1 | #include <stm32f4xx.h> |
Joelpallent | 0:7088bc4c9949 | 2 | #include <stdio.h> |
Joelpallent | 0:7088bc4c9949 | 3 | #include "ADC.h" |
Joelpallent | 0:7088bc4c9949 | 4 | #include "PLL_Config.c" |
Joelpallent | 0:7088bc4c9949 | 5 | #include "ADC.c" |
Joelpallent | 0:7088bc4c9949 | 6 | |
Joelpallent | 0:7088bc4c9949 | 7 | |
Joelpallent | 0:7088bc4c9949 | 8 | float adc_data_f = 0; |
Joelpallent | 0:7088bc4c9949 | 9 | unsigned short ADC_DATA = 0; |
Joelpallent | 0:7088bc4c9949 | 10 | |
Joelpallent | 0:7088bc4c9949 | 11 | int main(void) |
Joelpallent | 0:7088bc4c9949 | 12 | { |
Joelpallent | 0:7088bc4c9949 | 13 | |
Joelpallent | 0:7088bc4c9949 | 14 | //PLL_Config(); |
Joelpallent | 0:7088bc4c9949 | 15 | SystemCoreClockUpdate(); |
Joelpallent | 0:7088bc4c9949 | 16 | |
Joelpallent | 0:7088bc4c9949 | 17 | init_ADC(); //config ADC |
Joelpallent | 0:7088bc4c9949 | 18 | |
Joelpallent | 0:7088bc4c9949 | 19 | while(1) |
Joelpallent | 0:7088bc4c9949 | 20 | { |
Joelpallent | 0:7088bc4c9949 | 21 | ADC_DATA=read_adc(); //read value from ADC |
Joelpallent | 0:7088bc4c9949 | 22 | |
Joelpallent | 0:7088bc4c9949 | 23 | adc_data_f=(float)ADC_DATA; |
Joelpallent | 0:7088bc4c9949 | 24 | adc_data_f/=1000.0f; |
Joelpallent | 0:7088bc4c9949 | 25 | adc_data_f = adc_data_f*0.80513; |
Joelpallent | 0:7088bc4c9949 | 26 | printf("voltage = %0.2fv\n " , adc_data_f ); |
Joelpallent | 0:7088bc4c9949 | 27 | |
Joelpallent | 0:7088bc4c9949 | 28 | |
Joelpallent | 0:7088bc4c9949 | 29 | } |
Joelpallent | 0:7088bc4c9949 | 30 | |
Joelpallent | 0:7088bc4c9949 | 31 | } |