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 all_combined_week6 by
HK.cpp
00001 #include "HK.h" 00002 00003 DigitalOut SelectLine3 (p24); // MSB of Select Lines 00004 DigitalOut SelectLine2 (p23); 00005 DigitalOut SelectLine1 (p22); 00006 DigitalOut SelectLine0 (p21); // LSB of Select Lines 00007 00008 AnalogIn CurrentInput(p15); // Input from Current Multiplexer 00009 AnalogIn VoltageInput(p16); // Input from Voltage Multiplexer 00010 AnalogIn TemperatureInput(p17); // input from Temperature Multiplexer 00011 00012 SensorData Sensor; 00013 int quantiz(float start,float step,float x) 00014 { 00015 int y=(x-start)/step; 00016 if(y<=0)y=0; 00017 if(y>=15)y=15; 00018 return y; 00019 } 00020 00021 void init_beacon(ShortBeacy x){ 00022 x.Voltage[0]=1; 00023 x.AngularSpeed[0]=2; 00024 x.AngularSpeed[1]=3; 00025 x.SubsystemStatus[0]=145; 00026 x.Temp[0]=1; 00027 x.Temp[1]=2; 00028 x.Temp[2]=3; 00029 x.ErrorFlag[0]=3; 00030 } 00031 00032 ShortBeacy Shortbeacon; 00033 void FUNC_HK_MAIN() 00034 { 00035 printf("\nEntered function HK MAIN\n"); 00036 00037 init_beacon(Shortbeacon); 00038 00039 int LoopIterator; 00040 00041 SelectLine0=0; 00042 SelectLine1=0; 00043 SelectLine2=0; 00044 SelectLine3=0; 00045 00046 for(LoopIterator=0; LoopIterator<16; LoopIterator++) { 00047 00048 if(LoopIterator%2==0) { 00049 Sensor.Current[LoopIterator/2]=quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens))); 00050 Sensor.Voltage[LoopIterator/2]=quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37)); 00051 Sensor.Temperature[LoopIterator/2]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); 00052 } else { 00053 Sensor.Current[(LoopIterator-1)/2]=(Sensor.Current[(LoopIterator-1)/2]<<4)+quantiz(cstart,cstep,((CurrentInput.read()*3.18)/(50*rsens))); 00054 Sensor.Voltage[(LoopIterator-1)/2]=(Sensor.Voltage[(LoopIterator-1)/2]<<4)+quantiz(vstart,vstep,(VoltageInput.read()*3.18*5.37)); 00055 Sensor.Temperature[(LoopIterator-1)/2]=(Sensor.Temperature[(LoopIterator-1)/2]<<4)+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543)); 00056 } 00057 // The following lines are used to iterate the select lines from 0 to 15 00058 SelectLine0=!(SelectLine0); 00059 00060 if(LoopIterator%2==1) 00061 SelectLine1=!(SelectLine1); 00062 00063 if(LoopIterator%4==3) 00064 SelectLine2=!(SelectLine2); 00065 00066 if(LoopIterator%8==7) 00067 SelectLine3=!(SelectLine3); 00068 00069 wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. 00070 00071 } 00072 for(int i=0;i<8;i++) 00073 { 00074 printf("\nVoltage %d is %u\n",i,Sensor.Voltage[i]); 00075 printf("\nCurrent %d is %u\n",i,Sensor.Current[i]); 00076 printf("\nTemperature %d is %u\n",i,Sensor.Temperature[i]); 00077 } 00078 00079 printf("\nExited function HK MAIN\n"); 00080 }
Generated on Thu Jul 14 2022 22:49:02 by
1.7.2
