differential input adc board K64F Compatible hal freescale K64F

Dependents:   trms_helloworld AnalogIn_Diff_helloworld

Fork of AnalogIn_Diff by frederic blanc

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?

UserRevisionLine numberNew 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 }