Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BAE_FRDM_INTEGRATION by
HK.cpp
00001 #include "HK.h" 00002 MAX17048 master(A4,A5,100000);//CHECK SDA,SCL LINES,FREQUENCY 00003 int quantiz(float start,float step,float x); 00004 //GPIO pins used=> D2-D13, A0-A1 00005 DigitalOut SelectLinesA[]={D2,D3,D4,D5};//to mux1 00006 DigitalOut SelectLinesB[]={D6,D7,D8,D9};//to mux2 00007 DigitalOut SelectLinesC[]={D10,D11,D12,D13};//to mux3 00008 00009 //--------------------------------------------MSB is SelectLines[0],LSB is SelectLines[3]-------------------------------- 00010 00011 AnalogIn CurrentInput(A0); // Input from Current 00012 AnalogIn VoltageInput(A1); // Input from Voltage Multiplexer 00013 AnalogIn TemperatureInput(A2); /*Input from Temperature Multiplexer,thermistor Multiplexer- same multiplexer for both(0-3 for thermistor,4-15 for temperature sensor)*/ 00014 00015 SensorData Sensor;//struct variable 00016 00017 int quantiz(float start,float step,float x) // accepts min and measured values and step->quantises on a scale 0-15 00018 { 00019 int y=(x-start)/step; 00020 if(y<=0)y=0; 00021 if(y>=15)y=15; 00022 return y; 00023 } 00024 00025 void init_beacon(ShortBeacy x) //dummy values----------to be changed------------------- 00026 { 00027 x.Voltage[0]=1; 00028 x.AngularSpeed[0]=2; 00029 x.AngularSpeed[1]=3; 00030 x.SubsystemStatus[0]=145; 00031 x.Temp[0]=1; 00032 x.Temp[1]=2; 00033 x.Temp[2]=3; 00034 x.ErrorFlag[0]=3; 00035 } 00036 ShortBeacy Shortbeacon;//struct variable 00037 void FUNC_HK_MAIN() 00038 { 00039 00040 00041 init_beacon(Shortbeacon); 00042 //initialise all selectlines to zeroes->1st line of mux selected 00043 SelectLinesA[0]=SelectLinesA[1]=SelectLinesA[2]=SelectLinesA[3]=0; 00044 SelectLinesB[0]=SelectLinesB[1]=SelectLinesB[2]=SelectLinesB[3]=0; 00045 SelectLinesC[0]=SelectLinesC[1]=SelectLinesC[2]=SelectLinesC[3]=0; 00046 int LoopIterator; 00047 float resistance_thermistor,voltage_thermistor;//for thermistor 00048 00049 for(LoopIterator=0; LoopIterator<16; LoopIterator++) 00050 { 00051 00052 if(LoopIterator%2==0) 00053 { 00054 00055 Sensor.Voltage[LoopIterator/2]=quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37)); 00056 Sensor.Current[LoopIterator/2]=quantiz(cstart,cstep,(CurrentInput.read()*3.18/(50*rsens))); 00057 if(LoopIterator>3) 00058 Sensor.Temperature[(LoopIterator-4)/2]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); 00059 else 00060 { voltage_thermistor=TemperatureInput.read()*3.18; 00061 resistance_thermistor=24000*voltage_thermistor/(3.3-voltage_thermistor); 00062 if(voltage_thermistor<1.378) //Temperature>12 degC 00063 Sensor.PanelTemperature[(LoopIterator)/2]=quantiz(tstart_thermistor,tstep_thermistor,(3694/log(24.032242*resistance_thermistor))); 00064 00065 else { 00066 Sensor.PanelTemperature[(LoopIterator)/2]=quantiz(tstart_thermistor,tstep_thermistor,(3365.4792/log(7.60404*resistance_thermistor))); 00067 } 00068 } 00069 } 00070 00071 else 00072 { 00073 00074 Sensor.Voltage[(LoopIterator-1)/2]=Sensor.Voltage[(LoopIterator-1)/2]<<4+quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37)); 00075 Sensor.Current[(LoopIterator-1)/2]=Sensor.Current[(LoopIterator-1)/2]<<4+quantiz(cstart,cstep,(CurrentInput.read()*3.18/(50*rsens))); 00076 if(LoopIterator>3) 00077 Sensor.Temperature[(LoopIterator-5)/2]=Sensor.Temperature[(LoopIterator-5)/2]<<4+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); 00078 else 00079 { voltage_thermistor=TemperatureInput.read()*3.18; 00080 resistance_thermistor=24000*voltage_thermistor/(3.3-voltage_thermistor); 00081 if(voltage_thermistor<1.378) //Temperature>12 degC 00082 Sensor.PanelTemperature[(LoopIterator-1)/2]=Sensor.PanelTemperature[(LoopIterator-1)/2]<<4+quantiz(tstart_thermistor,tstep_thermistor,(3694/log(24.032242*resistance_thermistor))); 00083 else 00084 Sensor.PanelTemperature[(LoopIterator-1)/2]=Sensor.PanelTemperature[(LoopIterator-1)/2]<<4+quantiz(tstart_thermistor,tstep_thermistor,(3364.4792/log(7.60404*resistance_thermistor))); 00085 00086 } 00087 } 00088 float batteryparameters[4];//to populate battery parameters of struct variable Sensor 00089 FUNC_BATTERYGAUGE_MAIN(batteryparameters);//passing array to function 00090 00091 Sensor.Vcell=batteryparameters[0]; 00092 Sensor.soc=batteryparameters[1]; 00093 Sensor.crate=batteryparameters[2]; 00094 Sensor.alerts=batteryparameters[3]; 00095 00096 // The following lines are used to iterate the select lines from 0 to 15 00097 int SelectLineIterator; 00098 //following is an algorithm similar to counting binary numbers of 4 bit 00099 for(SelectLineIterator=3;SelectLineIterator>=0;SelectLineIterator--) 00100 { 00101 if(SelectLinesA[SelectLineIterator]==0) 00102 { 00103 SelectLinesA[SelectLineIterator]=1; 00104 break; 00105 } 00106 else SelectLinesA[SelectLineIterator]=0; 00107 00108 SelectLinesB[SelectLineIterator]=SelectLinesA[SelectLineIterator]; 00109 SelectLinesC[SelectLineIterator]=SelectLinesA[SelectLineIterator]; 00110 } 00111 00112 00113 wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. 00114 00115 } 00116 00117 } 00118 void FUNC_BATTERYGAUGE_MAIN(float array[]) 00119 { 00120 float vcell=master.vcell(); 00121 float soc=master.soc(); 00122 float crate=master.crate(); 00123 00124 printf("\nVcell=%f",vcell); 00125 printf("\nSOC=%f",soc); 00126 printf("\nC_rate=%f",crate); 00127 00128 array[0]=vcell; 00129 array[1]=soc; 00130 array[2]=crate; 00131 if (master.alerting()== true) //alert is on 00132 { 00133 array[3]=master.alertFlags(); 00134 master.clearAlert();//clear alert 00135 master.clearAlertFlags();//clear all alert flags 00136 } 00137 00138 00139 }
Generated on Tue Jul 12 2022 19:16:04 by
