acdt/board/Src/dac7311.c

116 lines
2.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "dac7311.h"
int cnum = 0;
void dac7311_init(void)
{
AO_DWQ_SYNC(1);
AO_BLF_SYNC1(1);
AO_BLF_SYNC2(1);
AO_DWQ_SCLK(0);
AO_BLF_SCLK(0);
}
void ao_write(uint16_t Data,uint8_t chip_select)
{
uint16_t temp;
uint8_t ui;
temp=Data << 2;
temp &= 0x3FFF;//设置模式为Normal
if(chip_select == AO_DWQ)
{
AO_DWQ_SYNC(1);
AO_DWQ_SCLK(1);
delay_tick(10);
AO_DWQ_SYNC(0);
delay_tick(10);
}
else if(chip_select == AO_BLF1)
{
AO_BLF_SYNC1(1);
AO_BLF_SCLK(1);
delay_tick(10);
AO_BLF_SYNC1(0);
delay_tick(10);
}
else if(chip_select == AO_BLF2)
{
AO_BLF_SYNC2(1);
AO_BLF_SCLK(1);
delay_tick(10);
AO_BLF_SYNC2(0);
delay_tick(10);
}
for(ui=0; ui<16; ui++)
{
AO_DWQ_SCLK(1);
AO_BLF_SCLK(1);
if(0x8000 == (temp & 0x8000))
{
AO_DWQ_DIN(1);
AO_BLF_DIN(1);
}
else
{
AO_DWQ_DIN(0);
AO_BLF_DIN(0);
}
delay_tick(10);
AO_DWQ_SCLK(0);
AO_BLF_SCLK(0);
delay_tick(10);
temp <<=1;
}
AO_DWQ_SYNC(1);
AO_BLF_SYNC1(1);
AO_BLF_SYNC2(1);
}
/*******************************************************************************
函数名称 ao_dwq_set
功 能 AO电流输出
参 数 current--电流值
返 回 值
*******************************************************************************/
void ao_dwq_set(float current)
{
uint16_t data = 0;
current = current * 100;//电流转为电压
data = (current * 4096) / 3300;
cnum = data;
ao_write(data,AO_DWQ);
}
/*******************************************************************************
函数名称 ao_blf1_set
功 能 AO电流输出
参 数 current--电流值
返 回 值
*******************************************************************************/
void ao_blf1_set(float current)
{
uint16_t data = 0;
current = current * 100;//电流转为电压
data = (current * 4096) / 3300;
ao_write(data,AO_BLF1);
}
/*******************************************************************************
函数名称 ao_blf2_set
功 能 AO电流输出
参 数 current--电流值
返 回 值
*******************************************************************************/
void ao_blf2_set(float current)
{
uint16_t data = 0;
current = current * 100;//电流转为电压
data = (current * 4096) / 3300;
ao_write(data,AO_BLF2);
}