4-10-2015 BAE_RTOS_TEST ACS_DATA_ACQ and I2C sending 25 bytes to CDMS

Dependencies:   mbed-rtos mbed

Fork of BAE_RTOS_test_1 by GOPA KUMAR K C

Committer:
gkumar
Date:
Sun Oct 04 07:06:22 2015 +0000
Revision:
1:b8c71afbe6e5
4-10-2015 BAE_RTOS_TEST1

Who changed what in which revision?

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