This demo will read the Voltage and Current from the "AttoPilot Voltage and Current Sense Board," convert the raw ADC data to Volts and Amps and display them as floating point numbers on the Serial Enabled LCD. (If you would like to do without the Serial LCD, I have included commented code for reading the results through the Serial Terminal.)

Dependencies:   mbed

Committer:
gert_lauritsen
Date:
Wed Feb 17 22:09:53 2016 +0000
Revision:
0:40a765d1b46b
; This demo will read the Voltage and Current from the "AttoPilot Voltage and Current Sense Board,"; convert the raw ADC data to Volts and Amps and display them as floating point numbers on the; Serial Enabled LCD. (If you would like to do without the S

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gert_lauritsen 0:40a765d1b46b 1 #include "mbed.h"
gert_lauritsen 0:40a765d1b46b 2
gert_lauritsen 0:40a765d1b46b 3 RawSerial pc(USBTX, USBRX);
gert_lauritsen 0:40a765d1b46b 4 AnalogIn Ain1(p19);// --- AttoPilot "V"
gert_lauritsen 0:40a765d1b46b 5 AnalogIn Ain2(p20);// --- AttoPilot "I"
gert_lauritsen 0:40a765d1b46b 6
gert_lauritsen 0:40a765d1b46b 7 int VRaw; //This will store our raw ADC data
gert_lauritsen 0:40a765d1b46b 8 int IRaw;
gert_lauritsen 0:40a765d1b46b 9 float VFinal; //This will store the converted data
gert_lauritsen 0:40a765d1b46b 10 float IFinal;
gert_lauritsen 0:40a765d1b46b 11
gert_lauritsen 0:40a765d1b46b 12 int main()
gert_lauritsen 0:40a765d1b46b 13 {
gert_lauritsen 0:40a765d1b46b 14 while(1) {
gert_lauritsen 0:40a765d1b46b 15 VRaw = Ain1.read_u16();
gert_lauritsen 0:40a765d1b46b 16 IRaw = Ain2.read_u16();
gert_lauritsen 0:40a765d1b46b 17
gert_lauritsen 0:40a765d1b46b 18 //Conversion
gert_lauritsen 0:40a765d1b46b 19 VFinal = VRaw/49.44; //45 Amp board
gert_lauritsen 0:40a765d1b46b 20 //VFinal = VRaw/12.99; //90 Amp board
gert_lauritsen 0:40a765d1b46b 21 //VFinal = VRaw/12.99; //180 Amp board
gert_lauritsen 0:40a765d1b46b 22
gert_lauritsen 0:40a765d1b46b 23 IFinal = IRaw/14.9; //45 Amp board
gert_lauritsen 0:40a765d1b46b 24 //IFinal = IRaw/7.4; //90 Amp board
gert_lauritsen 0:40a765d1b46b 25 //IFinal = IRaw/3.7; //180 Amp board
gert_lauritsen 0:40a765d1b46b 26 pc.printf("%.1 Volts\r\n",VFinal);
gert_lauritsen 0:40a765d1b46b 27 pc.printf("%.1f Amps\r\n\r\n\r\n",IFinal);
gert_lauritsen 0:40a765d1b46b 28 wait(0.2);
gert_lauritsen 0:40a765d1b46b 29 }
gert_lauritsen 0:40a765d1b46b 30 }