![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
things are working
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of CDMS_DEC_2016_jan by
CDMS_HK.cpp@4:560716ec8414, 2016-01-23 (annotated)
- Committer:
- cholletisaik777
- Date:
- Sat Jan 23 11:33:47 2016 +0000
- Revision:
- 4:560716ec8414
- Parent:
- 3:23cdab96a05d
things are working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pradeepvk2208 | 1:ad3b8a8032e2 | 1 | #include "Flags.h" |
pradeepvk2208 | 1:ad3b8a8032e2 | 2 | #include "CDMS_HK.h" |
pradeepvk2208 | 1:ad3b8a8032e2 | 3 | #include "mbed.h" |
pradeepvk2208 | 1:ad3b8a8032e2 | 4 | #include "cdms_rtc.h" |
pradeepvk2208 | 1:ad3b8a8032e2 | 5 | #include "i2c.h" |
pradeepvk2208 | 1:ad3b8a8032e2 | 6 | #include "Flash.h" |
pradeepvk2208 | 1:ad3b8a8032e2 | 7 | #include "cdms_sd.h" |
pradeepvk2208 | 1:ad3b8a8032e2 | 8 | #include "pinconfig.h" |
pradeepvk2208 | 1:ad3b8a8032e2 | 9 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 10 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 11 | Serial hk_cdms(USBTX, USBRX); |
pradeepvk2208 | 1:ad3b8a8032e2 | 12 | //DigitalOut Select_Lines_C[]={PIN85,PIN84,PIN39,PIN38}; //to mux on IF board,from LSB(Select_Lines_C[3]) to MSB(Select_Lines_C[0]) |
pradeepvk2208 | 1:ad3b8a8032e2 | 13 | DigitalOut Select_Lines_C[]={D7,D6,D5,D4}; |
pradeepvk2208 | 1:ad3b8a8032e2 | 14 | AnalogIn Temperature_voltage_Input(PIN53); //output from IF mux |
pradeepvk2208 | 1:ad3b8a8032e2 | 15 | //AnalogIn Sensor_Input(PIN53); //output from temperature sensor on CDMS |
pradeepvk2208 | 1:ad3b8a8032e2 | 16 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 17 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 18 | void FCTN_CDMS_HK_MAIN() |
pradeepvk2208 | 1:ad3b8a8032e2 | 19 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 20 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 21 | CDMS_HK_STATUS=(CDMS_HK_STATUS)|(HK_MAIN_STATUS); |
pradeepvk2208 | 1:ad3b8a8032e2 | 22 | |
cholletisaik777 | 3:23cdab96a05d | 23 | hk_cdms.printf(" \r\nCDMS HK entered \r\n"); |
pradeepvk2208 | 1:ad3b8a8032e2 | 24 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 25 | int HK_I2C; |
cholletisaik777 | 3:23cdab96a05d | 26 | char BAE_HK[74]; |
cholletisaik777 | 3:23cdab96a05d | 27 | FCTN_I2C_READ(BAE_HK,74); |
cholletisaik777 | 4:560716ec8414 | 28 | printf("BAE_HK=%c %c %c",BAE_HK[38], BAE_HK[39],BAE_HK[40]); |
pradeepvk2208 | 1:ad3b8a8032e2 | 29 | /*if(HK_I2C==0) |
pradeepvk2208 | 1:ad3b8a8032e2 | 30 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 31 | if(Power_level!=0) |
pradeepvk2208 | 1:ad3b8a8032e2 | 32 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 33 | printf("Update Power_level to 0 in Flash"); |
pradeepvk2208 | 1:ad3b8a8032e2 | 34 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 35 | Att_level=0; |
pradeepvk2208 | 1:ad3b8a8032e2 | 36 | CDMS_HK_STATUS=(CDMS_HK_STATUS)|(HK_BAE_ERR_I2C); |
pradeepvk2208 | 1:ad3b8a8032e2 | 37 | CDMS_HK_STATUS=(CDMS_HK_STATUS)&(~(HK_MAIN_STATUS)); |
pradeepvk2208 | 1:ad3b8a8032e2 | 38 | }**/ |
cholletisaik777 | 3:23cdab96a05d | 39 | uint64_t time=FCTN_CDMS_RD_RTC(); |
cholletisaik777 | 3:23cdab96a05d | 40 | char tree[82]; |
cholletisaik777 | 3:23cdab96a05d | 41 | hk_cdms.printf("i am done\r\n"); |
cholletisaik777 | 3:23cdab96a05d | 42 | uint8_t data[512]; |
cholletisaik777 | 3:23cdab96a05d | 43 | for(int i=0;i<512;i++) |
cholletisaik777 | 3:23cdab96a05d | 44 | { |
pradeepvk2208 | 2:2565deafb176 | 45 | data[i]=0x00; |
pradeepvk2208 | 2:2565deafb176 | 46 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 47 | tree[0]=(char)(time>>(56))&(0xFF); |
pradeepvk2208 | 1:ad3b8a8032e2 | 48 | tree[1]=(char)(time>>(48))&(0xFF); |
pradeepvk2208 | 1:ad3b8a8032e2 | 49 | tree[2]=(char)(time>>(40))&(0xFF); |
pradeepvk2208 | 1:ad3b8a8032e2 | 50 | tree[3]=(char)(time>>(32))&(0xFF); |
pradeepvk2208 | 1:ad3b8a8032e2 | 51 | tree[4]=(char)(time>>(24))&(0xFF); |
pradeepvk2208 | 1:ad3b8a8032e2 | 52 | tree[5]=(char)(time>>(16))&(0xFF); |
pradeepvk2208 | 1:ad3b8a8032e2 | 53 | tree[6]=(char)(time>>(8))&(0xFF); |
pradeepvk2208 | 1:ad3b8a8032e2 | 54 | tree[7]=(char)(time)&(0xFF); |
cholletisaik777 | 3:23cdab96a05d | 55 | for(int i=0;i<74;i++) |
pradeepvk2208 | 1:ad3b8a8032e2 | 56 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 57 | tree[i+8]=BAE_HK[i]; |
pradeepvk2208 | 1:ad3b8a8032e2 | 58 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 59 | printf("Hope u r alive \r\n"); |
cholletisaik777 | 3:23cdab96a05d | 60 | for(int i=0;i<82;i++) |
pradeepvk2208 | 2:2565deafb176 | 61 | { |
pradeepvk2208 | 2:2565deafb176 | 62 | data[i]=(uint8_t)tree[i]; |
pradeepvk2208 | 2:2565deafb176 | 63 | } |
pradeepvk2208 | 2:2565deafb176 | 64 | for(int i=0;i<512;i++) |
pradeepvk2208 | 2:2565deafb176 | 65 | { |
pradeepvk2208 | 2:2565deafb176 | 66 | printf("%d",data[i]); |
pradeepvk2208 | 2:2565deafb176 | 67 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 68 | uint8_t fsc=FCTN_SD_MNGR(0x3); |
pradeepvk2208 | 1:ad3b8a8032e2 | 69 | printf("FSC where SD is written is %d\r\n",fsc); |
pradeepvk2208 | 1:ad3b8a8032e2 | 70 | int a=SD_WRITE(data,0x00000012,0x3); |
pradeepvk2208 | 1:ad3b8a8032e2 | 71 | printf("Result of writing is %d \r\n",a); |
pradeepvk2208 | 1:ad3b8a8032e2 | 72 | //BCN long frame ??? |
cholletisaik777 | 3:23cdab96a05d | 73 | //CDMS_HK_STATUS=(CDMS_HK_STATUS)&(~(HK_MAIN_STATUS)); |
pradeepvk2208 | 1:ad3b8a8032e2 | 74 | hk_cdms.printf("let me know the truth\r\n"); |
pradeepvk2208 | 1:ad3b8a8032e2 | 75 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 76 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 77 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 78 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 79 | int quantiz(float l_start,float l_step,float l_x) // accepts min and measured values and step->quantises on a scale 0-15..(4 bit quantisation) |
pradeepvk2208 | 1:ad3b8a8032e2 | 80 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 81 | int l_y = (l_x - l_start)/l_step; |
pradeepvk2208 | 1:ad3b8a8032e2 | 82 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 83 | if(l_y <= 0) |
pradeepvk2208 | 1:ad3b8a8032e2 | 84 | l_y = 0; |
pradeepvk2208 | 1:ad3b8a8032e2 | 85 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 86 | if(l_y >= 15) |
pradeepvk2208 | 1:ad3b8a8032e2 | 87 | l_y = 15; |
pradeepvk2208 | 1:ad3b8a8032e2 | 88 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 89 | return l_y; |
pradeepvk2208 | 1:ad3b8a8032e2 | 90 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 91 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 92 | Sensor_Data Sensor; |
pradeepvk2208 | 1:ad3b8a8032e2 | 93 | Sensor_Data_Quantised Sensor_Quantised; |
pradeepvk2208 | 1:ad3b8a8032e2 | 94 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 95 | char* FCTN_CDMS_HK() |
pradeepvk2208 | 1:ad3b8a8032e2 | 96 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 97 | char CDMS_HK_DATA[8]; |
pradeepvk2208 | 1:ad3b8a8032e2 | 98 | float l_resistance_thermistor; //declaration of variables |
pradeepvk2208 | 1:ad3b8a8032e2 | 99 | float l_voltage_thermistor; |
pradeepvk2208 | 1:ad3b8a8032e2 | 100 | float l_Payload_voltage; |
pradeepvk2208 | 1:ad3b8a8032e2 | 101 | int l_Loop_Iterator = 0; |
pradeepvk2208 | 1:ad3b8a8032e2 | 102 | int l_Select_Line_Iterator = 3; |
pradeepvk2208 | 1:ad3b8a8032e2 | 103 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 104 | for(l_Loop_Iterator = 0; l_Loop_Iterator < 16; l_Loop_Iterator++) |
pradeepvk2208 | 1:ad3b8a8032e2 | 105 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 106 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 107 | l_voltage_thermistor = Temperature_voltage_Input.read()*3.3; //voltage across thermistor |
pradeepvk2208 | 1:ad3b8a8032e2 | 108 | l_resistance_thermistor = 24000*l_voltage_thermistor/(3.3 - l_voltage_thermistor); //resistance of thermistor |
pradeepvk2208 | 1:ad3b8a8032e2 | 109 | l_Payload_voltage = Temperature_voltage_Input.read()*3.3; |
pradeepvk2208 | 1:ad3b8a8032e2 | 110 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 111 | Sensor.l_Temperature_thermistor[(l_Loop_Iterator)] = 0.00000004*l_resistance_thermistor*l_resistance_thermistor - 0.0039*l_resistance_thermistor + 347.97; |
pradeepvk2208 | 1:ad3b8a8032e2 | 112 | Sensor.l_Temperature_sensor[l_Loop_Iterator] = (-90.7*3.3*Temperature_voltage_Input.read() + 190.1543); |
pradeepvk2208 | 1:ad3b8a8032e2 | 113 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 114 | if(l_Loop_Iterator % 2 == 0) |
pradeepvk2208 | 1:ad3b8a8032e2 | 115 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 116 | if(l_Loop_Iterator < 4) |
pradeepvk2208 | 1:ad3b8a8032e2 | 117 | Sensor_Quantised.l_Temperature_thermistor[(l_Loop_Iterator)/2] = quantiz(tstart_thermistor,tstep_thermistor,Sensor.l_Temperature_thermistor[(l_Loop_Iterator)]); |
pradeepvk2208 | 1:ad3b8a8032e2 | 118 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 119 | else |
pradeepvk2208 | 1:ad3b8a8032e2 | 120 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 121 | if(4 < l_Loop_Iterator < 14) |
pradeepvk2208 | 1:ad3b8a8032e2 | 122 | Sensor_Quantised.l_Payload_voltage[(l_Loop_Iterator)/2] = Sensor_Quantised.l_Payload_voltage[(l_Loop_Iterator)/2] <<4 + quantiz(tstart,tstep,Sensor.l_Payload_voltage[l_Loop_Iterator]); |
pradeepvk2208 | 1:ad3b8a8032e2 | 123 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 124 | else |
pradeepvk2208 | 1:ad3b8a8032e2 | 125 | Sensor_Quantised.l_Temperature_sensor[(l_Loop_Iterator)/2] = quantiz(tstart,tstep,Sensor.l_Temperature_sensor[l_Loop_Iterator]); |
pradeepvk2208 | 1:ad3b8a8032e2 | 126 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 127 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 128 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 129 | else |
pradeepvk2208 | 1:ad3b8a8032e2 | 130 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 131 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 132 | if(l_Loop_Iterator < 4) |
pradeepvk2208 | 1:ad3b8a8032e2 | 133 | Sensor_Quantised.l_Temperature_thermistor[(l_Loop_Iterator)/2] = Sensor_Quantised.l_Temperature_thermistor[(l_Loop_Iterator)/2] <<4 + quantiz(tstart_thermistor,tstep_thermistor,Sensor.l_Temperature_thermistor[l_Loop_Iterator]); |
pradeepvk2208 | 1:ad3b8a8032e2 | 134 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 135 | else |
pradeepvk2208 | 1:ad3b8a8032e2 | 136 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 137 | if(4 < l_Loop_Iterator < 14) |
pradeepvk2208 | 1:ad3b8a8032e2 | 138 | Sensor_Quantised.l_Payload_voltage[(l_Loop_Iterator)/2] = quantiz(tstart,tstep,Sensor.l_Payload_voltage[l_Loop_Iterator]); |
pradeepvk2208 | 1:ad3b8a8032e2 | 139 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 140 | else |
pradeepvk2208 | 1:ad3b8a8032e2 | 141 | Sensor_Quantised.l_Temperature_sensor[(l_Loop_Iterator)/2] = Sensor_Quantised.l_Temperature_sensor[(l_Loop_Iterator)/2] <<4 + quantiz(tstart,tstep,Sensor.l_Temperature_sensor[l_Loop_Iterator]); |
pradeepvk2208 | 1:ad3b8a8032e2 | 142 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 143 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 144 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 145 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 146 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 147 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 148 | // The following lines are used to iterate the select lines from 0 to 15 |
pradeepvk2208 | 1:ad3b8a8032e2 | 149 | for(l_Select_Line_Iterator = 3;l_Select_Line_Iterator >= 0;l_Select_Line_Iterator--) |
pradeepvk2208 | 1:ad3b8a8032e2 | 150 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 151 | if(Select_Lines_C[l_Select_Line_Iterator] == 0) |
pradeepvk2208 | 1:ad3b8a8032e2 | 152 | { |
pradeepvk2208 | 1:ad3b8a8032e2 | 153 | Select_Lines_C[l_Select_Line_Iterator] = 1; |
pradeepvk2208 | 1:ad3b8a8032e2 | 154 | break; |
pradeepvk2208 | 1:ad3b8a8032e2 | 155 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 156 | else Select_Lines_C[l_Select_Line_Iterator] = 0; |
pradeepvk2208 | 1:ad3b8a8032e2 | 157 | printf("%d\n",l_Select_Line_Iterator); |
pradeepvk2208 | 1:ad3b8a8032e2 | 158 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 159 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 160 | wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. |
pradeepvk2208 | 1:ad3b8a8032e2 | 161 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 162 | printf("vol %f temp %f",Temperature_voltage_Input.read()*3.3,-90.7*3.3*Temperature_voltage_Input.read() + 190.1543 ); |
pradeepvk2208 | 1:ad3b8a8032e2 | 163 | printf("CDMS_HK Data is Temperature_sensor=%s, l_Temperature_thermistor=%s, Payload_voltage=%s ",Sensor_Quantised.l_Temperature_sensor,Sensor_Quantised.l_Temperature_thermistor,Sensor_Quantised.l_Payload_voltage); |
pradeepvk2208 | 1:ad3b8a8032e2 | 164 | strcpy (CDMS_HK_DATA,Sensor_Quantised.l_Temperature_sensor); |
pradeepvk2208 | 1:ad3b8a8032e2 | 165 | strcat (CDMS_HK_DATA,Sensor_Quantised.l_Temperature_thermistor); |
pradeepvk2208 | 1:ad3b8a8032e2 | 166 | strcat (CDMS_HK_DATA,Sensor_Quantised.l_Payload_voltage); |
pradeepvk2208 | 1:ad3b8a8032e2 | 167 | return(CDMS_HK_DATA); |
pradeepvk2208 | 1:ad3b8a8032e2 | 168 | } |
pradeepvk2208 | 1:ad3b8a8032e2 | 169 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 170 | |
pradeepvk2208 | 1:ad3b8a8032e2 | 171 |