STM32 - Understanding DAC in One Text

Publisher: Future architect Updated on: April 21, 2022 Source: eefocus keyword: STM32    DAC    Digital input Mobile phone reading articles Scan QR code
Read articles on your mobile phone anytime, anywhere

1 DAC overview of STM32

The DAC module of STM32 is a 12 bit digital input and voltage output digital/analog converter, with two output channels, and each channel has a separate converter. In the dual DAC mode, the two channels can be converted independently, or simultaneously and synchronously update the output of the two channels. DAC can input reference voltage VREF+through pins to obtain more accurate conversion results. The DAC module is under the APB1 clock!


Note: The DAC module of STM32 only exists in high-capacity products (the FLASH capacity is between 256K and 512K).


1.1 Main characteristics

Two DAC converters: each converter corresponds to one output channel

8-bit or 12 bit monotone output

Left or right alignment of data in 12 bit mode

Synchronous update function

Noise waveform generation

Triangular wave Shape generation

Simultaneous or separate conversion of dual DAC channels

Each channel has DMA function

External trigger conversion

Input reference voltage VREF+


1.2 Block Diagram

The block diagram of a single DAC is as follows:

It is mainly divided into the following parts:


Power supply and reference voltage, output, trigger source, control register (corresponding to white) Data register DHR、 Digital to analog conversion unit.


The power supply pin has been introduced in STM32 - Understanding ADC.


There is nothing to say about the output. It should be noted that once the DAC x channel is enabled, the corresponding GPIO pin (PA4 or PA5) will be automatically connected to the analog output of the DAC

(DAC_OUTx)。 The output pins of the DAC1 and DAC2 modules are PA4 and PA5. To avoid parasitic interference and additional power consumption, when using the DAC function, the corresponding pins should be set to analog input (AIN).


The trigger sources are mainly as follows

If TENx bit is set to 1, DAC conversion can be triggered by an external event (timer counter, external interrupt line). Configure the control bit TSELx [2:0] to select one of the eight trigger events to trigger DAC conversion.


The so-called trigger refers to converting the data in the data register DORx into the signal output by the analog signal. Simply speaking, it is to refresh the output signal, because the data in the DOR data register will not be converted immediately after being updated, but will not be converted until the trigger signal.


Trigger can be selected as:

(1) The trigger mode is not used. In this mode, the DAC conversion module automatically converts once only after writing data to the DAC data register DHR.

(2) Software trigger mode: in this mode, the conversion is triggered when the command is written to the software trigger register SWTRIGR, that is, the data in the DOR register is converted.

(3) External trigger mode.

(3.1) Timer trigger, which is a periodic trigger mode, that is, periodic refresh mode. When will this method be used? Complex waveform! For example, output triangle wave. As will be mentioned later, the data generation of triangular wave is generated by a separate counter, which will add 1/minus 1 after each trigger. Imagine that if we trigger the timer to increase or decrease its output amplitude at a fixed time interval, and then set the maximum value of this counter, we can generate triangular waves of a certain frequency?

(3.2) External interrupt EXTI line trigger is mainly used for external signal control DAC conversion.


The control register mainly configures channel x, such as DMA enable, noise/triangle wave generation, trigger source selection, channel x trigger enable, etc. Details will follow.


There are 9 data registers DHR in total, but they are essentially used to store the data output from DAC. The data here will be transferred to the ODR register for DA output when appropriate.


A/D conversion unit, which loads the data in the data register into the DOR register and performs DA conversion.


The DAC output is directly controlled by the DORx register, but we cannot write data directly to the DORx register. Instead, DHRx is indirectly transferred to the DORx register to control the DAC output.


2 Function Details

2.1 DAC data format

STM32 product with dual DAC module, its DAC module has 9 data registers (DHR)! In the single channel mode, DAC1 and DAC2 are used separately, Dual channel There are also 3 registers in mode.


Three data formats in single channel mode, including 8-bit right alignment, 12 bit left alignment, and 12 bit right alignment. As shown in the figure below

