Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 3:307c56629df0, committed 2014-07-09
- Comitter:
- greenroshks
- Date:
- Wed Jul 09 09:03:11 2014 +0000
- Parent:
- 2:1792c9cda669
- Commit message:
- updated with pranoy's hk
Changed in this revision
diff -r 1792c9cda669 -r 307c56629df0 HK.cpp --- a/HK.cpp Fri Jul 04 11:30:40 2014 +0000 +++ b/HK.cpp Wed Jul 09 09:03:11 2014 +0000 @@ -1,25 +1,42 @@ - -#include "HK.h" - - SensorData Sensor; +#include "HK.h" - DigitalOut SelectLine3 (p24); // MSB of Select Lines - - DigitalOut SelectLine2 (p23); +DigitalOut SelectLine3 (p24); // MSB of Select Lines +DigitalOut SelectLine2 (p23); +DigitalOut SelectLine1 (p22); +DigitalOut SelectLine0 (p21); // LSB of Select Lines - DigitalOut SelectLine1 (p22); - - DigitalOut SelectLine0 (p21); // LSB of Select Lines +AnalogIn CurrentInput(p15); // Input from Current Multiplexer +AnalogIn VoltageInput(p16); // Input from Voltage Multiplexer +AnalogIn TemperatureInput(p17); // input from Temperature Multiplexer + +SensorData Sensor; +int quantiz(float start,float step,float x) +{ + int y=(x-start)/step; + if(y<=0)y=0; + if(y>=15)y=15; + return y; +} - AnalogIn AnalogInput(p15); // Input from Multiplexer - +void init_beacon(ShortBeacy x){ + x.Voltage[0]=1; + x.AngularSpeed[0]=2; + x.AngularSpeed[1]=3; + x.SubsystemStatus[0]=145; + x.Temp[0]=1; + x.Temp[1]=2; + x.Temp[2]=3; + x.ErrorFlag[0]=3; +} - -void FUNC_HK_MAIN() +void FUNC_HK_MAIN() { + + ShortBeacy ShortBeacon; + init_beacon(ShortBeacon); int LoopIterator; - printf("\nHK invoked\n"); + SelectLine0=0; SelectLine1=0; SelectLine2=0; @@ -27,22 +44,16 @@ for(LoopIterator=0; LoopIterator<16; LoopIterator++) { - float SignalValue= AnalogInput.read()*3.180; // Calculation using ADC Reference - float Temperature=-90.7*SignalValue+190.1543; // Linear Equation for Temperature Sensor - - - if(LoopIterator%3==0) - Sensor.Current[LoopIterator/3]=SignalValue/4.37; // Equation for Current Sensor - - if(LoopIterator%3==1) - Sensor.Voltage[LoopIterator/3]=SignalValue*4.64; // Equation for Voltage Sensor || GAIN NEEDS TO BE CHANGED || - - - if(LoopIterator%3==2) - Sensor.Temp[LoopIterator/3]=Temperature; - - - // The following lines are used to iterate the select lines from 0 to 15 + if(LoopIterator%2==0) { + Sensor.Current[LoopIterator/2]=quantiz(cstart,cstep,(CurrentInput.read()/(50*rsens))); + Sensor.Voltage[LoopIterator/2]=quantiz(vstart,vstep,(VoltageInput.read()/5.37)); + Sensor.Temperature[LoopIterator/2]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); + } else { + Sensor.Current[(LoopIterator-1)/2]=Sensor.Current[LoopIterator-1]<<4+quantiz(cstart,cstep,(CurrentInput.read()/(50*rsens))); + Sensor.Voltage[(LoopIterator-1)/2]=Sensor.Voltage[LoopIterator-1]<<4+quantiz(vstart,vstep,(VoltageInput.read()/5.37)); + Sensor.Temperature[(LoopIterator-1)/2]=Sensor.Temperature[LoopIterator-1]<<4+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); + } +// The following lines are used to iterate the select lines from 0 to 15 SelectLine0=!(SelectLine0); if(LoopIterator%2==1) @@ -54,10 +65,8 @@ if(LoopIterator%8==7) SelectLine3=!(SelectLine3); - wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. + wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. + } -} - - - +} \ No newline at end of file
diff -r 1792c9cda669 -r 307c56629df0 HK.h --- a/HK.h Fri Jul 04 11:30:40 2014 +0000 +++ b/HK.h Wed Jul 09 09:03:11 2014 +0000 @@ -1,15 +1,32 @@ -#ifndef HK_H -#define HK_H #include "mbed.h" +#define tstart -40 +#define tstep 8 +#define vstart 3.3 +#define vstep 0.84667 +#define cstart 0.0691 +#define cstep 0.09133 +#define rsens 0.095 + + struct SensorData { - float Voltage[10]; - float Current[10]; - float Temp[10]; + char Voltage[10]; + char Current[10]; + char Temperature[10]; //float Battery[2]; -}; - +}; + +typedef struct ShortBeacon { + char Voltage[1]; + char AngularSpeed[2]; + char SubsystemStatus[1]; + char Temp[3]; + char ErrorFlag[1]; +}ShortBeacy; + void FUNC_HK_MAIN(); + +int quantiz(float start,float step,float x); + -#endif
diff -r 1792c9cda669 -r 307c56629df0 main.cpp --- a/main.cpp Fri Jul 04 11:30:40 2014 +0000 +++ b/main.cpp Wed Jul 09 09:03:11 2014 +0000 @@ -1,8 +1,9 @@ - #include "rtos.h" #include "HK.h" #include "slave.h" +#define _bool uint8_t +#define intmax 65531 //to allow smooth functioning of scheduler Serial pc(USBTX,USBRX); Timer t; Thread *t_acs; @@ -14,7 +15,7 @@ -int flag = 0; //for detecting keypress from computer +_bool beac_flag = 0; //for detecting keypress from computer /*---------------------------------------------------------------------------------------------------------------------------------------------------- @@ -261,7 +262,7 @@ printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state()); printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state()); - if(flag==0) + if(beac_flag==0) { FUNC_BEA_READBAERAM(); @@ -273,7 +274,7 @@ //led=1; Thread::wait(60000); - flag=0; + beac_flag=0; //myled=0; } } @@ -288,7 +289,7 @@ if(pc.getc()=='s') { pc.printf("\nTime of telecommand %f",t.read()); - flag=1; + beac_flag=1; } } } @@ -334,9 +335,13 @@ //---------------------------------------------------------------------------------------------------------------------------------------------- //Scheduler //---------------------------------------------------------------------------------------------------------------------------------------------- -int schedcount=1; +uint16_t schedcount=1; //the value will reset to 0 after reaching 65535 which again will reset to 0. void scheduler(void const * args) { + if(schedcount == intmax+1) //the value is reset at this value so as to ensure smooth flow, 65532 and 0 are divisible by 3 and 2. + { + schedcount =0; + } if(schedcount == 7) { int * fault_id = faults.alloc();
diff -r 1792c9cda669 -r 307c56629df0 slave.cpp --- a/slave.cpp Fri Jul 04 11:30:40 2014 +0000 +++ b/slave.cpp Wed Jul 09 09:03:11 2014 +0000 @@ -73,7 +73,7 @@ else if(loopvariable2%3==2) { screen.printf("\ntemp%d\n",loopvariable2/3); - split(Sensor.Temp[loopvariable2/3]); + split(Sensor.Temperature[loopvariable2/3]); } loopvariable2++; slave.stop();