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
Revision 0:0f6f4be28e21, committed 2014-05-20
- Comitter:
- JimCarver
- Date:
- Tue May 20 00:58:33 2014 +0000
- Child:
- 1:7b36e4381d83
- Commit message:
- A basic Library for the 16 bit Differential A/D in the K64F Freedom platform
Changed in this revision
AnalogIn_Diff.h | Show annotated file Show diff for this revision Revisions of this file |
AnalohIn_Diff.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AnalogIn_Diff.h Tue May 20 00:58:33 2014 +0000 @@ -0,0 +1,26 @@ + +#ifndef K64F_DIFF_A2D_H +#define K64F_DIFF_A2D_H + +#include "mbed.h" + + +class AnalogIn_Diff +{ +public: + AnalogIn_Diff(int channel); + + /** + * AnalogIn_Diff destructor + */ + ~AnalogIn_Diff(); + int16_t read_16(void); + float read(void); + +private: + + int ch; + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AnalohIn_Diff.cpp Tue May 20 00:58:33 2014 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" +#include "AnalogIn_Diff.h" + + +AnalogIn_Diff::AnalogIn_Diff(int channel) : ch(channel) { + if(ch) BW_SIM_SCGC3_ADC1(1); + else BW_SIM_SCGC6_ADC0(1); + BW_ADC_SC1n_ADCH(ch, 0, 0x01); + BW_ADC_SC1n_DIFF(ch, 0, 1); + BW_ADC_CFG1_ADICLK(ch, 0); + BW_ADC_CFG1_MODE(ch, 3); + BW_ADC_CFG1_ADLSMP(ch, 0); // + BW_ADC_CFG1_ADIV(ch, 3); + BW_ADC_CFG1_ADLPC(ch, 0); +} + +AnalogIn_Diff::~AnalogIn_Diff() { } + +int16_t AnalogIn_Diff::read_16(void) { + BW_ADC_SC1n_ADCH(ch, 0, 0x01); + while(!BR_ADC_SC1n_COCO(ch, 0)); + return(BR_ADC_Rn_D(ch, 0)); +} + +float AnalogIn_Diff::read(void) { + int16_t i; + float t; + BW_ADC_SC1n_ADCH(ch, 0, 0x01); + while(!BR_ADC_SC1n_COCO(ch, 0)); + i = BR_ADC_Rn_D(ch, 0); + t = ((float) i); + t = t / 32768.0f; + return(t); +}