diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-12 18:23:05 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-12 18:23:05 +0300 |
| commit | 819b2bc2094baac1ddf4e6e84cd308e96eb17d8e (patch) | |
| tree | 8b77801f6ccc5aea874583c334f3bf71ff6083d0 /Software/Embedded_SW/Embedded | |
| parent | da8c561c85c9ee296cb18796e5db95ca759d1063 (diff) | |
| parent | a4a2a94fe295f57c462eb3cd2c24c9ba512de5a6 (diff) | |
| download | Tango-819b2bc2094baac1ddf4e6e84cd308e96eb17d8e.tar.gz Tango-819b2bc2094baac1ddf4e6e84cd308e96eb17d8e.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Embedded_SW/Embedded')
4 files changed, 199 insertions, 4 deletions
diff --git a/Software/Embedded_SW/Embedded/Drivers/Heater/Heater.c b/Software/Embedded_SW/Embedded/Drivers/Heater/Heater.c index 5f5f04063..d67a65b17 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Heater/Heater.c +++ b/Software/Embedded_SW/Embedded/Drivers/Heater/Heater.c @@ -37,7 +37,7 @@ uint32_t HeaterActive = 0; static GPIOIntPortMap portMap[MAX_HEATERS_NUM] = { - {DRYER_SSR2_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__DryerAirTemperature + {DRYER_SSR3_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__DryerAirTemperature **** Not connected **** {DRYER_SSR1_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__DryerHeaterMain {DRYER_SSR2_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__DryerHeaterSecondary {DYEINGH_SSR8_CTRL, false}, // HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ1 - Head Heater #1 - rightmost diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c new file mode 100644 index 000000000..0dbf24ac9 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.c @@ -0,0 +1,167 @@ +/* + * ADC_MUX.c + * + * Created on: Aug 12, 2018 + * Author: avi + * + * 8-Channel, I2C, 12-Bit SAR ADC with Temperature Sensor AD7291 + * Mid tank pressure sensor. Bosch 02612300215 + */ +#include <stdint.h> +#include <stdbool.h> +#include "include.h" +#include "inc/hw_memmap.h" +#include "inc/hw_types.h" +#include "inc/tm4c1294ncpdt.h" +#include "driverlib/gpio.h" +#include "driverlib/pin_map.h" +#include "driverlib/rom.h" +#include "driverlib/rom_map.h" +#include "driverlib/sysctl.h" +#include "driverlib/i2c.h" +#include "Drivers/I2C_Communication/I2C_Switch/I2C_Swith.h" +#include "drivers/I2C_Communication/I2C.h" + +#include "ADC_MUX.h" + +double MidTank_Pressure[8]; + +uint32_t I2C_ADC_Config(uint32_t I2C_Slave_Add,uint32_t channel ) +{ + uint32_t Status = OK; + + uint8_t Config_Buf[3]; + + Config_Buf[0] = 0x00; + Config_Buf[1] = channel; + Config_Buf[2] = 0x80; + + Status = I2C_Write(MUX_I2C_BASE, I2C_Slave_Add, Config_Buf, 3); + + return Status; +} + +uint32_t I2C_ADC_Set_For_Read_Ch(uint32_t I2C_Slave_Add ) +{ + uint32_t Status = OK; + + uint8_t SetRead = 0x02; + + Status = I2C_Write(MUX_I2C_BASE, SetRead, SetRead, 1); + + return Status; +} + + +uint32_t I2C_ADC_Read_Ch(uint32_t I2C_Slave_Add ) +{ + uint32_t VsampleInBits = 0,temp; + + uint8_t No_BytesToRead = 2; + + uint8_t I2C_Read_buf[2] = {0,0}; + + I2C_Read(MUX_I2C_BASE, I2C_Slave_Add, *I2C_Read_buf, No_BytesToRead ); + + temp = (I2C_Read_buf[0] << 8) | I2C_Read_buf[1]; + + VsampleInBits=temp & 0x0fff; + + return VsampleInBits; +} + +uint32_t Calculate_Pressure(uint32_t VsampleInBits ) +{ + double Pressure = 0, temp, PKpa,PBar,VADC = 0 ,VSensor; + + //---- VBits -> VADC ---- + + //ADC 12 bit -> 4096 -> 2.5V + + temp = VsampleInBits*2.5; + VADC = temp / 0xFFF; + + //---- 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 + + temp = 4.94 * VADC ; + + VSensor = 11.0544 - temp; + + // ---- Vsensor -> P[KPa] ---- + + //Vsensor = 5* (0.16*P + 0.5) + + temp = VSensor - 2.5; + PKpa = temp / 0.8; + + // ---- P[Kpa] -> BAR ---- + + PBar = PKpa / 100; + + Pressure = PBar; + return Pressure; +} + +uint32_t Read_MidTank_Pressure_Sensor(MidTank_t MidTank_ID) //0-7 +{ + uint32_t Status = OK; + uint32_t I2C_Slave_Add; + uint32_t Channel; + uint32_t VsampleInBits; + + assert (MidTank_ID<NUM_OF_MIDTANKS); + + switch(MidTank_ID) + { + case MIDTANK_RB: + I2C_Slave_Add = 0x44; + Channel = 0x20; + break; + case MIDTANK_RMB: + I2C_Slave_Add = 0x44; + Channel = 0x08; + break; + case MIDTANK_RMF: + I2C_Slave_Add = 0x46; + Channel = 0x80; + break; + case MIDTANK_RF: + I2C_Slave_Add = 0x46; + Channel = 0x20; + break; + case MIDTANK_LB: + I2C_Slave_Add = 0x44; + Channel = 0x10; + break; + case MIDTANK_LMB: + I2C_Slave_Add = 0x44; + Channel = 0x04; + break; + case MIDTANK_LMF: + I2C_Slave_Add = 0x46; + Channel = 0x40; + break; + case MIDTANK_LF: + I2C_Slave_Add = 0x46; + Channel = 0x10; + break; + default: + break; + } + + Status = I2C_ADC_Config(I2C_Slave_Add, Channel); + Status = I2C_ADC_Set_For_Read_Ch(I2C_Slave_Add); + VsampleInBits = I2C_ADC_Read_Ch(I2C_Slave_Add); + + MidTank_Pressure[MidTank_ID] = Calculate_Pressure(VsampleInBits); + + return Status; +} + + + diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.h new file mode 100644 index 000000000..fb50a2a73 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/ADC_MUX/ADC_MUX.h @@ -0,0 +1,28 @@ +/* + * ADC_MUX.h + * + * Created on: Aug 12, 2018 + * Author: avi + */ + +#ifndef DRIVERS_I2C_COMMUNICATION_ADC_MUX_ADC_MUX_H_ +#define DRIVERS_I2C_COMMUNICATION_ADC_MUX_ADC_MUX_H_ + +#define MUX_I2C_BASE 2 + +typedef enum +{ + MIDTANK_RB, + MIDTANK_RMB, + MIDTANK_RMF, + MIDTANK_RF, + MIDTANK_LB, + MIDTANK_LMB, + MIDTANK_LMF, + MIDTANK_LF, + NUM_OF_MIDTANKS, +} MidTank_t; + +uint32_t Read_MidTank_Pressure_Sensor(MidTank_t MidTank_ID); + +#endif /* DRIVERS_I2C_COMMUNICATION_ADC_MUX_ADC_MUX_H_ */ diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c index 6312c701e..1efce00e3 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_init.c @@ -35,9 +35,9 @@ void Calculateinit (void) Bits_0Pascal = Vlow * 4096 / 3; // Vlow * 4096bit / 3Vref = 709.973328 bits Bits_1MPascal = VHigh * 4096 / 3; // VHigh * 4096bit / 3Vref = 3549.86646 bits - a = (Bits_1MPascal - Bits_0Pascal) / (1 - 0) ;// Mpascal/Bits = 2839.89307 + a = (1 - 0) / (Bits_1MPascal - Bits_0Pascal);// Mpascal/Bits = 0.000352125 - b = Bits_0Pascal - (a * 0 ); //709.973328 + b = 0 - (a * Bits_0Pascal ); // y = ax + b (x= Bits_0Pascal, y = 0) } float CalculateDispenserPressure (int DispenserId) @@ -58,7 +58,7 @@ float CalculateDispenserPressure (int DispenserId) if(data<Bits_0Pascal) data = Bits_0Pascal;//40mA 0Bar - temp = (data - b) / a; + temp = a * data + b; DispenserPressure[DispenserId] = temp; // [Mpascal] ( 1 Mpascal = 10 Bar ) |
