Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AnalogIn_Diff by
AnalohIn_Diff.cpp@0:0f6f4be28e21, 2014-05-20 (annotated)
- Committer:
- JimCarver
- Date:
- Tue May 20 00:58:33 2014 +0000
- Revision:
- 0:0f6f4be28e21
- Child:
- 1:7b36e4381d83
A basic Library for the 16 bit Differential A/D in the K64F Freedom platform
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JimCarver | 0:0f6f4be28e21 | 1 | #include "mbed.h" |
| JimCarver | 0:0f6f4be28e21 | 2 | #include "AnalogIn_Diff.h" |
| JimCarver | 0:0f6f4be28e21 | 3 | |
| JimCarver | 0:0f6f4be28e21 | 4 | |
| JimCarver | 0:0f6f4be28e21 | 5 | AnalogIn_Diff::AnalogIn_Diff(int channel) : ch(channel) { |
| JimCarver | 0:0f6f4be28e21 | 6 | if(ch) BW_SIM_SCGC3_ADC1(1); |
| JimCarver | 0:0f6f4be28e21 | 7 | else BW_SIM_SCGC6_ADC0(1); |
| JimCarver | 0:0f6f4be28e21 | 8 | BW_ADC_SC1n_ADCH(ch, 0, 0x01); |
| JimCarver | 0:0f6f4be28e21 | 9 | BW_ADC_SC1n_DIFF(ch, 0, 1); |
| JimCarver | 0:0f6f4be28e21 | 10 | BW_ADC_CFG1_ADICLK(ch, 0); |
| JimCarver | 0:0f6f4be28e21 | 11 | BW_ADC_CFG1_MODE(ch, 3); |
| JimCarver | 0:0f6f4be28e21 | 12 | BW_ADC_CFG1_ADLSMP(ch, 0); // |
| JimCarver | 0:0f6f4be28e21 | 13 | BW_ADC_CFG1_ADIV(ch, 3); |
| JimCarver | 0:0f6f4be28e21 | 14 | BW_ADC_CFG1_ADLPC(ch, 0); |
| JimCarver | 0:0f6f4be28e21 | 15 | } |
| JimCarver | 0:0f6f4be28e21 | 16 | |
| JimCarver | 0:0f6f4be28e21 | 17 | AnalogIn_Diff::~AnalogIn_Diff() { } |
| JimCarver | 0:0f6f4be28e21 | 18 | |
| JimCarver | 0:0f6f4be28e21 | 19 | int16_t AnalogIn_Diff::read_16(void) { |
| JimCarver | 0:0f6f4be28e21 | 20 | BW_ADC_SC1n_ADCH(ch, 0, 0x01); |
| JimCarver | 0:0f6f4be28e21 | 21 | while(!BR_ADC_SC1n_COCO(ch, 0)); |
| JimCarver | 0:0f6f4be28e21 | 22 | return(BR_ADC_Rn_D(ch, 0)); |
| JimCarver | 0:0f6f4be28e21 | 23 | } |
| JimCarver | 0:0f6f4be28e21 | 24 | |
| JimCarver | 0:0f6f4be28e21 | 25 | float AnalogIn_Diff::read(void) { |
| JimCarver | 0:0f6f4be28e21 | 26 | int16_t i; |
| JimCarver | 0:0f6f4be28e21 | 27 | float t; |
| JimCarver | 0:0f6f4be28e21 | 28 | BW_ADC_SC1n_ADCH(ch, 0, 0x01); |
| JimCarver | 0:0f6f4be28e21 | 29 | while(!BR_ADC_SC1n_COCO(ch, 0)); |
| JimCarver | 0:0f6f4be28e21 | 30 | i = BR_ADC_Rn_D(ch, 0); |
| JimCarver | 0:0f6f4be28e21 | 31 | t = ((float) i); |
| JimCarver | 0:0f6f4be28e21 | 32 | t = t / 32768.0f; |
| JimCarver | 0:0f6f4be28e21 | 33 | return(t); |
| JimCarver | 0:0f6f4be28e21 | 34 | } |

ADC DIFF K64F