after pin

Dependencies:   mbed-rtos mbed

Fork of BAE_vr2_gingerbread by sakthi priya amirtharaj

Committer:
raizel_varun
Date:
Wed Dec 17 09:52:27 2014 +0000
Revision:
3:3d9e5f48b0c1
Parent:
2:7aede71f4c22
AFTER PINS;

Who changed what in which revision?

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