acs beacon and hk integrated

Dependencies:   mbed-rtos mbed

Committer:
sakthipriya
Date:
Sat May 16 07:07:56 2015 +0000
Revision:
0:1a04c0beef21
acs beacon and hk integrated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sakthipriya 0:1a04c0beef21 1 #include "HK.h"
sakthipriya 0:1a04c0beef21 2 #include "pin_config.h"
sakthipriya 0:1a04c0beef21 3
sakthipriya 0:1a04c0beef21 4
sakthipriya 0:1a04c0beef21 5 //GPIO pins used=> D2-D12, A0-A1
sakthipriya 0:1a04c0beef21 6
sakthipriya 0:1a04c0beef21 7 DigitalOut SelectLinesA[]={PIN43,PIN44,PIN45,PIN46}; //to mux1=>voltage mux , PTA 13-16 , CHNGE TO PIN43 LATER
sakthipriya 0:1a04c0beef21 8 DigitalOut SelectLinesB[]={PIN56,PIN57,PIN58,PIN59}; //to mux2=>current mux(differential mux) , PTB 3,7,8,9
sakthipriya 0:1a04c0beef21 9 DigitalOut SelectLinesC[]={PIN64,PIN65,PIN66,PIN67}; //to mux3=>temp mux PTB 18-21
sakthipriya 0:1a04c0beef21 10
sakthipriya 0:1a04c0beef21 11 //--------------------------------------------MSB is SelectLines[0],LSB is SelectLines[3]--------------------------------
sakthipriya 0:1a04c0beef21 12
sakthipriya 0:1a04c0beef21 13 AnalogIn CurrentInput(PIN53); // output from Current Mux PTB0
sakthipriya 0:1a04c0beef21 14 AnalogIn VoltageInput(PIN54); // output from Voltage Multiplexer PTB1
sakthipriya 0:1a04c0beef21 15 AnalogIn TemperatureInput(PIN55); /*PTB2 output from Temperature Multiplexer,thermistor Multiplexer- same multiplexer for both(lines 1-4 for thermistor,line 0 for temperature sensor)*/
sakthipriya 0:1a04c0beef21 16
sakthipriya 0:1a04c0beef21 17
sakthipriya 0:1a04c0beef21 18
sakthipriya 0:1a04c0beef21 19 int quantiz(float start,float step,float x) // accepts min and measured values and step->quantises on a scale 0-15..(4 bit quantisation)
sakthipriya 0:1a04c0beef21 20 {
sakthipriya 0:1a04c0beef21 21 int y=(x-start)/step;
sakthipriya 0:1a04c0beef21 22 if(y<=0)y=0;
sakthipriya 0:1a04c0beef21 23 if(y>=15)y=15;
sakthipriya 0:1a04c0beef21 24 return y;
sakthipriya 0:1a04c0beef21 25 }
sakthipriya 0:1a04c0beef21 26
sakthipriya 0:1a04c0beef21 27 void init_beacon(ShortBeacy* x,SensorDataQuantised y)
sakthipriya 0:1a04c0beef21 28 {
sakthipriya 0:1a04c0beef21 29 (*x).Voltage[0]=2; //quantised value
sakthipriya 0:1a04c0beef21 30 (*x).Temp[0]=y.PanelTemperature[0]; //quantised value
sakthipriya 0:1a04c0beef21 31 (*x).Temp[1]=y.PanelTemperature[1]; //quantised value
sakthipriya 0:1a04c0beef21 32 (*x).AngularSpeed[0]=y.AngularSpeed[0];
sakthipriya 0:1a04c0beef21 33 (*x).AngularSpeed[1]=y.AngularSpeed[1];
sakthipriya 0:1a04c0beef21 34
sakthipriya 0:1a04c0beef21 35 (*x).SubsystemStatus[0]=145; //dummy values----------to be changed-------------------
sakthipriya 0:1a04c0beef21 36 (*x).ErrorFlag[0]=3; //dummy values----------to be changed-------------------
sakthipriya 0:1a04c0beef21 37 }
sakthipriya 0:1a04c0beef21 38
sakthipriya 0:1a04c0beef21 39 SensorData Sensor;
sakthipriya 0:1a04c0beef21 40 SensorDataQuantised SensorQuantised;
sakthipriya 0:1a04c0beef21 41 ShortBeacy Shortbeacon;
sakthipriya 0:1a04c0beef21 42 void FUNC_HK_MAIN()
sakthipriya 0:1a04c0beef21 43 {
sakthipriya 0:1a04c0beef21 44 //define structure variables
sakthipriya 0:1a04c0beef21 45
sakthipriya 0:1a04c0beef21 46 //initialise all selectlines to zeroes->1st line of muxes selected
sakthipriya 0:1a04c0beef21 47 SelectLinesA[0]=SelectLinesA[1]=SelectLinesA[2]=SelectLinesA[3]=0;
sakthipriya 0:1a04c0beef21 48 SelectLinesB[0]=SelectLinesB[1]=SelectLinesB[2]=0;
sakthipriya 0:1a04c0beef21 49 SelectLinesC[0]=SelectLinesC[1]=SelectLinesC[2]=SelectLinesC[3]=0;
sakthipriya 0:1a04c0beef21 50
sakthipriya 0:1a04c0beef21 51 int LoopIterator;
sakthipriya 0:1a04c0beef21 52 int SelectLineIterator;
sakthipriya 0:1a04c0beef21 53
sakthipriya 0:1a04c0beef21 54 float resistance_thermistor,voltage_thermistor;//for thermistor
sakthipriya 0:1a04c0beef21 55
sakthipriya 0:1a04c0beef21 56 //measurement from voltage sensor=> 16 sensors in place
sakthipriya 0:1a04c0beef21 57 for(LoopIterator=0; LoopIterator<16; LoopIterator++)
sakthipriya 0:1a04c0beef21 58 {
sakthipriya 0:1a04c0beef21 59 //read the sensor values and stores them in 'SensorData' structure's variable 'Sensor'
sakthipriya 0:1a04c0beef21 60 Sensor.Voltage[LoopIterator]=(VoltageInput.read()*3.3*5.545454);//resistors in voltage divider=>15Mohm,3.3Mohm
sakthipriya 0:1a04c0beef21 61
sakthipriya 0:1a04c0beef21 62 if(LoopIterator%2==0)
sakthipriya 0:1a04c0beef21 63 SensorQuantised.Voltage[LoopIterator/2]=quantiz(vstart,vstep,Sensor.Voltage[LoopIterator]);
sakthipriya 0:1a04c0beef21 64
sakthipriya 0:1a04c0beef21 65 else
sakthipriya 0:1a04c0beef21 66 SensorQuantised.Voltage[(LoopIterator)/2]=SensorQuantised.Voltage[(LoopIterator)/2]<<4+quantiz(vstart,vstep,Sensor.Voltage[LoopIterator]);
sakthipriya 0:1a04c0beef21 67
sakthipriya 0:1a04c0beef21 68 //iterate the select lines from 0 to 15
sakthipriya 0:1a04c0beef21 69 for(SelectLineIterator=3;SelectLineIterator>=0;SelectLineIterator--)
sakthipriya 0:1a04c0beef21 70 {
sakthipriya 0:1a04c0beef21 71 if(SelectLinesA[SelectLineIterator]==0)
sakthipriya 0:1a04c0beef21 72 {
sakthipriya 0:1a04c0beef21 73 SelectLinesA[SelectLineIterator]=1;
sakthipriya 0:1a04c0beef21 74 break;
sakthipriya 0:1a04c0beef21 75 }
sakthipriya 0:1a04c0beef21 76 else SelectLinesA[SelectLineIterator]=0;
sakthipriya 0:1a04c0beef21 77 }
sakthipriya 0:1a04c0beef21 78
sakthipriya 0:1a04c0beef21 79 wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed.
sakthipriya 0:1a04c0beef21 80 }
sakthipriya 0:1a04c0beef21 81
sakthipriya 0:1a04c0beef21 82
sakthipriya 0:1a04c0beef21 83 //measurement from current sensor=> 8 sensors in place
sakthipriya 0:1a04c0beef21 84 for(LoopIterator=0; LoopIterator<8; LoopIterator++)
sakthipriya 0:1a04c0beef21 85 {
sakthipriya 0:1a04c0beef21 86 //read the sensor values and stores them in 'SensorData' structure variable 'Sensor'
sakthipriya 0:1a04c0beef21 87 Sensor.Current[LoopIterator]=(CurrentInput.read()*3.3/(50*rsens));
sakthipriya 0:1a04c0beef21 88 if(LoopIterator%2==0)
sakthipriya 0:1a04c0beef21 89 SensorQuantised.Current[LoopIterator/2]=quantiz(cstart,cstep,Sensor.Current[LoopIterator]);
sakthipriya 0:1a04c0beef21 90 else
sakthipriya 0:1a04c0beef21 91 SensorQuantised.Current[(LoopIterator)/2]=SensorQuantised.Current[(LoopIterator)/2]<<4+quantiz(cstart,cstep,Sensor.Current[LoopIterator]);
sakthipriya 0:1a04c0beef21 92
sakthipriya 0:1a04c0beef21 93 //iterate the select lines from 0 to 7
sakthipriya 0:1a04c0beef21 94 for(SelectLineIterator=2;SelectLineIterator>=0;SelectLineIterator--)
sakthipriya 0:1a04c0beef21 95 {
sakthipriya 0:1a04c0beef21 96 if(SelectLinesB[SelectLineIterator]==0)
sakthipriya 0:1a04c0beef21 97 {
sakthipriya 0:1a04c0beef21 98 SelectLinesB[SelectLineIterator]=1;
sakthipriya 0:1a04c0beef21 99 break;
sakthipriya 0:1a04c0beef21 100 }
sakthipriya 0:1a04c0beef21 101 else SelectLinesB[SelectLineIterator]=0;
sakthipriya 0:1a04c0beef21 102
sakthipriya 0:1a04c0beef21 103 }
sakthipriya 0:1a04c0beef21 104
sakthipriya 0:1a04c0beef21 105 wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed.
sakthipriya 0:1a04c0beef21 106 }
sakthipriya 0:1a04c0beef21 107
sakthipriya 0:1a04c0beef21 108
sakthipriya 0:1a04c0beef21 109 //measurement of temperature
sakthipriya 0:1a04c0beef21 110 //temperature measurement=> 4 thermistors, 1 temperature sensor
sakthipriya 0:1a04c0beef21 111 //mux line 1=>temp sensor, mux lines 2 to 5 =>thermistors
sakthipriya 0:1a04c0beef21 112
sakthipriya 0:1a04c0beef21 113 for(LoopIterator=0; LoopIterator<5; LoopIterator++)
sakthipriya 0:1a04c0beef21 114 {
sakthipriya 0:1a04c0beef21 115 //read the sensor values and stores them in 'SensorData' structure variable 'Sensor'
sakthipriya 0:1a04c0beef21 116 Sensor.Temperature[LoopIterator]=(-90.7*3.3*TemperatureInput.read()+190.1543);
sakthipriya 0:1a04c0beef21 117 voltage_thermistor=TemperatureInput.read()*3.3;//voltage across thermistor
sakthipriya 0:1a04c0beef21 118 resistance_thermistor=24000*voltage_thermistor/(3.3-voltage_thermistor);//resistance of thermistor
sakthipriya 0:1a04c0beef21 119 if (LoopIterator==0)
sakthipriya 0:1a04c0beef21 120 {
sakthipriya 0:1a04c0beef21 121 printf(" \n\rTemp =%f",-90.7*3.3*TemperatureInput.read()+190.1543);
sakthipriya 0:1a04c0beef21 122 }
sakthipriya 0:1a04c0beef21 123
sakthipriya 0:1a04c0beef21 124 if(LoopIterator%2==0)
sakthipriya 0:1a04c0beef21 125 {
sakthipriya 0:1a04c0beef21 126 if(LoopIterator<1) //->corresponding to temperature sensor
sakthipriya 0:1a04c0beef21 127 SensorQuantised.Temperature[(LoopIterator)/2]=quantiz(tstart,tstep,Sensor.Temperature[LoopIterator]);
sakthipriya 0:1a04c0beef21 128
sakthipriya 0:1a04c0beef21 129 else //->corresponding to thermistor
sakthipriya 0:1a04c0beef21 130 {
sakthipriya 0:1a04c0beef21 131 if(voltage_thermistor<1.378) //Temperature>12 degC
sakthipriya 0:1a04c0beef21 132 Sensor.PanelTemperature[(LoopIterator-1)]=(3694/log(24.032242*resistance_thermistor));
sakthipriya 0:1a04c0beef21 133
sakthipriya 0:1a04c0beef21 134 else
sakthipriya 0:1a04c0beef21 135 Sensor.PanelTemperature[(LoopIterator-1)]=(3365.4792/log(7.60404*resistance_thermistor));
sakthipriya 0:1a04c0beef21 136
sakthipriya 0:1a04c0beef21 137
sakthipriya 0:1a04c0beef21 138 SensorQuantised.PanelTemperature[(LoopIterator-1)/2]=quantiz(tstart_thermistor,tstep_thermistor,Sensor.PanelTemperature[(LoopIterator-1)]);
sakthipriya 0:1a04c0beef21 139
sakthipriya 0:1a04c0beef21 140 }
sakthipriya 0:1a04c0beef21 141 }
sakthipriya 0:1a04c0beef21 142 else
sakthipriya 0:1a04c0beef21 143 {
sakthipriya 0:1a04c0beef21 144 if(LoopIterator<1)
sakthipriya 0:1a04c0beef21 145 SensorQuantised.Temperature[(LoopIterator)/2]=SensorQuantised.Temperature[(LoopIterator)/2]<<4+quantiz(tstart,tstep,Sensor.Temperature[LoopIterator]);
sakthipriya 0:1a04c0beef21 146
sakthipriya 0:1a04c0beef21 147 else
sakthipriya 0:1a04c0beef21 148 {
sakthipriya 0:1a04c0beef21 149 if(voltage_thermistor<1.378) //Temperature>12 degC
sakthipriya 0:1a04c0beef21 150 Sensor.PanelTemperature[LoopIterator-1]=(3694/log(24.032242*resistance_thermistor));
sakthipriya 0:1a04c0beef21 151 else
sakthipriya 0:1a04c0beef21 152 Sensor.PanelTemperature[LoopIterator-1]=(3365.4792/log(7.60404*resistance_thermistor));
sakthipriya 0:1a04c0beef21 153
sakthipriya 0:1a04c0beef21 154 SensorQuantised.PanelTemperature[(LoopIterator-1)/2]=SensorQuantised.PanelTemperature[(LoopIterator-1)/2]<<4+quantiz(tstart_thermistor,tstep_thermistor,Sensor.PanelTemperature[LoopIterator-1]);
sakthipriya 0:1a04c0beef21 155 }
sakthipriya 0:1a04c0beef21 156 }
sakthipriya 0:1a04c0beef21 157 // The following lines are used to iterate the select lines from 0 to 4
sakthipriya 0:1a04c0beef21 158 for(SelectLineIterator=3;SelectLineIterator>=0;SelectLineIterator--)
sakthipriya 0:1a04c0beef21 159 {
sakthipriya 0:1a04c0beef21 160 if(SelectLinesC[SelectLineIterator]==0)
sakthipriya 0:1a04c0beef21 161 {
sakthipriya 0:1a04c0beef21 162 SelectLinesC[SelectLineIterator]=1;
sakthipriya 0:1a04c0beef21 163 break;
sakthipriya 0:1a04c0beef21 164 }
sakthipriya 0:1a04c0beef21 165 else SelectLinesC[SelectLineIterator]=0;
sakthipriya 0:1a04c0beef21 166 }
sakthipriya 0:1a04c0beef21 167
sakthipriya 0:1a04c0beef21 168 wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed.
sakthipriya 0:1a04c0beef21 169 }
sakthipriya 0:1a04c0beef21 170
sakthipriya 0:1a04c0beef21 171
sakthipriya 0:1a04c0beef21 172 //update magnetometer data->
sakthipriya 0:1a04c0beef21 173 //populate values in structure variable 'Sensor' from data to be given by Green
sakthipriya 0:1a04c0beef21 174 SensorQuantised.AngularSpeed[0]=quantiz(AngularSpeed_start,AngularSpeed_step,Sensor.AngularSpeed[1]);
sakthipriya 0:1a04c0beef21 175 SensorQuantised.AngularSpeed[0]=SensorQuantised.AngularSpeed[0]<<4+quantiz(AngularSpeed_start,AngularSpeed_step,Sensor.AngularSpeed[0]);
sakthipriya 0:1a04c0beef21 176 SensorQuantised.AngularSpeed[1]=quantiz(AngularSpeed_start,AngularSpeed_step,Sensor.AngularSpeed[2]);
sakthipriya 0:1a04c0beef21 177
sakthipriya 0:1a04c0beef21 178 //update gyro data->
sakthipriya 0:1a04c0beef21 179 //populate values in structure variable 'Sensor' from data to be given by Green
sakthipriya 0:1a04c0beef21 180 SensorQuantised.Bnewvalue[0]=quantiz(Bnewvalue_start,Bnewvalue_step,Sensor.Bnewvalue[1]);
sakthipriya 0:1a04c0beef21 181 SensorQuantised.Bnewvalue[0]=SensorQuantised.Bnewvalue[0]<<4+quantiz(Bnewvalue_start,Bnewvalue_step,Sensor.Bnewvalue[0]);
sakthipriya 0:1a04c0beef21 182 SensorQuantised.Bnewvalue[1]=quantiz(Bnewvalue_start,Bnewvalue_step,Sensor.Bnewvalue[2]);
sakthipriya 0:1a04c0beef21 183
sakthipriya 0:1a04c0beef21 184 //update beacon structure
sakthipriya 0:1a04c0beef21 185 init_beacon(&Shortbeacon,SensorQuantised);//Shortbeacon is passed
sakthipriya 0:1a04c0beef21 186 printf("\n here temperature :%d",SensorQuantised.Temperature);
sakthipriya 0:1a04c0beef21 187 }
sakthipriya 0:1a04c0beef21 188
sakthipriya 0:1a04c0beef21 189
sakthipriya 0:1a04c0beef21 190