![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
IGGE Power board
Dependencies: mbed ADS1015 USBDevice MCP4725
main.cpp
- Committer:
- jamesdem1123
- Date:
- 2014-04-01
- Revision:
- 3:a01ea06ca9ab
- Parent:
- 2:321c8783ea30
- Child:
- 4:d29a7b77b1c6
File content as of revision 3:a01ea06ca9ab:
#include "mbed.h" #include "Adafruit_ADS1015.h" #include "USBSerial.h" #define SERIAL_BAUD_RATE 9600 //library function setup I2C i2c(p28, p27); Adafruit_ADS1015 ads(&i2c); USBSerial pc; // USB CDC serial port CAN cantbus(p30, p29); Ticker graph; //leds DigitalOut led0(LED1); DigitalOut led1(LED2); DigitalOut led2(LED3); DigitalOut led3(LED4); //current readings AnalogIn iBat(p15); //75a AnalogIn iTwelve(p17); //31a AnalogIn iFive(p18);//31a AnalogIn iMot(p16);//75a AnalogIn iCpu(p20);//31a AnalogIn iPeri(p19);//31a //voltage scalers #define batScal 12.2 #define motScal 12.2 #define twelveScal 12.2 #define fiveScal 12.2 //Relays DigitalOut relSens(p21); DigitalOut relUsr(p22); DigitalOut relNet(p23); DigitalOut relCpuRst(p24); DigitalOut relCpuPower(p25); //30 minute graph arrays uint16_t iBatArr [180]; uint16_t vBatArr [180]; uint16_t iTwelveArr [180]; uint16_t vTwelveArr [180]; uint16_t iFiveArr [180]; uint16_t vFiveArr [180]; uint16_t iMotArr [180]; uint16_t vMotArr [180]; uint16_t iCpuArr [180]; uint16_t iPeriArr [180]; //volt uint16_t vBat, vTwelve,vFive,vMot ; void updateArray (void) { vBat = ads.readADC_SingleEnded(0); // read channel 0 vTwelve = ads.readADC_SingleEnded(1); // read channel 0 vFive = ads.readADC_SingleEnded(2); // read channel 0 vMot = ads.readADC_SingleEnded(3); // read channel 0 for(int i =179; i >0; i--) { iBatArr[i] =iBatArr[i-1]; } iBatArr[0]= iBat.read_u16(); for(int i =179; i >0; i--) { vBatArr[i] =vBatArr[i-1]; } vBatArr[0]= vBat; for(int i =179; i >0; i--) { iTwelveArr[i] =iTwelveArr[i-1]; } iTwelveArr[0]= iTwelve.read_u16(); for(int i =179; i >0; i--) { vTwelveArr[i] =vTwelveArr[i-1]; } vTwelveArr[0]= vTwelve; for(int i =179; i >0; i--) { iFiveArr[i] =iFiveArr[i-1]; } iFiveArr[0]= iFive.read_u16(); for(int i =179; i >0; i--) { vFiveArr[i] =vFiveArr[i-1]; } vFiveArr[0]= vFive; for(int i =179; i >0; i--) { iMotArr[i] =iMotArr[i-1]; } iMotArr[0]= iMot.read_u16(); for(int i =179; i >0; i--) { vMotArr[i] =vMotArr[i-1]; } vMotArr[0]= vMot; for(int i =179; i >0; i--) { iCpuArr[i] =iCpuArr[i-1]; } iCpuArr[0]= iCpu.read_u16(); for(int i =179; i >0; i--) { iPeriArr[i] =iPeriArr[i-1]; } iPeriArr[0]= iPeri.read_u16(); led0= !led0; } void setup(void) { graph.attach(&updateArray, 10); //update array every 10 seconds cantbus.frequency(500000); CANMessage can_MsgRx; //initialize relays relSens= 0; relNet =0; relCpuPower=0; relCpuRst =0; relUsr=0; } int main() { setup(); graph.attach(updateArray, 1); //update array every 10 seconds cantbus.frequency(500000); CANMessage can_MsgRx; //initialize relays relSens= 0; relNet =0; relCpuPower=0; relCpuRst =0; relUsr=0; while (1) { pc.printf("reading: %d\r\n", vBat); // print reading pc.printf("reading: %d\r\n", vTwelve); // print reading pc.printf("reading: %d\r\n", vFive); // print reading pc.printf("reading: %d\r\n", vMot); // print reading wait(2); } }