5075 views|9 replies

411

Posts

9

Resources
The OP
 

I want to use TIM+DMA+DAC conversion for stm32F4. Can someone help me find out what is wrong with the program? [Copy link]

This post was last edited by shijizai on 2018-7-25 17:31 I want to use TIM+DMA+DAC conversion for stm32F4. Can someone help me find out what's wrong with the program? The oscilloscope can't display the waveform. This is the main function #include "dac.h" #include "sys.h" #include "delay.h" #include "led.h" u16 Sine12bit[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 }; int main(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); TIM6_Config(5000-1,840-1); delay_init(168); while (1) { DAC_DeInit(); DAC_Ch2_SineWaveConfig(); // DAC_SetChannel2Data(DAC_Align_12b_R, 100); // DAC_SetChannel2Data(DAC_Align_12b_R, 3000); } } This is the function of DAC+TIM+DMA #include "dac.h" #include "sys.h" #include "led.h" extern u16 Sine12bit[32]; void TIM6_Config(u16 arr, u16 psc) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = arr; TIM_TimeBaseStructure.TIM_Prescaler = psc; 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); } void DAC_Ch2_SineWaveConfig(void) { DMA_InitTypeDef DMA_InitStructure; DAC_InitTypeDef DAC_InitStructure; DMA_DeInit(DMA1_Stream6); DMA_InitStructure.DMA_Channel = DMA_Channel_7; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&DAC->DHR12R2; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&Sine12bit; 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_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; 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_Full; 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_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;
//    DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
    DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
  DAC_Init(DAC_Channel_2, &DAC_InitStructure);

  DAC_Cmd(DAC_Channel_2, ENABLE);

  DAC_DMACmd(DAC_Channel_2, ENABLE);
   
//    DAC_SetChannel2Data(DAC_Align_12b_R,0);
   
}
这个是.h文件
#ifndef __dac_H
#define __dac_H
#include "sys.h"

void TIM6_Config(u16 arr, u16 psc);
void DAC_Ch2_SineWaveConfig(void);

#endif
期待大神。。。

DAC0.rar

4.29 MB, downloads: 33

DAC+TIM+DMA未成功程序

This post is from stm32/stm8

Latest reply

AFIO clock is not turned on   Details Published on 2019-6-11 11:04
 

4005

Posts

0

Resources
2
 
There is no need to repeat DAC_DeInit(); Also, if you have TIM, you don't need DMA, just one will do.
This post is from stm32/stm8

Comments

I understand the first sentence, but not the second. TIM controls the trigger time, and DMA controls the transmission. There is no overlap in their functions. Why is it enough to have only one?  Details Published on 2018-7-25 18:43
 
 

411

Posts

9

Resources
3
 
huo_hu posted on 2018-7-25 18:10 There is no need to repeat DAC_DeInit(); In addition, if there is TIM, there is no need for DMA, just one is enough.
I understand the first sentence, but not the second one. TIM controls the trigger time, and DMA controls the transmission. There is no overlap in the functions of the two. Why is it enough to have only one?
This post is from stm32/stm8

Comments

The purpose of DMA transmission is to reduce the transmission time occupied by the MCU. You just need to process the previous data before the timer triggers the next conversion. It's not impossible, it's just unnecessary.  Details Published on 2018-7-26 16:57
 
 

9707

Posts

24

Resources
4
 
The official has ready-made code for you to learn about
This post is from stm32/stm8

Comments

Well, I'll look for it.  Details Published on 2018-7-26 08:39
 
 
 

411

Posts

9

Resources
5
 
littleshrimp posted on 2018-7-25 21:50 The official has ready-made code, you can learn about it
Well, I'll look for it
This post is from stm32/stm8
 
 
 

4005

Posts

0

Resources
6
 
This post was last edited by huo_hu on 2018-7-26 17:03
Shijizai posted on 2018-7-25 18:43 I understand the first sentence, but not the second one. TIM controls the trigger time, and DMA controls the transmission. There is no overlap between the two functions. Why...
Yes, I read it wrong. DAC can

This post is from stm32/stm8

Comments

Uh-huh  Details Published on 2018-7-26 18:36
 
 
 

411

Posts

9

Resources
7
 
huo_hu posted on 2018-7-26 16:57 Yes, I read it wrong. DAC is OK
Yes
This post is from stm32/stm8
 
 
 

2

Posts

0

Resources
8
 
Is the problem solved?
This post is from stm32/stm8

Comments

Solved, but it's been a while, I took some time to think about it and posted the solution on this post  Details Published on 2019-5-7 18:38
 
 
 

411

Posts

9

Resources
9
 
It is solved, but it is a bit long ago. I will take some time to think about it and post the solution on this post
This post is from stm32/stm8
 
 
 

21

Posts

0

Resources
10
 

AFIO clock is not turned on

This post is from stm32/stm8
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list