STM32 uses DAC+DMA+TIMER to output sine wave

Publisher:素心悠远Latest update time:2017-10-29 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The board used is STM32F407, and the program refers to the program in the DAC_SignalsGeneration folder of the STM32F4xx firmware library. The official routines use the Escalator Wave trapezoidal wave, Sine Wave sine wave of the DAC's disabled generation wave (DAC_WaveGeneration_None) and the built-in Noise Wave (DAC_WaveGeneration_Noise), Triangle Wave (DAC_WaveGeneration_Triangle) of stm32.

The following mainly talks about the configuration of output sine wave.


Array of sinusoidal voltages

const uint16_t aSine12bit[32] = {

                      2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056,

                      3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909,

                      599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647};

After plotting the above array using Matlab, it looks like this:

STM32 uses DAC+DMA+TIMER to output sine wave

The following is the program to configure DAC channel 2, turn on DMA, and set TIMER6 to trigger DAC

void DAC_Ch2_SineWaveConfig(void)

{

  DMA_InitTypeDef DMA_InitStructure;

  DAC_InitTypeDef  DAC_InitStructure;

 

  DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;

  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;

  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;

  DAC_Init(DAC_Channel_2, &DAC_InitStructure);

 

 

  DMA_DeInit(DMA1_Stream6);

  DMA_InitStructure.DMA_Channel = DMA_Channel_7; 

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R2_ADDRESS;

  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&aSine12bit;

  DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;

  DMA_InitStructure.DMA_BufferSize = 32;

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

  DMA_InitStructure.DMA_Priority = DMA_Priority_High;

  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;        

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  DMA_Init(DMA1_Stream6, &DMA_InitStructure);

 

 

  DMA_Cmd(DMA1_Stream6, ENABLE);

 

 

  DAC_Cmd(DAC_Channel_2, ENABLE);

 

 

  DAC_DMACmd(DAC_Channel_2, ENABLE);

}

Below is the configuration program for timer 6

The timer update frequency is 84M/(0xFF+1)=328KHZ

void TIM6_Config(void)

{

  TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;

 

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);

 

 

 

  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

  TIM_TimeBaseStructure.TIM_Period = 0xFF;         

  TIM_TimeBaseStructure.TIM_Prescaler = 0;      

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;   

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 

  TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);

 

 

  TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);

 

 

  TIM_Cmd(TIM6, ENABLE);

}

Because our sine waveform is composed of 32 points, the frequency of the output sine waveform is 328K/32=10.25K

Verify with an oscilloscope, as shown below

STM32 uses DAC+DMA+TIMER to output sine wave


Keywords:STM32 Reference address:STM32 uses DAC+DMA+TIMER to output sine wave

Previous article:Some problems encountered in learning STM3210X
Next article:Application principle of BOOT0 and BOOT1 of STM32 microcontroller

Recommended ReadingLatest update time:2024-11-16 13:40

STM32 uses DMA to read data from the serial port to the memory
Using DMA to read data from the serial port to the memory is the same as moving data from the memory to the serial port, but you need to pay attention to the different DMA channels used. Once configured, if there is data transmission on the serial port, DMA will automatically move the data to the memory. When working
[Microcontroller]
STM32——JLINK downloader flash firmware
While using the JLINK downloader, JLINK suddenly became unusable and the indicator light did not light up. I thought the board was burned out. After this failure occurred many times, I searched the Internet to find out the cause. I just went to Baidu and found that many people have this phenomenon. Reason: The count
[Microcontroller]
Steps to set up interrupts for STM32
The following figure summarizes the interrupts of the STM32F10XXX series chips By default, the interrupt vector table is located in a read-only memory such as Flash, and there is no need to modify the vector table during operation. The interrupt vector table is located at the beginning of the memory by default (a
[Microcontroller]
Steps to set up interrupts for STM32
stm32 controls lcd to write characters, draw lines, Chinese characters, etc.
1. Algorithm for drawing straight lines          When drawing a straight line, due to the granularity of the display on the LCD, the problem of the pace of the x and y axes is distinguished. The problem of pace involves the problem of slope. Therefore, even if the line drawing algorithm is completed, it is necessary t
[Microcontroller]
STM32 SysTick tick clock analysis
Analysis of Delay_ms() Function Generated by System sysTick() Clock SysTick timer, SysTick is a 24-bit countdown timer. When it counts to 0, it will automatically reload the timing initial value from the RELOAD register and start a new round of counting. As long as the enable bit in the SysTick control and status regi
[Microcontroller]
Using the PWM function of the microcontroller to realize DAC with the help of filters
P1027 of the STC15 manual, I’ll study it when I have time!
[Microcontroller]
Using the PWM function of the microcontroller to realize DAC with the help of filters
stm32 storage structure & memory map
1 STM32 system architecture     To deeply understand the memory of STM32, you need to first know the system structure of STM32. Figure 1 is a block diagram of the STM32 system structure. According to the description in the STM32 Reference manual (RM0008), as shown in the figure:     You can learn about the com
[Microcontroller]
stm32 storage structure & memory map
Red light therapy device control system based on STM32
1. Determination of STM32 ADC sampling frequency First look at some information to determine the clock of the STM32 ADC: (1) The ADCCLK clock provided by the clock controller is synchronized with PCLK2 (APB2 clock). The CLK controller provides a dedicated programmable prescaler for the ADC clock. (2)
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号