dac单通道dma输出正弦波,对吗?没有示波器,自己用adc采集没有数据

2019-07-20 02:46发布

[mw_shl_code=applescript,true]#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
};
      
      u16 Sine12bit1[32];
/****************ÕýÏÒ²¨Êä³öÒý½&AringA4³õʼ»¯******************/
void SineWave_GPIO_Config(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
          GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_DOWN;
    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);         
}

/******************ÕýÏÒ²¨DAC1³õʼ»¯*************************/
void SineWave_DAC_Config(void)
{
    DAC_InitTypeDef            DAC_InitStructure;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

    DAC_InitStructure.DAC_Trigger=DAC_Trigger_T2_TRGO;//ʹÓÃTIM2×÷Ϊ´¥·¢Ô´       
          DAC_InitStructure.DAC_WaveGeneration=DAC_WaveGeneration_None;
          DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bit0;
          DAC_InitStructure.DAC_OutputBuffer=DAC_OutputBuffer_Enable ;       
    DAC_Init(DAC_Channel_1,&DAC_InitStructure);       
       
          DAC_Cmd(DAC_Channel_1, ENABLE); //ʹÄÜͨµÀ1 Ó&EacuteA4Êä³ö
    DAC_DMACmd(DAC_Channel_1, ENABLE);//ʹÄÜDACµÄDMAÇëÇó
}


/******************ÕýÏÒ²¨TIM³õʼ»¯**************************/
void SineWave_TIM_Config(void)
{
    TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
       
    TIM_TimeBaseStructure.TIM_Prescaler=0xFF;     
    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);
       
}

/******************ÕýÏÒ²¨DMA³õʼ»¯**************************/
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_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_InitStructure.DMA_PeripheralBaseAddr=DAC_DHR12R1_Address;//ÍâÉèµØÖ·
    DMA_InitStructure.DMA_Memory0BaseAddr=(u32)&(Sine12bit1);//ÄÚ´æµØÖ·
    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++)        //&Igrave;&icirc;&sup3;&auml;&Otilde;&yacute;&Iuml;&Ograve;&sup2;¨&pound;&not;&micro;&yen;&Iacute;¨&micro;&Agrave;&Oacute;&Ograve;&para;&Ocirc;&AElig;&euml;
        {
     Sine12bit1=Sine12bit;
       
        }
       
}[/mw_shl_code]

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。