82 lines
2.5 KiB
C
82 lines
2.5 KiB
C
#ifndef __DAC161P997_H__
|
|
#define __DAC161P997_H__
|
|
#include "main.h"
|
|
#include "gpios.h"
|
|
|
|
#define DAC161P997_IO_PORT (DAC161P997_GPIO_Port)
|
|
#define DAC161P997_IO_PIN (DAC161P997_Pin)
|
|
|
|
#define DAC161P997_CURRENT_SLOPE 2730.625f // adc = (current / 24) * 0xffff
|
|
|
|
// Symbol Periods
|
|
#define DUTY_CYCLE_100 (1000U) // (CPU_CLK / BAUD_RATE)
|
|
#define DUTY_CYCLE_75 (DUTY_CYCLE_100 * 0.75f)
|
|
#define DUTY_CYCLE_50 (DUTY_CYCLE_100 * 0.50f)
|
|
#define DUTY_CYCLE_25 (DUTY_CYCLE_100 * 0.25f)
|
|
|
|
/************************************************************
|
|
* TI DAC161P997 REGISTER SET ADDRESSES
|
|
************************************************************/
|
|
#define DAC161P997_LCK_REG (0x0000)
|
|
#define DAC161P997_CONFIG1_REG (0x0100)
|
|
#define DAC161P997_CONFIG2_REG (0x0200)
|
|
#define DAC161P997_CONFIG3_REG (0x0300)
|
|
#define DAC161P997_ERR_LOW_REG (0x0400)
|
|
#define DAC161P997_ERR_HIGH_REG (0x0500)
|
|
|
|
// TI DAC161P997 Register Bits
|
|
#define DAC161P997_LCK_REG_LOCK (0x00AA) // any value other than 0x95
|
|
#define DAC161P997_LCK_REG_UNLOCK (0x0095)
|
|
#define DAC161P997_CONFIG1_REG_RST (0x0001)
|
|
#define DAC161P997_CONFIG1_REG_NOP (0 * 0x08u)
|
|
#define DAC161P997_CONFIG1_REG_SET_ERR (1 * 0x08u)
|
|
#define DAC161P997_CONFIG1_REG_CLEAR_ERR (2 * 0x08u)
|
|
#define DAC161P997_CONFIG1_REG_NOP3 (3 * 0x08u)
|
|
#define DAC161P997_CONFIG2_REG_LOOP (0x0001)
|
|
#define DAC161P997_CONFIG2_REG_CHANNEL (0x0002)
|
|
#define DAC161P997_CONFIG2_REG_PARITY (0x0004)
|
|
#define DAC161P997_CONFIG2_REG_FRAME (0x0008)
|
|
#define DAC161P997_CONFIG2_REG_ACK_EN (0x0010)
|
|
#define DAC161P997_CONFIG3_REG_RX_ERR_CNT_16 (0x000F)
|
|
#define DAC161P997_CONFIG3_REG_RX_ERR_CNT_8 (0x0007)
|
|
#define DAC161P997_CONFIG3_REG_RX_ERR_CNT_1 (0x0000)
|
|
|
|
// Tags
|
|
#define DACCODE_WRITE (0x00)
|
|
#define CONFIG_WRITE (0x01)
|
|
|
|
// Valid Symbols
|
|
#define ZERO_SYM (0x00)
|
|
#define ONE_SYM (0x01)
|
|
#define IDLE_SYM (0x02)
|
|
#define STATIC_LOW_SYM (0x03)
|
|
|
|
// DAC Codes for different currents
|
|
#define DACCODE_0mA (0x0000)
|
|
#define DACCODE_4mA (0x2AAA)
|
|
#define DACCODE_8mA (0x5555)
|
|
#define DACCODE_12mA (0x7FFF)
|
|
#define DACCODE_16mA (0xAAAA)
|
|
#define DACCODE_20mA (0xD555)
|
|
#define DACCODE_24mA (0xFFFF)
|
|
|
|
// cycles
|
|
// #define QUARTER_CYCLES (625)
|
|
// #define HALF_CYCLES (1250)
|
|
// #define THREE_CYCLES (1875)
|
|
// #define FULL_CYCLES (2500)
|
|
|
|
typedef struct
|
|
{
|
|
gpio_t *io;
|
|
} dac161p997_t;
|
|
|
|
void dac161p997_output_0(void);
|
|
void dac161p997_output_1(void);
|
|
void dac161p997_output_d(void);
|
|
void dac161p997_output_symbol(uint8_t sym);
|
|
void dac161p997_swif_write_reg(uint16_t data, uint8_t tag);
|
|
extern void dac161p997_output_current(float32 current);
|
|
extern void dac161p997_init(void);
|
|
#endif
|