hk tentative jul 9

Dependencies:   mbed

Fork of mbed_hkfinal by Bharath S

Committer:
nbharaths
Date:
Tue Jul 08 16:03:07 2014 +0000
Revision:
0:333cda053c40
Child:
1:8b8bc4aef6f9
HkFinal;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nbharaths 0:333cda053c40 1 struct SensorData {
nbharaths 0:333cda053c40 2 char Voltage[10];
nbharaths 0:333cda053c40 3 char Current[10];
nbharaths 0:333cda053c40 4 char Temperature[10];
nbharaths 0:333cda053c40 5 //float Battery[2];
nbharaths 0:333cda053c40 6 } SensorData;
nbharaths 0:333cda053c40 7
nbharaths 0:333cda053c40 8 int quantiz(float start,float step,float x)
nbharaths 0:333cda053c40 9 {
nbharaths 0:333cda053c40 10 int y=((x*3.18/65536)-start)/step;
nbharaths 0:333cda053c40 11 if(y<=0)y=0;
nbharaths 0:333cda053c40 12 if(y>=15)y=15;
nbharaths 0:333cda053c40 13 return y;
nbharaths 0:333cda053c40 14 }
nbharaths 0:333cda053c40 15
nbharaths 0:333cda053c40 16 void FUNC_HK_MAIN()
nbharaths 0:333cda053c40 17 {
nbharaths 0:333cda053c40 18
nbharaths 0:333cda053c40 19 int LoopIterator;
nbharaths 0:333cda053c40 20
nbharaths 0:333cda053c40 21 SelectLine0=0;
nbharaths 0:333cda053c40 22 SelectLine1=0;
nbharaths 0:333cda053c40 23 SelectLine2=0;
nbharaths 0:333cda053c40 24 SelectLine3=0;
nbharaths 0:333cda053c40 25
nbharaths 0:333cda053c40 26 for(LoopIterator=0; LoopIterator<16; LoopIterator++) {
nbharaths 0:333cda053c40 27
nbharaths 0:333cda053c40 28 if(LoopIterator%2==0) {
nbharaths 0:333cda053c40 29 SensorData.Current[LoopIterator]=quantiz(start,step,CurrentInput.read_u16());
nbharaths 0:333cda053c40 30 SensorData.Voltage[LoopIterator]=quantiz(start,step,VoltageInput.read_u16());
nbharaths 0:333cda053c40 31 SensorData.Temperature[LoopIterator]=quantiz(start,step,TemperatureInput.read_u16());
nbharaths 0:333cda053c40 32 } else {
nbharaths 0:333cda053c40 33 SensorData.Current[LoopIterator-1]=Current[LoopIterator-1]<<4+quantiz(start,step,CurrentInput.read_u16());
nbharaths 0:333cda053c40 34 SensorData.Voltage[LoopIterator-1]=Voltage[LoopIterator-1]<<4+quantiz(start,step,VoltageInput.read_u16());
nbharaths 0:333cda053c40 35 SensorData.Temperature[LoopIterator-1]=Temperature[LoopIterator-1]<<4+quantiz(start,step,TemperatureInput.read_u16());
nbharaths 0:333cda053c40 36 }
nbharaths 0:333cda053c40 37 // The following lines are used to iterate the select lines from 0 to 15
nbharaths 0:333cda053c40 38 SelectLine0=!(SelectLine0);
nbharaths 0:333cda053c40 39
nbharaths 0:333cda053c40 40 if(LoopIterator%2==1)
nbharaths 0:333cda053c40 41 SelectLine1=!(SelectLine1);
nbharaths 0:333cda053c40 42
nbharaths 0:333cda053c40 43 if(LoopIterator%4==3)
nbharaths 0:333cda053c40 44 SelectLine2=!(SelectLine2);
nbharaths 0:333cda053c40 45
nbharaths 0:333cda053c40 46 if(LoopIterator%8==7)
nbharaths 0:333cda053c40 47 SelectLine3=!(SelectLine3);
nbharaths 0:333cda053c40 48
nbharaths 0:333cda053c40 49 wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed.
nbharaths 0:333cda053c40 50
nbharaths 0:333cda053c40 51 }
nbharaths 0:333cda053c40 52
nbharaths 0:333cda053c40 53 }