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