The three data formats in dual channel mode are also 8-bit right aligned, 12 bit left aligned, and 13 bit right aligned. As shown in the figure below


2.2 Relationship between data registers DHR and DOR

The data register DHR is a development oriented register that can directly write data, which is the data output to the corresponding DAC channel.


The data register DOR is a register that directly controls the DAC data output. Data cannot be written to this register directly. The data of this register is transferred from the data register DHR.


If the DAC is not output by enabling external trigger, the data stored in the register DHR will be automatically transferred to the DOR after an APB1 clock cycle.

If the external departure mode is enabled, it shall be transmitted to DOR three APB1 clock cycles after the external trigger signal occurs. As shown in the figure below


2.3 DAC output voltage

Range: 0~Vref


Relationship: DAC output=Vref x (DOR/4095)


DAC has an output buffer function, which can increase the output drive capability of the IO port, but there is a problem that the output cannot return to zero! This function is not recommended.


2.4 Noise generation

Operation.. It's OK to generate noise!


STM32 uses linear feedback to generate noise for the register (LFSR), as shown in the following figure. To understand the principle of noise generated by such registers, here and here. Don't go deep into its principle first, just know it can!

Set WAVEx [1:0] bit of DAC_CR register to '01' to select DAC noise generation function, and update the value of this register after 3 APB1 clock cycles after each trigger event. Set the MAMPx [3:0] bit of the DAC_CR register to mask the data of some or all LFSR registers.


Whether generating noise or triangular wave, the final output data of DAC is the addition of LSFR value and DAC_DHRx value, and then the overflow bit is removed. It is then written to the DAC_DORx register. (The following figure about triangular wave can be explained vividly)


In this way, if overflow occurs, some DC parts can be removed (that is, the value part in DAC_DHRx).


What is removing overflow bits?


For example, for an 8-bit data, the maximum number of bits that can be represented is 0xFF, and then add 1 to become 0x00, which is called removing the overflow bit. Because 0xFF+0x01=0x100, the highest bit here is the overflow bit for 8-bit data, which becomes 0x00 after removal.


Note: In order to generate noise or triangular wave, DAC triggering must be enabled (set TENx bit of CR register as 1). This is because the DOR register can be modified (modified by the noise algorithm circuit or the triangle wave counter) without modifying the value of the DHR register for output noise or triangle wave, and the modification is periodic. Therefore, the DA output must be constantly updated by triggering. Generally, the timer triggering method is used.


2.5 Triangular wave generation

Triangle wave can be added on the basis of DC signal output by DACx. Set WAVEx [1:0] bit to '10' to select the triangle wave generation function of DAC. Set the MAMPx [3:0] bit of the DAC_CR register to select the amplitude of the triangular wave.

There is a triangle wave counter inside the DACx module, which accumulates 1 after 3 APB1 clock cycles after each trigger event. The counter value is added to the value of the DAC_DORx register, and the overflow bit is discarded and written to the DAC_DORx register. When the value passed into the DAC_DORx register is less than the maximum amplitude defined by the MAMP [3:0] bit, the triangle wave counter will accumulate gradually. Once the set maximum amplitude is reached, the counter starts to decrease, and then starts to accumulate after reaching 0.


Note: The MAMP [3:0] bit must be set before enabling DAC, otherwise its value cannot be modified.


2.6 Dual DAC channels

DAC supports the simultaneous use of two modules and has a special data register in dual channel mode (mentioned above).


There are 11 modes available in dual channel mode.

 image.png

2.6.1 Independent trigger without waveform generator

When the DAC channel 1 trigger event occurs, the value of register DHR1 (after delaying 3 APB1 clock cycles) is transferred to register DAC_DOR1.

When the DAC channel 2 trigger event occurs, the value of register DHR2 (after delaying 3 APB1 clock cycles) is transferred to register DAC_DOR2.


2.6.2 Independent Trigger Using the Same LFSR

