![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
bae integrated final (may be)
Fork of BAE_FRDMTESIN2 by
HK.cpp@0:8b0d43fe6c05, 2014-09-10 (annotated)
- Committer:
- greenroshks
- Date:
- Wed Sep 10 06:41:21 2014 +0000
- Revision:
- 0:8b0d43fe6c05
- Child:
- 8:667fbc82d634
BAE FRDM Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
greenroshks | 0:8b0d43fe6c05 | 1 | #include "HK.h" |
greenroshks | 0:8b0d43fe6c05 | 2 | |
greenroshks | 0:8b0d43fe6c05 | 3 | DigitalOut SelectLine3 (D4); // MSB of Select Lines |
greenroshks | 0:8b0d43fe6c05 | 4 | DigitalOut SelectLine2 (D3); |
greenroshks | 0:8b0d43fe6c05 | 5 | DigitalOut SelectLine1 (D2); |
greenroshks | 0:8b0d43fe6c05 | 6 | DigitalOut SelectLine0 (D1); // LSB of Select Lines |
greenroshks | 0:8b0d43fe6c05 | 7 | |
greenroshks | 0:8b0d43fe6c05 | 8 | AnalogIn CurrentInput(A1); // Input from Current Multiplexer |
greenroshks | 0:8b0d43fe6c05 | 9 | AnalogIn VoltageInput(A2); // Input from Voltage Multiplexer |
greenroshks | 0:8b0d43fe6c05 | 10 | AnalogIn TemperatureInput(A3); // input from Temperature Multiplexer |
greenroshks | 0:8b0d43fe6c05 | 11 | |
greenroshks | 0:8b0d43fe6c05 | 12 | SensorData Sensor; |
greenroshks | 0:8b0d43fe6c05 | 13 | int quantiz(float start,float step,float x) |
greenroshks | 0:8b0d43fe6c05 | 14 | { |
greenroshks | 0:8b0d43fe6c05 | 15 | int y=(x-start)/step; |
greenroshks | 0:8b0d43fe6c05 | 16 | if(y<=0)y=0; |
greenroshks | 0:8b0d43fe6c05 | 17 | if(y>=15)y=15; |
greenroshks | 0:8b0d43fe6c05 | 18 | return y; |
greenroshks | 0:8b0d43fe6c05 | 19 | } |
greenroshks | 0:8b0d43fe6c05 | 20 | ShortBeacy Shortbeacon; |
greenroshks | 0:8b0d43fe6c05 | 21 | void init_beacon(ShortBeacy x){ |
greenroshks | 0:8b0d43fe6c05 | 22 | ; |
greenroshks | 0:8b0d43fe6c05 | 23 | } |
greenroshks | 0:8b0d43fe6c05 | 24 | |
greenroshks | 0:8b0d43fe6c05 | 25 | |
greenroshks | 0:8b0d43fe6c05 | 26 | void FUNC_HK_MAIN() |
greenroshks | 0:8b0d43fe6c05 | 27 | { |
greenroshks | 0:8b0d43fe6c05 | 28 | printf("\nEntered function HK MAIN\n"); |
greenroshks | 0:8b0d43fe6c05 | 29 | |
greenroshks | 0:8b0d43fe6c05 | 30 | Shortbeacon.Voltage[0]=1; |
greenroshks | 0:8b0d43fe6c05 | 31 | Shortbeacon.AngularSpeed[0]=2; |
greenroshks | 0:8b0d43fe6c05 | 32 | Shortbeacon.AngularSpeed[1]=3; |
greenroshks | 0:8b0d43fe6c05 | 33 | Shortbeacon.SubsystemStatus[0]=145; |
greenroshks | 0:8b0d43fe6c05 | 34 | Shortbeacon.Temp[0]=1; |
greenroshks | 0:8b0d43fe6c05 | 35 | Shortbeacon.Temp[1]=2; |
greenroshks | 0:8b0d43fe6c05 | 36 | Shortbeacon.Temp[2]=3; |
greenroshks | 0:8b0d43fe6c05 | 37 | Shortbeacon.ErrorFlag[0]=3; |
greenroshks | 0:8b0d43fe6c05 | 38 | |
greenroshks | 0:8b0d43fe6c05 | 39 | int LoopIterator; |
greenroshks | 0:8b0d43fe6c05 | 40 | |
greenroshks | 0:8b0d43fe6c05 | 41 | SelectLine0=0; |
greenroshks | 0:8b0d43fe6c05 | 42 | SelectLine1=0; |
greenroshks | 0:8b0d43fe6c05 | 43 | SelectLine2=0; |
greenroshks | 0:8b0d43fe6c05 | 44 | SelectLine3=0; |
greenroshks | 0:8b0d43fe6c05 | 45 | |
greenroshks | 0:8b0d43fe6c05 | 46 | for(LoopIterator=0; LoopIterator<16; LoopIterator++) { |
greenroshks | 0:8b0d43fe6c05 | 47 | |
greenroshks | 0:8b0d43fe6c05 | 48 | if(LoopIterator%2==0) { |
greenroshks | 0:8b0d43fe6c05 | 49 | Sensor.Current[LoopIterator/2]=quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens))); |
greenroshks | 0:8b0d43fe6c05 | 50 | Sensor.Voltage[LoopIterator/2]=quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37)); |
greenroshks | 0:8b0d43fe6c05 | 51 | Sensor.Temperature[LoopIterator/2]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); |
greenroshks | 0:8b0d43fe6c05 | 52 | } else { |
greenroshks | 0:8b0d43fe6c05 | 53 | Sensor.Current[(LoopIterator-1)/2]=(Sensor.Current[(LoopIterator-1)/2]<<4)+quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens))); |
greenroshks | 0:8b0d43fe6c05 | 54 | Sensor.Voltage[(LoopIterator-1)/2]=(Sensor.Voltage[(LoopIterator-1)/2]<<4)+quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37)); |
greenroshks | 0:8b0d43fe6c05 | 55 | Sensor.Temperature[(LoopIterator-1)/2]=(Sensor.Temperature[(LoopIterator-1)/2]<<4)+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); |
greenroshks | 0:8b0d43fe6c05 | 56 | } |
greenroshks | 0:8b0d43fe6c05 | 57 | // The following lines are used to iterate the select lines from 0 to 15 |
greenroshks | 0:8b0d43fe6c05 | 58 | SelectLine0=!(SelectLine0); |
greenroshks | 0:8b0d43fe6c05 | 59 | |
greenroshks | 0:8b0d43fe6c05 | 60 | if(LoopIterator%2==1) |
greenroshks | 0:8b0d43fe6c05 | 61 | SelectLine1=!(SelectLine1); |
greenroshks | 0:8b0d43fe6c05 | 62 | |
greenroshks | 0:8b0d43fe6c05 | 63 | if(LoopIterator%4==3) |
greenroshks | 0:8b0d43fe6c05 | 64 | SelectLine2=!(SelectLine2); |
greenroshks | 0:8b0d43fe6c05 | 65 | |
greenroshks | 0:8b0d43fe6c05 | 66 | if(LoopIterator%8==7) |
greenroshks | 0:8b0d43fe6c05 | 67 | SelectLine3=!(SelectLine3); |
greenroshks | 0:8b0d43fe6c05 | 68 | |
greenroshks | 0:8b0d43fe6c05 | 69 | wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. |
greenroshks | 0:8b0d43fe6c05 | 70 | |
greenroshks | 0:8b0d43fe6c05 | 71 | } |
greenroshks | 0:8b0d43fe6c05 | 72 | |
greenroshks | 0:8b0d43fe6c05 | 73 | printf("\nVoltage is %u\n",Shortbeacon.Voltage[0]); |
greenroshks | 0:8b0d43fe6c05 | 74 | printf("\nCurrent is %u\n",Shortbeacon.Temp[0]); |
greenroshks | 0:8b0d43fe6c05 | 75 | |
greenroshks | 0:8b0d43fe6c05 | 76 | |
greenroshks | 0:8b0d43fe6c05 | 77 | |
greenroshks | 0:8b0d43fe6c05 | 78 | printf("\nExited function HK MAIN\n"); |
greenroshks | 0:8b0d43fe6c05 | 79 | } |