DAC+DMA输出正弦波没波形

2019-07-20 00:49发布


#include "sin.h"

const u16 Sine12bit[32] = {
        2448,2832,3186,3496,3751,3940,4057,4095,4057,3940,
        3751,3496,3186,2832,2448,2048,1648,1264,910,600,345,
        156,39,0,39,156,345,600,910,1264,1648,2048
};
      
      u32 Sine12bit1[32];

void SineWave_GPIO_Config(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
       
          GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AN;      
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;   
    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4;   
    GPIO_Init(GPIOA, &GPIO_InitStructure);      
}


void SineWave_DAC_Config(void)
{
    DAC_InitTypeDef            DAC_InitStructure;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

    DAC_InitStructure.DAC_Trigger=DAC_Trigger_T2_TRGO;
          DAC_InitStructure.DAC_WaveGeneration=DAC_WaveGeneration_None;
          DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bit0;
          DAC_InitStructure.DAC_OutputBuffer=DAC_OutputBuffer_Disable ;       
    DAC_Init(DAC_Channel_1,&DAC_InitStructure);       
       
          DAC_Cmd(DAC_Channel_1, ENABLE);
    DAC_DMACmd(DAC_Channel_1, ENABLE);
}



void SineWave_TIM_Config(void)
{
    TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
       
    TIM_TimeBaseStructure.TIM_Prescaler=0x0;     
    TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
    TIM_TimeBaseStructure.TIM_Period=19;
          TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
       
    TIM_SelectOutputTrigger(TIM2,TIM_TRGOSource_Update);
       
          TIM_Cmd(TIM2,ENABLE);
}

void SineWave_DMA_Config(void)
{                  
    DMA_InitTypeDef            DMA_InitStructure;
    RCC_APB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);

    DMA_InitStructure.DMA_Channel=DMA_Channel_7;
DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)&(DAC->DHR12R1);
    DMA_InitStructure.DMA_Memory0BaseAddr=(u32)&(Sine12bit1);

    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_Priority=DMA_Priority_VeryHigh;
    DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;
   
    DMA_Init(DMA1_Stream5,&DMA_InitStructure);
       
    DMA_Cmd(DMA1_Stream5, ENABLE);      

}



void SineWave_Init(void)
{
    u16 i=0;
    SineWave_GPIO_Config();            
    SineWave_TIM_Config();            
    SineWave_DAC_Config();              
    SineWave_DMA_Config();              
    TIM_Cmd(TIM2, ENABLE);       
    for(i=0;i<32;i++)       
        {
     Sine12bit1=Sine12bit;
       
        }
       
}
为什么呀


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
翼行园子
1楼-- · 2019-07-20 03:48
03零三邓何芯桃
2楼-- · 2019-07-20 07:25
 精彩回答 2  元偷偷看……
13372533333
3楼-- · 2019-07-20 12:59
怎么解决的

一周热门 更多>