更新dac161p997
This commit is contained in:
parent
5401ebeb61
commit
82feca4263
|
@ -1,8 +1,14 @@
|
|||
#include "dac161p997.h"
|
||||
#include "delay.h"
|
||||
|
||||
#include "tims.h"
|
||||
static dac161p997_t _handle;
|
||||
|
||||
static void delay_us(uint32_t us)
|
||||
{
|
||||
RESET_TIM_COUNT(TIME_1US);
|
||||
while (LL_TIM_GetCounter(TIME_1US) < us)
|
||||
; // 等待计数器达到指定值
|
||||
}
|
||||
|
||||
static void dac161p997_output_0()
|
||||
{
|
||||
_handle.io->set(*_handle.io);
|
||||
|
@ -124,17 +130,8 @@ void dac161p997_swif_write_reg(uint16_t data, uint8_t tag)
|
|||
*/
|
||||
void dac161p997_output_current(float32 current)
|
||||
{
|
||||
uint8_t adc = (uint16_t)(current * DAC161P997_CURRENT_SLOPE) >> 8;
|
||||
static uint8_t last_adc;
|
||||
if (adc == last_adc)
|
||||
{
|
||||
last_adc = adc;
|
||||
return;
|
||||
}
|
||||
|
||||
dac161p997_swif_write_reg(DAC161P997_LCK_REG_UNLOCK, CONFIG_WRITE);
|
||||
dac161p997_swif_write_reg(DAC161P997_ERR_LOW_REG + adc, CONFIG_WRITE);
|
||||
dac161p997_swif_write_reg(DAC161P997_LCK_REG_LOCK, CONFIG_WRITE);
|
||||
uint16_t adc = (uint16_t)(current * DAC161P997_CURRENT_SLOPE);
|
||||
dac161p997_swif_write_reg(adc, DACCODE_WRITE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,13 +146,9 @@ void dac161p997_output_current(float32 current)
|
|||
*/
|
||||
void dac161p997_init()
|
||||
{
|
||||
ENABLE_TIM_COUNT(TIME_1US);
|
||||
_handle.io = gpio_create(DAC161P997_IO_PORT, DAC161P997_IO_PIN);
|
||||
dac161p997_swif_write_reg(DAC161P997_LCK_REG_UNLOCK, CONFIG_WRITE);
|
||||
dac161p997_swif_write_reg(DAC161P997_CONFIG2_REG +
|
||||
DAC161P997_CONFIG2_REG_LOOP +
|
||||
DAC161P997_CONFIG2_REG_CHANNEL +
|
||||
DAC161P997_CONFIG2_REG_PARITY +
|
||||
DAC161P997_CONFIG2_REG_FRAME,
|
||||
CONFIG_WRITE);
|
||||
dac161p997_swif_write_reg(DAC161P997_LCK_REG_LOCK, CONFIG_WRITE);
|
||||
dac161p997_swif_write_reg(DAC161P997_LCK_REG + DAC161P997_LCK_REG_UNLOCK, CONFIG_WRITE);
|
||||
dac161p997_swif_write_reg(DAC161P997_CONFIG2_REG, CONFIG_WRITE);
|
||||
dac161p997_swif_write_reg(DAC161P997_LCK_REG + DAC161P997_LCK_REG_LOCK, CONFIG_WRITE);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define __DAC161P997_H__
|
||||
#include "main.h"
|
||||
#include "gpios.h"
|
||||
|
||||
#define TIME_1US TIM1
|
||||
#define DAC161P997_IO_PORT (DAC161P997_GPIO_Port)
|
||||
#define DAC161P997_IO_PIN (DAC161P997_Pin)
|
||||
|
||||
|
@ -60,15 +60,15 @@
|
|||
#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 enum
|
||||
{
|
||||
DAC161P997_IDLE_SYM,
|
||||
|
||||
} dac161p997_e;
|
||||
typedef struct
|
||||
{
|
||||
gpio_t *io;
|
||||
uint8_t count;
|
||||
} dac161p997_t;
|
||||
|
||||
void dac161p997_output_0(void);
|
||||
|
@ -76,6 +76,7 @@ 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
|
||||
|
|
Loading…
Reference in New Issue