diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-02 15:24:01 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-02 15:24:01 +0300 |
| commit | 5efe56d0d4b2f4acd8cc275670955d68b7e196cf (patch) | |
| tree | 6c5a6c7ffcc8e7f586e3ad9889fd15ad182548d5 /Software | |
| parent | 7ec5bf094de95ff3827b40dec61ddb9b37f93e33 (diff) | |
| parent | f4b51ad784cffc3493f32a9b4f1e9afc6fd2a43c (diff) | |
| download | Tango-5efe56d0d4b2f4acd8cc275670955d68b7e196cf.tar.gz Tango-5efe56d0d4b2f4acd8cc275670955d68b7e196cf.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software')
3 files changed, 219 insertions, 1 deletions
diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/DAC/Blower.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/DAC/Blower.c new file mode 100644 index 000000000..085e09b6d --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/DAC/Blower.c @@ -0,0 +1,156 @@ +/* + * Blower.c + * + * Created on: Aug 1, 2018 + * Author: avi + * + * AD5691R + * support standard (100 kHz) and fast (400 kHz) data transfer modes + * I2C 12 bits DAC chip U207 + */ +#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 "Blower.h" + +DAC_Union DAC; + +uint32_t Write_Control_Register() +{ + uint32_t status = OK; + + DAC.Bytes.Command = AD5691R_CMD_WRITE_CONTROL_REG; + DAC.Bytes.Data_High = AD5691R_Control_Normal_Mode | AD5691R_Control_Reference_Enabled | AD5691R_Control_Gain_0V_VREF; + DAC.Bytes.Data_Low = AD5691R_DONT_CARE_DATA_BYTE; + + status = I2C_Write(2, I2C_DAC_ADDRESS, DAC.Write_DAC_I2C_Buf, 3); + + return status; +} + +uint32_t Write_DAC_and_Input_Register(uint32_t Bits) +{ + uint32_t status = OK; + + DAC.Bytes.Command = AD5691R_CMD_WRITE_INPUT_N_UPDATE_REG; + + DAC.Bytes.Data_High = Bits; + + DAC.Bytes.Data_Low = AD5691R_DONT_CARE_DATA_BYTE; + + status = I2C_Write(DAC_I2C_BASE, I2C_DAC_ADDRESS, DAC.Write_DAC_I2C_Buf, 3); + + return status; +} + +uint32_t Write_Input_Register() +{ + uint32_t status = OK; + + DAC.Bytes.Command = AD5691R_CMD_WRITE_INPUT_REG; + DAC.Bytes.Data_High = 0xFF; + DAC.Bytes.Data_Low = AD5691R_DONT_CARE_DATA_BYTE; + + status = I2C_Write(DAC_I2C_BASE, I2C_DAC_ADDRESS, DAC.Write_DAC_I2C_Buf, 3); + + return status; +} + +uint32_t Update_DAC_register() +{ + uint32_t status = OK; + + DAC.Bytes.Command = AD5691R_CMD_UPDATE_DAC_REG; + DAC.Bytes.Data_High = AD5691R_DONT_CARE_DATA_BYTE; + DAC.Bytes.Data_Low = AD5691R_DONT_CARE_DATA_BYTE; + + status = I2C_Write(DAC_I2C_BASE, I2C_DAC_ADDRESS, DAC.Write_DAC_I2C_Buf, 3); + + return status; +} + +uint32_t Write_NOP() +{ + uint32_t status = OK; + + DAC.Bytes.Command = AD5691R_CMD_NOOP; + DAC.Bytes.Data_High = AD5691R_DONT_CARE_DATA_BYTE; + DAC.Bytes.Data_Low = AD5691R_DONT_CARE_DATA_BYTE; + + status = I2C_Write(DAC_I2C_BASE, I2C_DAC_ADDRESS, DAC.Write_DAC_I2C_Buf, 3); + + return status; +} + + +uint8_t DAC_mV2Bits(VoutmV) // 0-8V +{ + //based on the function from acording to the shceme : VOUT=VIN+(VIN-0.2)*(9.76/4.12) - Vin 0-2.5V Vout 0-8V + //=> Vin = (Vout + 0.4737)/3.3689 + //Vin is the VAmpin (VDACout) + uint8_t Bits; + uint32_t temp; + + if(VoutmV > 8000) + VoutmV = 8000;// 8V is the output for 0xFF (2.5V after Amp. we get 8V) + + temp = VoutmV + 473;// Vamp - Vampin + + temp = temp * 0xFF;//Vampin(=VDACout) -> bits) + temp/=3368;// Vamp - Vampin + temp/=2.5;//Vampin(=VDACout) -> bits) + + Bits = temp & 0xFF;//8bit + + return Bits; +} + +//------------------------------------------------------------------------------------------------------------ + + +uint32_t Turn_the_Blower_On() +{ + uint32_t status = OK; + + status = Write_Control_Register(); + + status |= Write_DAC_and_Input_Register(DAC_mV2Bits(Default_Voltage)); + + return status; +} + +uint32_t Control_Voltage_To_Blower(uint32_t mV) +{ + uint32_t status = OK; + + status |= Write_DAC_and_Input_Register(DAC_mV2Bits(mV)); + + return status; +} + +uint32_t Turn_the_Blower_Off() +{ + uint32_t status = OK; + + status |= Write_DAC_and_Input_Register(0); + + return status; +} + + + + + + + diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/DAC/Blower.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/DAC/Blower.h new file mode 100644 index 000000000..febaa6a4b --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/DAC/Blower.h @@ -0,0 +1,56 @@ +/* + * Blower.h + * + * Created on: Aug 1, 2018 + * Author: avi + */ + +#ifndef DRIVERS_I2C_COMMUNICATION_DAC_BLOWER_H_ +#define DRIVERS_I2C_COMMUNICATION_DAC_BLOWER_H_ + +uint32_t Turn_the_Blower_On(); +uint32_t Control_Voltage_To_Blower(uint32_t mV); +uint32_t Turn_the_Blower_Off(); + + +#define I2C_DAC_ADDRESS 0x98 + +//Command Byte +#define AD5691R_CMD_NOOP 0x00 +#define AD5691R_CMD_WRITE_INPUT_REG 0x10 +#define AD5691R_CMD_UPDATE_DAC_REG 0x20 +#define AD5691R_CMD_WRITE_INPUT_N_UPDATE_REG 0x30 +#define AD5691R_CMD_WRITE_CONTROL_REG 0x40 + +#define AD5691R_DONT_CARE_DATA_BYTE 0x00 + +#define Default_Voltage 2800 //3.058V the output voltage is 2.8V + +#define DAC_I2C_BASE 2 + +typedef union +{ + struct + { + uint8_t Command; + uint8_t Data_High; + uint8_t Data_Low; + }Bytes; + uint8_t Write_DAC_I2C_Buf[3]; +}DAC_Union; + + + +//AD5691R Control Data High Byte +#define AD5691R_Control_Reset 0x80 +#define AD5691R_Control_Normal_Mode 0x00 +#define AD5691R_Control_Power_Down_1K 0x20 +#define AD5691R_Control_Power_Down_100K 0x40 +#define AD5691R_Control_Power_Down_Three_State 0x60 +#define AD5691R_Control_Reference_Enabled 0x00 +#define AD5691R_Control_Reference_Disabled 0x10 +#define AD5691R_Control_Gain_0V_VREF 0x00 +#define AD5691R_Control_Gain_0V_2VREF 0x08 +#endif /* DRIVERS_I2C_COMMUNICATION_DAC_BLOWER_H_ */ + + diff --git a/Software/Embedded_SW/Embedded/Main.c b/Software/Embedded_SW/Embedded/Main.c index 1c4d3b409..e6a39721a 100644 --- a/Software/Embedded_SW/Embedded/Main.c +++ b/Software/Embedded_SW/Embedded/Main.c @@ -56,7 +56,7 @@ extern Semaphore_Handle sdCardSem; #include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h" - +#include "drivers/I2C_Communication/DAC/Blower.h" //#define WATCHDOG //***************************************************************************** @@ -187,8 +187,14 @@ int main(void) //Test_Write_Flash_Buf(); + + + //Write_DAC_and_Input_Register(); //----------------------------------------------------------- #ifndef EVALUATION_BOARD + + Turn_the_Blower_On(); + DeActivateAllSSR(); ActivateChiller();//SSR12 |
