Bharath S
/
mbed_hkey
HK sensor acq pls
HK.c@0:d3502c903f56, 2014-06-26 (annotated)
- Committer:
- nbharaths
- Date:
- Thu Jun 26 08:13:48 2014 +0000
- Revision:
- 0:d3502c903f56
hkey pls;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nbharaths | 0:d3502c903f56 | 1 | |
nbharaths | 0:d3502c903f56 | 2 | struct SensorData { |
nbharaths | 0:d3502c903f56 | 3 | float Voltage[10]; |
nbharaths | 0:d3502c903f56 | 4 | float Current[10]; |
nbharaths | 0:d3502c903f56 | 5 | float Temp[10]; |
nbharaths | 0:d3502c903f56 | 6 | //float Battery[2]; |
nbharaths | 0:d3502c903f56 | 7 | } SensorData; |
nbharaths | 0:d3502c903f56 | 8 | |
nbharaths | 0:d3502c903f56 | 9 | |
nbharaths | 0:d3502c903f56 | 10 | void FUNC_HK_MAIN() |
nbharaths | 0:d3502c903f56 | 11 | { |
nbharaths | 0:d3502c903f56 | 12 | |
nbharaths | 0:d3502c903f56 | 13 | int LoopIterator; |
nbharaths | 0:d3502c903f56 | 14 | |
nbharaths | 0:d3502c903f56 | 15 | SelectLine0=0; |
nbharaths | 0:d3502c903f56 | 16 | SelectLine1=0; |
nbharaths | 0:d3502c903f56 | 17 | SelectLine2=0; |
nbharaths | 0:d3502c903f56 | 18 | SelectLine3=0; |
nbharaths | 0:d3502c903f56 | 19 | |
nbharaths | 0:d3502c903f56 | 20 | for(LoopIterator=0; LoopIterator<16; LoopIterator++) { |
nbharaths | 0:d3502c903f56 | 21 | |
nbharaths | 0:d3502c903f56 | 22 | float SignalValue= AnalogInput.read()*3.180; // Calculation using ADC Reference |
nbharaths | 0:d3502c903f56 | 23 | float Temperature=-90.7*SignalValue+190.1543; // Linear Equation for Temperature Sensor |
nbharaths | 0:d3502c903f56 | 24 | |
nbharaths | 0:d3502c903f56 | 25 | |
nbharaths | 0:d3502c903f56 | 26 | if(LoopIterator%3==0) |
nbharaths | 0:d3502c903f56 | 27 | SensorData.Current[LoopIterator/3]=SignalValue/4.37; // Equation for Current Sensor |
nbharaths | 0:d3502c903f56 | 28 | |
nbharaths | 0:d3502c903f56 | 29 | if(LoopIterator%3==1) |
nbharaths | 0:d3502c903f56 | 30 | SensorData.Voltage[LoopIterator/3]=SignalValue*4.64; // Equation for Voltage Sensor || GAIN NEEDS TO BE CHANGED || |
nbharaths | 0:d3502c903f56 | 31 | |
nbharaths | 0:d3502c903f56 | 32 | |
nbharaths | 0:d3502c903f56 | 33 | if(LoopIterator%3==2) |
nbharaths | 0:d3502c903f56 | 34 | SensorData.Temp[LoopIterator/3]=Temperature; |
nbharaths | 0:d3502c903f56 | 35 | |
nbharaths | 0:d3502c903f56 | 36 | |
nbharaths | 0:d3502c903f56 | 37 | // The following lines are used to iterate the select lines from 0 to 15 |
nbharaths | 0:d3502c903f56 | 38 | SelectLine0=!(SelectLine0); |
nbharaths | 0:d3502c903f56 | 39 | |
nbharaths | 0:d3502c903f56 | 40 | if(LoopIterator%2==1) |
nbharaths | 0:d3502c903f56 | 41 | SelectLine1=!(SelectLine1); |
nbharaths | 0:d3502c903f56 | 42 | |
nbharaths | 0:d3502c903f56 | 43 | if(LoopIterator%4==3) |
nbharaths | 0:d3502c903f56 | 44 | SelectLine2=!(SelectLine2); |
nbharaths | 0:d3502c903f56 | 45 | |
nbharaths | 0:d3502c903f56 | 46 | if(LoopIterator%8==7) |
nbharaths | 0:d3502c903f56 | 47 | SelectLine3=!(SelectLine3); |
nbharaths | 0:d3502c903f56 | 48 | |
nbharaths | 0:d3502c903f56 | 49 | wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. |
nbharaths | 0:d3502c903f56 | 50 | } |
nbharaths | 0:d3502c903f56 | 51 | |
nbharaths | 0:d3502c903f56 | 52 | } |
nbharaths | 0:d3502c903f56 | 53 |