diff options
3 files changed, 109 insertions, 0 deletions
diff --git a/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.h b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.h index 6deab3aca..65064c837 100644 --- a/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.h +++ b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC.h @@ -66,6 +66,8 @@ uint8_t Calculate_Gas_Power_Consumption(); uint32_t Read_Dryer_Heaters_Current(HEATERS_CURRENT Heater_ID); void CheckAcInputVoltage(); +double ReadVAC(); + extern PowerControlFlag Power_Control_Flag; #endif /* DRIVERS_ADC_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC_VAC.c b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC_VAC.c new file mode 100644 index 000000000..a6ee83ecc --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/ADC_Sampling/ADC_VAC.c @@ -0,0 +1,99 @@ +/* + * ADC_VAC.c + * + * Created on: Jan 1, 2020 + * Author: avi + * + * According to the email "AC Voltage measurements" on December 20 2019 + */ + +#include "include.h" +#include "ADC.h" + +#define AC_Index 0 +#define DC_Index 1 + +#define AcTable_MaxLine 9 +#define AcTable_MaxColumn 2 + +double AcLookUpTable[AcTable_MaxLine][AcTable_MaxColumn] = +{ + 180.2 , 5.963, + 190.1 , 6.298, + 200.16 , 6.639, + 210.2 , 6.980, + 220.03 , 7.320, + 230.26 , 7.639, + 240.23 , 7.981, + 250.2 , 8.317, + 259.9 , 8.647 +}; + +double VDC2VAC(double VDC)//Volts +{ + double VAC = 0, VAC_Delta = 0, VDC_Delta = 0, Temp = 0; + unsigned char i = 0; + + if ((VDC < AcLookUpTable[0][DC_Index]) || (VDC > AcLookUpTable[AcTable_MaxLine - 1][DC_Index])) + { + VAC = 29.5522 * VDC + 3.981;//linear line according to the lookup table + } + else + { + for (i = 0; i < AcTable_MaxLine; i++) + { + if (VDC == AcLookUpTable[i][DC_Index]) + { + VAC = AcLookUpTable[i][AC_Index]; + break; + } + else if ((VDC > AcLookUpTable[i][DC_Index]) && (VDC < AcLookUpTable[i + 1][DC_Index])) + { + VAC_Delta = AcLookUpTable[i + 1][AC_Index] - AcLookUpTable[i][AC_Index]; + VDC_Delta = AcLookUpTable[i + 1][DC_Index] - AcLookUpTable[i][DC_Index]; + Temp = VDC - AcLookUpTable[i][DC_Index]; + Temp = Temp * VAC_Delta / VDC_Delta; + VAC = AcLookUpTable[i][AC_Index] + Temp; + break; + } + + } + + } + return VAC;//Volts +} + +double ReadVAC() +{ + uint32_t VsampleInBits; + + double temp, VADC = 0.0 ,VSensor, VAC = 0.0; + + VsampleInBits = ADC_GetReading(ADC_AIR_PRESSURE_2); + + //---- VBits -> VADC ---- + + //ADC 12 bit -> 4096 -> 3V + + //temp = (double)(VsampleInBits)*3.0; + //VADC = temp / 4096.0; + + + temp = 4096 - VsampleInBits; + temp *= 3;//Vref internal ADC + temp *= 1000; //move to mv + temp /= 4096; + VADC = 3000 - temp; + + //---- VADC -> VSensor --- + + //VADC = 1.96 - 10k( VSensor - 1.96) / 46.4k (from the electrical scheme) + // VSensor = 0 V -> VADC = 2.3824 V + // VSensor = 10 V -> VADC = 0.2272 V + + VSensor = (1.96- (VADC/1000)) * 4.64 + 1.96; + + VAC = VDC2VAC((double)(VSensor)); + + return VAC; //Volts +} diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c index 6fd2e0eb1..8d0a23f23 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c @@ -28,6 +28,7 @@ #include <Drivers/I2C_Communication/I2C.h> #include <Drivers/I2C_Communication/Head_Card/I2C_Head_Mux.h> #include <Drivers/I2C_Communication/Head_Card/IO_Ports/Head_IO.h> +#include "drivers/adc_sampling/adc.h" //#include "graphics_adapter.h" extern uint8_t Input_Voltage; @@ -80,6 +81,13 @@ void Stub_ProgressRequest(MessageContainer* requestContainer) } else + if((request->amount == 0xAC) && (request->delay == 0xAC)) //VAC + { + response.progress = ReadVAC(); + response.has_progress = true; + + } + else if(request->amount == 0x0EAD) //Head Card I/O { uint8_t Write_Buf[2] = {0,0}; |