When the DAC channel 1 trigger event occurs, the LFSR1 counter value with the same mask is added to the DHR1 register value, and the result (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR1, and then the LFSR1 counter is updated.

When the DAC channel 2 trigger event occurs, the LFSR2 counter value with the same mask is added to the DHR2 register value, and the result (after delaying 3 APB1 clock cycles) is passed into the register DAC_DOR2, and then the LFSR2 counter is updated.


2.6.3 Independent triggering using different LFSRs

When the DAC channel 1 trigger event occurs, the LFSR1 counter value masked according to the MAMP1 [3:0] is added to the DHR1 register value, (after delaying 3 APB1 clock cycles) the result is transferred to the register DAC_DOR1, and then the LFSR1 counter is updated.

When the DAC channel 2 trigger event occurs, the LFSR2 counter value masked according to the MAMP2 [3:0] is added to the DHR2 register value, (after delaying 3 APB1 clock cycles) the result is transferred to the register DAC_DOR2, and then the LFSR2 counter is updated.


2.6.4 Independent trigger for generating the same triangle wave

When the DAC channel 1 trigger event occurs, the same triangle amplitude value plus the value of the DHR1 register (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR1, and then the DAC channel 1 triangle wave counter is updated.

When the DAC channel 2 trigger event occurs, the same triangle amplitude value plus the value of the DHR2 register (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR2, and then the DAC channel 2 triangle counter is updated.


2.6.5 Independent triggering for generating different triangular waves

When the DAC channel 1 trigger event occurs, the triangle wave amplitude value set by MAMP1 [3:0] plus the DHR1 register value (after delaying 3 APB1 clock cycles) is transferred to the register DAC_DOR1, and then the DAC channel 1 triangle wave counter is updated.

When the DAC channel 2 trigger event occurs, the triangle wave amplitude value set by MAMP2 [3:0] plus the DHR2 register value (after delaying 3 APB1 clock cycles) is transferred to the register DAC_DOR2, and then the DAC channel 2 triangle wave counter is updated.


2.6.6 Simultaneous software startup

In this configuration, after an APB1 clock cycle, the values of DHR1 and DHR2 registers are transferred to DAC_DOR1 and DAC_DOR2 registers respectively.


2.6.7 Simultaneous triggering without waveform generator

When a trigger event occurs (after delaying 3 APB1 clock cycles), the values of DHR1 and DHR2 registers are transferred to DAC_DOR1 and DAC_DOR2 registers respectively.


2.6.8 Simultaneous triggering using the same LFSR

When a trigger event occurs, the LFSR1 counter value masked by MAMP1 [3:0] is added to the value of the DHR1 register, and the result (after three APB1 clock cycles are delayed) is transferred to the DAC_DOR1 register, and then the LFSR1 counter is updated.

Similarly, the LFSR2 counter value of the mask set by MAMP1 [3:0] is added to the value of the DHR2 register, and the result (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR2, and then the LFSR2 counter is updated.


2.6.9 Simultaneous triggering using different LFSRs

When a trigger event occurs, the LFSR1 counter value with the same mask is added to the DHR1 register value, and the result (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR1, and then the LFSR1 counter is updated.

At the same time, the LFSR2 counter value with the same mask is added to the DHR2 register value, and the result (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR2, and then the LFSR2 counter is updated.


2.6.10 Simultaneous triggering using the same triangle wave generator

When a trigger event occurs, the same triangle amplitude value is added to the DHR1 register value, and the result (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR1, and then the LFSR1 counter is updated.

At the same time, the same triangle amplitude value is added to the DHR2 register value, and the result (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR2, and then the LFSR2 counter is updated.


2.6.11 Simultaneous triggering with different triangle wave generators

When a trigger event occurs, the triangle amplitude value set by MAMP1 [3:0] is added to the value of the DHR1 register, and the result (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR1, and then the LFSR1 counter is updated.

At the same time, the triangle amplitude value set by MAMP2 [3:0] is added to the DHR2 register value, and the result (after three APB1 clock cycles are delayed) is transferred to the register DAC_DOR2, and then the LFSR2 counter is updated.


3 Related registers

3.1 DAC control register (DAC_CR)

This register is used to configure DAC1 (low 8 bits) and DAC2 (high 8 bits), here only DAC1 is mentioned.

3.2 DAC software trigger register (DAC_SWTRIGR)

Control software triggering of DAC1 and DAC2.

The other controls DAC2.


3.3 Various DHR data registers

The register format is shown in the picture in section 2.1. A total of 9.


3.4 Two DOR data registers

The register that ultimately controls the DAC output.

————————————————

Copyright notice: This is the original article of CSDN blogger "BUG from beginner to proficient", which follows CC 4.0 BY-SA copyright agreement. Please attach the original source link and this notice for reprinting.

Original link: https://blog.csdn.net/wei348144881/article/details/109295021


keyword: STM32    DAC    Digital input Reference address: STM32 - Understanding DAC in One Text

Previous: STM32 - Quick Start DAC
Next: STM32 - Quick Start DMA

Recommended reading Latest update time: 2024-09-26 11:06

be based on STM32 BLE smart bulb
This article will teach you how to use STM32 to make a smart bulb with BLE enabled. Home automation involves automating home environment equipment. To this end, we have developed a smart light bulb that is easy to install and can control connected devices through a web browser or smartphone application. The purpose of this project is to use a web browser or smart phone to control different household appliances. 1、 This project shows a simple method of using BleuIO Dongle to open and close the bulb connected to STM32 Nucleo-144 through 5V relay. You will need two dongles, one connected to the Nucleo board and the other connected to the computer, to run the web script. When BleuIO Dongle is connected to the USB port of the Nucleo board, STM32 will recognize it and directly start advertising. This allows another dongle to connect to it.
[MCU]
 BLE smart bulb based on<font color='red '>STM32</font>
stm32 Topic 14: Memory Introduction
Memory is generally divided into volatile memory (RAM - random access memory) and non-volatile memory (ROM - read only memory) volatile memory (SRAM): Static Random Access Memory (SRAM). The basic storage unit is composed of SR latch, which does not need to be refreshed regularly. DRAM: Dynamic Random Access Memory (SRAM), composed of capacitors and transistors, is very simple in structure. The storage unit of dynamic random access memory DRAM represents data by the charge of capacitance, with charge representing 1 and without charge representing 0. But over time, the capacitor representing 1 will discharge, and the capacitor representing 0 will absorb charges, so it needs to be refreshed regularly. Refresh Operation
[MCU]
 <font color='red '>stm32</font>Topic 14: Memory Introduction
Design of servo controller for bionic hydraulic quadruped robot
Introduction In recent years, various military robots have played an important role in the field of national defense and geo strategy. In the vast western region of China, due to the complex terrain and rough roads, traditional wheeled or tracked robots cannot meet the requirements of terrain trafficability, while bionic quadruped robots can better meet the task requirements of reliable travel in unstructured terrain. The hydraulic driven bionic quadruped robot is a research hotspot and major project at home and abroad in recent years. Among its key technologies, the electro-hydraulic servo control technology is the core technology to ensure the bionic hydraulic quadruped robot to achieve stable travel function. 1 Overall design 1.1 Control object analysis This paper relies on a bionic hydraulic quadruped robot being developed by the Special Robot Technology Innovation Center of Beijing University of Technology. Each leg of the robot has three active degrees of freedom and one passive degree of freedom, respectively, the hip side sway joint, the hip forward swing joint, the knee joint and the foot second-order spring damper, All 12 active joints are composed of fluid
[MCU]
 Design of servo controller for bionic hydraulic quadruped robot
Play with STM32CubeMX| DAC Digital to analog conversion
1. DAC (digital to analog converter) is a digital to analog converter, which can convert digital signals into analog signals. Its function is opposite to that of ADC. In common digital signal systems, most sensor signals are converted into voltage signals, while ADC converts voltage analog signals into digital codes that are easy for computer storage and processing. After computer processing, DAC outputs voltage analog signals to drive some executive devices, making it easy for humans to perceive. For example, audio signal acquisition and restoration is such a process. The DAC module of STM32F1 is a 12 bit digital input and voltage output DAC. It can be configured as 8-bit or 12 bit mode, or it can be used with DMA controller. When DAC works in 12 bit mode, data can be set as left aligned or right aligned. The DAC module has two output channels, and each channel has a separate converter. In dual DAC
[MCU]
 Play with STM32CubeMX |<font color='red '>DAC</font>digital analog conversion
stm32 Clock division
(1) TIM_Perscaler to set the prescaler coefficient; (2) TIM_ClockDivision to set the clock division (clock division factor); (3) TIM_CounterMode to set the counter mode; Clock division defines the division ratio between the timer clock frequency (CK_INT) and the sampling frequency used by digital filters (ETR, TIx). Parameters of TIM_ClockDivision are shown in the following table: TIM_ClockDivision describes binary values TIM_CKD_DIV1 tDTS = Tck_tim 0x00 TIM_CKD_DIV2 tDTS = 2 * Tck_tim 0x01 TIM_CKD_DIV4 tDTS = 4
[MCU]
Stm32 Key input Control LED
Note: GPIOA, GPIO_Pin_0 corresponds to key1; GPIOA, GPIO_Pin_1 corresponds to key2; GPIOA, GPIO_Pin_2 corresponds to LED1; GPIOA, GPIO_Pin_3 correspond to LED2 # include stm32f10x. h # include stm32f10x_rcc. h # include stm32f10x_gpio. h # include system_stm32f10x. h/* Control light: 0 off 1 on */# define ON 1 # define OFF 0 # define KEY_ON 0 # define KEY_OFF 1 void RCC_
[MCU]
STM32 Program and circuit design of driving DC motor
This paper introduces how to use STM32F103 single chip microcomputer to drive the program design and circuit design of DC motor by setting the complementary PWM embedded in the dead zone output of advanced timer TIM1 through the official firmware library. The hardware circuit uses IR2110S chip as the driver of mos transistor to drive the H bridge composed of IRF840. In the use of IR2110S chip, there is a difficult point to understand - bootstrap capacitor. This article also involves its principle. The schematic diagram file is a simplified schematic diagram of the system, and the left side is a single-chip microcomputer. In the middle is IR2110S chip. In order to facilitate explanation, the internal structure of the chip is listed. On the right is the H bridge composed of MOS tubes. M is a DC motor with positive and negative rotation. VCC is 15V, MOTOR_VCC is 24V, the voltage can be changed, and the maximum value is not more than 500V. Generally, the single chip microcomputer is 3.3V or 5V, which cannot directly drive the motor. The control of DC motor can be realized by means of H-bridge
[MCU]
 <font color='red '>STM32</font>Program and circuit design for driving DC motor
How to use code clearing STM32 PCROP on MCU
Preface STM32PROP proprietary code reading protection, setting a certain area to only allow execution, can prevent the code from being read and modified illegally. The ST website provides free PCROP reference code, but the routine only provides setting PCROP with code. To facilitate the development and deployment of intellectual property protection with PCROP, this article provides a method to clear PCROP with code when the RDP level is set to 1 or 0. PCROP reference code on ST website Learn to use PCROP. You can download documents and reference code from ST website. There are step-by-step instructions in the document. The reference code implements how to set the compilation and development environment to remove the Literal pool, so as to avoid reading and accessing the protected area; The reference code also realizes how to use code to enable PCROP protection and how to export interface symbols for secondary development. You can compile and run
[MCU]
 How to use code to clear the PCROP on the<font color='red '>STM32</font>MCU

Recommended Posts

[All purpose small gateway | CH32V208] -- 3. Key interruption
This section describes the external interrupt of key IO. 1、 The principle and preparation of keys are known from the following schematic diagram that the user's keys are triggered at low level on the falling edge. Here we use PA0 as the key detection IO port, and connect the pin PA0 and KEY pins on the DuPont cable. Figure 1: Key Principle II. Code Preparation 1. Initialize and configure PA0 external interrupt, and trigger the falling edge. voidEXTI0_INT_INIT(void){GPIO_InitTypeDefGPIO_InitStructure={0}; EXTI_InitTypeDefEXTI_InitStructur
dirty Domestic chip communication
Calculate the parameters of the low-pass filter
To get the cut-off frequency of 100HZ, how to calculate R3BR4BR5B? Calculate the parameters of the low-pass filter. Find the screenshot on the Internet and search for the post of teacher gmchen. This is one of the articles "Random talk about active power filter low-pass filter". This circuit of the building is a third-order low-pass filter. Mr. Zhang said to search my post, but I'm sorry that I didn't mention the third-order filter of this structure in my post. This third-order filter implemented with an operational amplifier has a cut-off angle frequency equal to the third root of the reciprocal of the product of three resistors and three capacitors. In the figure on the first floor, the three capacitors in the circuit with cut-off frequency of 100Hz are already 1/10 of the cut-off frequency of 10Hz
zk643 Analog electron
Mobile payment, the next security battlefield
As a basic application of RFID, mobile payment has gradually shifted from the initial hype concept to an all-round application. Some technologies and industries related to mobile payment have developed well in the past two years, which provides the basic conditions for the development of mobile payment. For example, the development of mobile Internet enables users to access more services through mobile phones; Mobile terminals have more and more functions. Mobile phones have the power of wallet and bus card. It is predicted that from 2010 to 2012, the mobile payment industry will have a blowout development. However, it cannot be denied that the disunity of mobile payment standards will inevitably affect the way forward for mobile payment. For the security market, how will cross-border applications of mobile payment affect the security world? Mobile payment
xyh_521 Security Electronics
How to draw PCB board with VGA USB power supply
Hello everyone, I'm a novice. Today, the master said that I should draw a power board with USBVGA two pin power supply on one side. There are no other components. How should I draw it? What's more, how is the packaging of VGA? I asked the master not to say more, so I had to ask everyone how to draw a PCB board with VGA USB power supply. Thank you
Pine in snow PCB design
Selection Rules of ST AMG SensorTile Development Competition
Click to learn about the selection rules of the STAMGSensorTile Development Contest Release date: December 2016 Basic requirements Originality: works must be first published in the original STMEMSBBS, otherwise they will not be selected. Authenticity: Let the judges see that SensorTile is indeed used in this design, otherwise it will not be selected. Scoring form (full score: 100 points) Scoring criteria for expert judges (80 points) Integrity of design documents (15 points): • Design name (required, not scored) • Functions implemented(
EEWORLD Community MEMS sensor
WEBENCH design process+power architecture design tool, 5VTO3.3; 1.5; 9V
The design requirement is to convert 5V DC voltage into 3.3V commonly used; 1.5V and 9V common voltage power supply. Enter the WEBENCH design tool interface, click the POWERARCHITECH tag, enter the following interface, fill in the 4-6V input voltage range in the input voltage configuration area, click the load adding button on the right side, add the output voltage value of 1.5.3.3.9V in turn, and modify the output current to 1A; Click the green button on the right to provide the solution tool to display the power architecture, cost, efficiency, power consumption and other calculation results according to the settings. Use the optimization tool of the tool to optimize the efficiency of the power supply. The results are shown in the figure below. Click the green button on the upper right corner to enter the next step. Design results of tools
gaon Analog and mixed signals
Small broadcast
Design Resources train Development board Essence recommendation

The latest single-chip article
He Limin Column Microcontroller and embedded dictionary

Professor of Beijing University of Aeronautics and Astronautics, devoted to the promotion of single-chip microcomputer and embedded system for more than 20 years.

Change more Relevant hot search device
Copyright Electronic Engineering World Beijing B2-20211791 Jing ICP Bei 10001474-1 TSSP [2006] No. 258 Jinggong Network Anbei No. 11010802033920 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved