working code of bae with i2c

Dependencies:   mbed-rtos mbed

Fork of all_combined_week6 by green rosh

Committer:
greenroshks
Date:
Tue Jul 15 10:04:38 2014 +0000
Revision:
6:82153349cc9b
Parent:
4:79b97f9cab00
BAE RTOS final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
greenroshks 4:79b97f9cab00 1 #include "HK.h"
greenroshks 4:79b97f9cab00 2
greenroshks 4:79b97f9cab00 3 DigitalOut SelectLine3 (p24); // MSB of Select Lines
greenroshks 4:79b97f9cab00 4 DigitalOut SelectLine2 (p23);
greenroshks 4:79b97f9cab00 5 DigitalOut SelectLine1 (p22);
greenroshks 4:79b97f9cab00 6 DigitalOut SelectLine0 (p21); // LSB of Select Lines
greenroshks 4:79b97f9cab00 7
greenroshks 4:79b97f9cab00 8 AnalogIn CurrentInput(p15); // Input from Current Multiplexer
greenroshks 4:79b97f9cab00 9 AnalogIn VoltageInput(p16); // Input from Voltage Multiplexer
greenroshks 4:79b97f9cab00 10 AnalogIn TemperatureInput(p17); // input from Temperature Multiplexer
greenroshks 4:79b97f9cab00 11
greenroshks 4:79b97f9cab00 12 SensorData Sensor;
greenroshks 4:79b97f9cab00 13 int quantiz(float start,float step,float x)
greenroshks 4:79b97f9cab00 14 {
greenroshks 4:79b97f9cab00 15 int y=(x-start)/step;
greenroshks 4:79b97f9cab00 16 if(y<=0)y=0;
greenroshks 4:79b97f9cab00 17 if(y>=15)y=15;
greenroshks 4:79b97f9cab00 18 return y;
greenroshks 4:79b97f9cab00 19 }
greenroshks 4:79b97f9cab00 20
greenroshks 4:79b97f9cab00 21 void init_beacon(ShortBeacy x){
greenroshks 4:79b97f9cab00 22 x.Voltage[0]=1;
greenroshks 4:79b97f9cab00 23 x.AngularSpeed[0]=2;
greenroshks 4:79b97f9cab00 24 x.AngularSpeed[1]=3;
greenroshks 4:79b97f9cab00 25 x.SubsystemStatus[0]=145;
greenroshks 4:79b97f9cab00 26 x.Temp[0]=1;
greenroshks 4:79b97f9cab00 27 x.Temp[1]=2;
greenroshks 4:79b97f9cab00 28 x.Temp[2]=3;
greenroshks 4:79b97f9cab00 29 x.ErrorFlag[0]=3;
greenroshks 4:79b97f9cab00 30 }
greenroshks 4:79b97f9cab00 31
greenroshks 6:82153349cc9b 32 ShortBeacy Shortbeacon;
greenroshks 4:79b97f9cab00 33 void FUNC_HK_MAIN()
greenroshks 4:79b97f9cab00 34 {
greenroshks 6:82153349cc9b 35 printf("\nEntered function HK MAIN\n");
greenroshks 4:79b97f9cab00 36
greenroshks 6:82153349cc9b 37 init_beacon(Shortbeacon);
greenroshks 4:79b97f9cab00 38
greenroshks 4:79b97f9cab00 39 int LoopIterator;
greenroshks 4:79b97f9cab00 40
greenroshks 4:79b97f9cab00 41 SelectLine0=0;
greenroshks 4:79b97f9cab00 42 SelectLine1=0;
greenroshks 4:79b97f9cab00 43 SelectLine2=0;
greenroshks 4:79b97f9cab00 44 SelectLine3=0;
greenroshks 4:79b97f9cab00 45
greenroshks 4:79b97f9cab00 46 for(LoopIterator=0; LoopIterator<16; LoopIterator++) {
greenroshks 4:79b97f9cab00 47
greenroshks 4:79b97f9cab00 48 if(LoopIterator%2==0) {
greenroshks 6:82153349cc9b 49 Sensor.Current[LoopIterator/2]=quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens)));
greenroshks 6:82153349cc9b 50 Sensor.Voltage[LoopIterator/2]=quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37));
greenroshks 4:79b97f9cab00 51 Sensor.Temperature[LoopIterator/2]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
greenroshks 4:79b97f9cab00 52 } else {
greenroshks 6:82153349cc9b 53 Sensor.Current[(LoopIterator-1)/2]=(Sensor.Current[(LoopIterator-1)/2]<<4)+quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens)));
greenroshks 6:82153349cc9b 54 Sensor.Voltage[(LoopIterator-1)/2]=(Sensor.Voltage[(LoopIterator-1)/2]<<4)+quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37));
greenroshks 6:82153349cc9b 55 Sensor.Temperature[(LoopIterator-1)/2]=(Sensor.Temperature[(LoopIterator-1)/2]<<4)+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
greenroshks 4:79b97f9cab00 56 }
greenroshks 4:79b97f9cab00 57 // The following lines are used to iterate the select lines from 0 to 15
greenroshks 4:79b97f9cab00 58 SelectLine0=!(SelectLine0);
greenroshks 4:79b97f9cab00 59
greenroshks 4:79b97f9cab00 60 if(LoopIterator%2==1)
greenroshks 4:79b97f9cab00 61 SelectLine1=!(SelectLine1);
greenroshks 4:79b97f9cab00 62
greenroshks 4:79b97f9cab00 63 if(LoopIterator%4==3)
greenroshks 4:79b97f9cab00 64 SelectLine2=!(SelectLine2);
greenroshks 4:79b97f9cab00 65
greenroshks 4:79b97f9cab00 66 if(LoopIterator%8==7)
greenroshks 4:79b97f9cab00 67 SelectLine3=!(SelectLine3);
greenroshks 4:79b97f9cab00 68
greenroshks 4:79b97f9cab00 69 wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed.
greenroshks 4:79b97f9cab00 70
greenroshks 4:79b97f9cab00 71 }
greenroshks 6:82153349cc9b 72 for(int i=0;i<8;i++)
greenroshks 6:82153349cc9b 73 {
greenroshks 6:82153349cc9b 74 printf("\nVoltage %d is %u\n",i,Sensor.Voltage[i]);
greenroshks 6:82153349cc9b 75 printf("\nCurrent %d is %u\n",i,Sensor.Current[i]);
greenroshks 6:82153349cc9b 76 printf("\nTemperature %d is %u\n",i,Sensor.Temperature[i]);
greenroshks 6:82153349cc9b 77 }
greenroshks 6:82153349cc9b 78
greenroshks 6:82153349cc9b 79 printf("\nExited function HK MAIN\n");
greenroshks 4:79b97f9cab00 80 }