当前位置:网站首页>Peripheral driver library development notes 42:dac8552 DAC driver
Peripheral driver library development notes 42:dac8552 DAC driver
2022-06-09 07:03:00 【foxclever】
Analog signal output is a common application requirement , There should be many solutions , But what we use most is digital to analog conversion . For different digital to analog converters, we need to write appropriate drivers , In this article, we will consider how to realize DAC8552 High precision analog-to-digital converter driver .
1、 Function Overview
The DAC8552 It's a 16 position , Two channels , Voltage output digital to analog converter (DAC) Provide low power operation and flexible serial host interface . Precise output amplifiers on each chip allow rail to rail output oscillations , To achieve in 2.7V To 5.5V Scope of supply for . The device supports standard three wire serial interface , Can operate with input data clock frequency up to 30MHz Of VDD = 5V.
1.1、 Functional structure
DAC8552 The low power consumption of this device under normal circumstances makes it very suitable for portable 、 Battery powered devices and other low power applications . use SOIC-8 The packaging form of , Pins are defined as follows :
DAC8552 An external reference voltage is required to set each DAC The output range of the channel .DAC8552 It also includes a power on reset circuit , In order to ensure that DAC The output power can be output to zero , And keep it there , Until a valid write value is obtained .DAC8552 To have a SPI serial interface , This interface provides flexible functions .
It can be seen from the above structure diagram ,DAC8552 Only one output can be operated at a time , Because all operations are implemented through the same shift register .
1.2、 shift register
DAC8552 There is one 24 Bit input shift register , front 8 Bits are used as control bits , Back 16 Bits are used as data bits . The details are shown in the following figure :
In front of 8 Bit control bit ,DB23 and DB22 Is reserved bit must be “0”,DB21(LDB) Bit and DB20(LDA) Used to control the following 16 Bit data is applicable to which output channel is loaded or Power_Down command .DB19 No definition ,DAC8552 Do not care about the specific value of this bit .DB18 Select bits for the buffer , The target channel for control data is DAC A still DAC B. Follow up DB17(PD1) and DB16(PD0) For choosing Power_Down The pattern of . The specific commands are described in the following table :
as for Power_Down There are several options for the mode of , As shown in the following table :
2、 Drive design and implementation
We already know DAC8552 The basic structure and register command of , Next we will design according to these cognition DAC8552 Driver program .
2.1、 Object definitions
In the design DAC8552 Before the driver of , Let's think about it first DAC8552 Object definition problem . As an object, we generally include attributes and operations . Let's first analyze DAC8552 What attributes should an object contain . Attributes are used to identify certain properties of an object ,DAC8552 adopt SPI The bus sends data and commands , We didn't find any features that needed special marking , So we don't need to be DAC8552 Object design properties .
Let's take another look at ,DAC8552 What operations the object needs to implement . First DAC8552 Use SPI Bus for communication , and SPI The bus uses chip select signals to distinguish different nodes , So we need to operate DAC8552 On the screen signal of , The operation of the chip selection model obviously depends on the specific operating platform , So we will control the chip selection signal as DAC8552 Object . in addition ,DAC8552 As an analog output object , We need to send them commands and data , Sending data and commands to it also depends on the specific operating platform , Therefore, it should be implemented as an operation of the object . From this we can define DAC8552 The object types of are as follows :
/* Definition DAC8552 object type */
typedef struct DAC8552Object {
void (*WriteDataToDAC)(uint8_t *tData,uint16_t tSize); // towards DAC send data
void (*ChipSelcet)(DAC8552CSType cs); // Piece of optional signal
}DAC8552xObjectType;
We defined DAC8552 Object type of , But when we use it to declare an object , It can't be used directly , We need to initialize the object , This requires us to design an object initialization function . The object initialization function handles the configuration of object related properties and operations , The specific implementation is as follows :
/* initialization DAC8552 object */
void DAC8552Initialization(DAC8552xObjectType *dac, //DAC8552 Object variables
DAC8552WriteType write, // Write data function pointer
DAC8552ChipSelectType cs // Chip selection operation function pointer
)
{
if((dac==NULL)||(write==NULL))
{
return;
}
if(cs!=NULL)
{
dac->ChipSelcet=cs;
}
else
{
dac->ChipSelcet=DefaultChipSelect;
}
}
2.2、 The object operation
We have defined DAC8552 The object type of is DAC8552 Object to design the initialization function , Now let's take a look at DAC8552 The operation to be implemented . about DAC8552 The object is , Our operation on it is nothing more than writing its shift register to realize the issuance of commands and data . From its data table, we can see that the timing of operating the shift register is as follows :
According to what we're facing DAC8552 Understanding of relevant data and the above sequence diagram , We can encapsulate the operation function of its shift register as follows :
/* operation DAC8552 Output channel */
void SetDAC8552ChannelValue(DAC8552xObjectType *dac,DAC8552LDType ld,DAC8552BSType bs,DAC8552PDType pd,uint16_t data)
{
uint32_t inputShiftData=0;
uint8_t sData[3];
inputShiftData=data;
inputShiftData=inputShiftData|(ld<<20);
inputShiftData=inputShiftData|(bs<<18);
inputShiftData=inputShiftData|(pd<<16);
sData[0]=(uint8_t)(inputShiftData>>16);
sData[1]=(uint8_t)(inputShiftData>>8);
sData[2]=(uint8_t)inputShiftData;
dac->ChipSelcet(DAC8552CS_Enable);
dac->WriteDataToDAC(sData,3);
dac->ChipSelcet(DAC8552CS_Disable);
}
3、 Use of drivers
We designed DAC8552 Object driven , But we need to verify whether this driver is correct . So next we design a simple example to verify the driver .
3.1、 Declare and initialize objects
We use the designed driver to operate DAC8552 when , First, we need to declare a with the object type we defined DAC8552 object .
DAC8552xObjectType dac8552;
After declaring this object variable , We also need to use the initialization function to initialize it before using . This initialization function has 3 Parameters :
DAC8552xObjectType *dac, //DAC8552 Object variables
DAC8552WriteType write, // Write data function pointer
DAC8552ChipSelectType cs // Chip selection operation function pointer
The first parameter is the object variable we want to initialize ; The second parameter is to DAC8552 Function pointers to write commands and data ; The third parameter is the chip selection signal operation function pointer . These two function pointers require us to implement . Their prototypes are as follows :
/* towards DAC Send data function pointer type */
typedef void (*DAC8552WriteType)(uint8_t *tData,uint16_t tSize);
/* The type of operation function pointer in slice selection */
typedef void (*DAC8552ChipSelectType)(DAC8552CSType cs);
We define according to the function prototype , Implement them on a specific implementation platform , As we are STM32 The implementation on the platform is as follows :
/* Define the chip selection signal function */
void DAC8552CS(DAC8552CSType en)
{
if(DAC8552CS_Enable==en)
{
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_4, GPIO_PIN_RESET);
}
else
{
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_4, GPIO_PIN_SET);
}
}
/* Define the function of sending data */
void DAC8552TransmitData(uint8_t *wData,uint16_t wSize)
{
HAL_SPI_Transmit (&dac8552hspi, wData, wSize, 1000);
}
We combine object variables with the above implementation 2 A function pointer to a function is passed as a parameter to DAC8552 Object initialization function to initialize object variables . As follows :
DAC8552Initialization(&dac8552, //DAC8552 Object variables
DAC8552TransmitData, // Write data function pointer
DAC8552CS // Chip selection operation function pointer
);
3.2、 Object based operations
After initializing the object variable , Based on this object variable, we can implement our DAC8552 Operating the . We have encapsulated a function that operates on its shift register , Call this function directly to realize our operation . A simple implementation function is as follows :
/* modify DAC8552 Channel output of */
void DAC8552Operation(void)
{
uint16_t wData=0;
wData=(uint16_t)(65535*tValueA/100);
SetDAC8552ChannelValue(&dac8552, // The operation of DAC object
DAC8552_LoadA, // Loaded channel
DAC8552BS_BufferA, // Selected cache
DAC8552PD_Normal, //Power-Down Set up
wData // The data written
);
wData=(uint16_t)(65535*tValueB/100);
SetDAC8552ChannelValue(&dac8552, // The operation of DAC object
DAC8552_LoadB, // Loaded channel
DAC8552BS_BufferB, // Selected cache
DAC8552PD_Normal, //Power-Down Set up
wData // The data written
);
}
In this example, we have adjusted... By percentage setting A、B The output of the channel , To operate in normal mode A perhaps B passageway , And update the specified cache .
4、 Application Summary
We designed and implemented DAC8552 Analog to digital converter driver , And a simple application is designed to verify the correctness of the driver . The results show that the design of the driver is no problem , In fact, we have applied it to practical projects , Good effect .
When using the driver, you should pay attention to , The chip selection signal does not have to be realized . Because sometimes we may need to select it directly on the hardware , At this point, adding a slice selection operation function is meaningless , We can pass in NULL To complete .
Welcome to your attention :

