![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
working code of bae with i2c
Fork of all_combined_week6 by
HK.cpp@4:79b97f9cab00, 2014-07-12 (annotated)
- Committer:
- greenroshks
- Date:
- Sat Jul 12 07:26:06 2014 +0000
- Revision:
- 4:79b97f9cab00
- Child:
- 6:82153349cc9b
Version (may be) final
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:79b97f9cab00 | 32 | void FUNC_HK_MAIN() |
greenroshks | 4:79b97f9cab00 | 33 | { |
greenroshks | 4:79b97f9cab00 | 34 | |
greenroshks | 4:79b97f9cab00 | 35 | ShortBeacy ShortBeacon; |
greenroshks | 4:79b97f9cab00 | 36 | init_beacon(ShortBeacon); |
greenroshks | 4:79b97f9cab00 | 37 | |
greenroshks | 4:79b97f9cab00 | 38 | int LoopIterator; |
greenroshks | 4:79b97f9cab00 | 39 | |
greenroshks | 4:79b97f9cab00 | 40 | SelectLine0=0; |
greenroshks | 4:79b97f9cab00 | 41 | SelectLine1=0; |
greenroshks | 4:79b97f9cab00 | 42 | SelectLine2=0; |
greenroshks | 4:79b97f9cab00 | 43 | SelectLine3=0; |
greenroshks | 4:79b97f9cab00 | 44 | |
greenroshks | 4:79b97f9cab00 | 45 | for(LoopIterator=0; LoopIterator<16; LoopIterator++) { |
greenroshks | 4:79b97f9cab00 | 46 | |
greenroshks | 4:79b97f9cab00 | 47 | if(LoopIterator%2==0) { |
greenroshks | 4:79b97f9cab00 | 48 | Sensor.Current[LoopIterator/2]=quantiz(cstart,cstep,(CurrentInput.read()/(50*rsens))); |
greenroshks | 4:79b97f9cab00 | 49 | Sensor.Voltage[LoopIterator/2]=quantiz(vstart,vstep,(VoltageInput.read()/5.37)); |
greenroshks | 4:79b97f9cab00 | 50 | Sensor.Temperature[LoopIterator/2]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); |
greenroshks | 4:79b97f9cab00 | 51 | } else { |
greenroshks | 4:79b97f9cab00 | 52 | Sensor.Current[(LoopIterator-1)/2]=Sensor.Current[LoopIterator-1]<<4+quantiz(cstart,cstep,(CurrentInput.read()/(50*rsens))); |
greenroshks | 4:79b97f9cab00 | 53 | Sensor.Voltage[(LoopIterator-1)/2]=Sensor.Voltage[LoopIterator-1]<<4+quantiz(vstart,vstep,(VoltageInput.read()/5.37)); |
greenroshks | 4:79b97f9cab00 | 54 | Sensor.Temperature[(LoopIterator-1)/2]=Sensor.Temperature[LoopIterator-1]<<4+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); |
greenroshks | 4:79b97f9cab00 | 55 | } |
greenroshks | 4:79b97f9cab00 | 56 | // The following lines are used to iterate the select lines from 0 to 15 |
greenroshks | 4:79b97f9cab00 | 57 | SelectLine0=!(SelectLine0); |
greenroshks | 4:79b97f9cab00 | 58 | |
greenroshks | 4:79b97f9cab00 | 59 | if(LoopIterator%2==1) |
greenroshks | 4:79b97f9cab00 | 60 | SelectLine1=!(SelectLine1); |
greenroshks | 4:79b97f9cab00 | 61 | |
greenroshks | 4:79b97f9cab00 | 62 | if(LoopIterator%4==3) |
greenroshks | 4:79b97f9cab00 | 63 | SelectLine2=!(SelectLine2); |
greenroshks | 4:79b97f9cab00 | 64 | |
greenroshks | 4:79b97f9cab00 | 65 | if(LoopIterator%8==7) |
greenroshks | 4:79b97f9cab00 | 66 | SelectLine3=!(SelectLine3); |
greenroshks | 4:79b97f9cab00 | 67 | |
greenroshks | 4:79b97f9cab00 | 68 | wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. |
greenroshks | 4:79b97f9cab00 | 69 | |
greenroshks | 4:79b97f9cab00 | 70 | } |
greenroshks | 4:79b97f9cab00 | 71 | |
greenroshks | 4:79b97f9cab00 | 72 | } |