边栏推荐
- PPT导入视频裁剪后,如何裁剪后的视频另存为保存下来?
- 高精度人员定位系统,电厂室内定位应用解决方案
- 蘑菇街發布2022財年財報:下半年虧損同比收窄50%
- Mongodb basic understanding
- Database final exam outline
- Clickhouse2 fragment 2 replica high availability cluster setup and chproxy proxy configuration
- Kotlin 's Null safety
- Mushroom Street released the financial report of fiscal year 2022: the loss in the second half of the year narrowed by 50% year-on-year
- 使用postman模拟携带token的请求
- UML series articles (21) high level behavior - events and signals
猜你喜欢

bucher液压泵怎么选择?掌握这3点很重要!

技术分享| 浅谈调度平台设计

UML series articles (21) high level behavior - events and signals

数据库操作语句

市场变化,欢聚集团如何穿越不确定性风暴?

Mendeley 等文献管理工具在word中插入参考文献的报错解决

Database final exam outline

After ppt imports video clipping, how to save the clipped video as?

As the market changes, how does huanju group survive the storm of uncertainty?

fastadmin 自定义导出的excl表名称+时间
随机推荐
The original, skillful and vulgar skills of cloud
ROS编译报错 genmsg/cmake/genmsg-extras.cmake:307 的解决方法
Quit smoking log_ 03 (day_07)
ROS compilation error genmsg/cmake/genmsg-extras Cmake:307 solution
[work direction] CONDA common command summary
UML series article (22) advanced behavior -- state machine
[C language] summary of document knowledge points
MongoDB基础理解
WPF 数据绑定(二)
Can I use machine learning programming without knowing mathematics?
Introduction to mongodb framework zero Foundation (unfinished)
Mendeley 等文献管理工具在word中插入参考文献的报错解决
The Sandbox 和 Ikonia 达成合作,在元宇宙中还原足球传奇人物皮尔洛的壁画
Chapter_ 05 adding (fusing) two images using OpenCV
生产者消费者问题
[quick record for CV] teachyourselfsql_ MySQL
No editing software is needed to teach you how to edit videos simply and quickly
【工作向】conda常用命令汇总
常用类——String类概述
自己写的小工具,pillow库将图片转为buf