cancel
Showing results for 
Search instead for 
Did you mean: 

Noisy DAC on STM32F303

epalaima
Associate II
Posted on August 08, 2016 at 22:39

Hi, I just set up DAC output on the STM32F303 Discovery Board and I'm noticing a lot of wideband noise on the output (about .5 volts peak to peak), even when I set it to a constant value within my program. Is there something in the way I'm am setting up DAC output that might be causing this? I based the output configuration off of the DMA_RAM_DAC peripheral example project.

Here is my code for setting up DAC output, please let me know if you see anything: 

int main(void)

{

  /*!< At this stage the microcontroller clock setting is already configured, 

       this is done through SystemInit() function which is called from startup

       file (startup_stm32f30x.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f30x.c file

     */

  

  DMA_Config();

  DAC_Config();

  TIM_Config();

  while (1)

  {

 DAC1Output = 4095;

  }

}

/**

  * @brief  Configures the TIM2

  * @param  None

  * @retval None

  */

static void TIM_Config(void)

{

  TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;

  /* TIM2 Periph clock enable */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

  /* Time base configuration */

  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); 

  TIM_TimeBaseStructure.TIM_Period = 0xFF;//0xFF;

  TIM_TimeBaseStructure.TIM_Prescaler = 0x0;       

  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;    

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  

  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

  /* TIM2 TRGO selection: update event is selected as trigger for DAC */

  TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);

  /* TIM2 enable counter */

  TIM_Cmd(TIM2, ENABLE);

}

/**

  * @brief  Configures DAC channel 1 and channel 2

  * @param  None

  * @retval None

  */

static void DAC_Config(void)

{

  DAC_InitTypeDef   DAC_InitStructure;

  GPIO_InitTypeDef  GPIO_InitStructure;

  

  /* Enable GPIOA Periph clock --------------------------------------*/

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

  

  /* Configure PA.04 (DAC1_OUT1), PA.05 (DAC1_OUT2) as analog */

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4 | GPIO_Pin_5;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  

  /* DAC Periph clock enable */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);

  

  /* Fill DAC InitStructure */

  DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;

  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;

  //DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;

  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;

  

  /* DAC channel1 Configuration */

  DAC_Init(DAC_Channel_1, &DAC_InitStructure);

  

  /* DAC channel2 Configuration */

  DAC_Init(DAC_Channel_2, &DAC_InitStructure);

  

  /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 

  automatically connected to the DAC converter. */

  DAC_Cmd(DAC_Channel_1, ENABLE);

  

  /* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is 

  automatically connected to the DAC converter. */

  DAC_Cmd(DAC_Channel_2, ENABLE);

  

  /* Enable DMA for DAC Channel1 */

  DAC_DMACmd(DAC_Channel_1, ENABLE);

}

/**

  * @brief  Configures DMA2 channel3

  * @param  None

  * @retval None

  */

static void DMA_Config(void)

{

  DMA_InitTypeDef   DMA_InitStructure;

  /* Enable DMA2 clock -------------------------------------------------------*/

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);

  DMA_DeInit(DMA2_Channel3);

  DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address;

  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DAC1Output;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;

  DMA_InitStructure.DMA_BufferSize = 1;

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;

  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_M2M = DMA_M2M_Disable;

  DMA_Init(DMA2_Channel3, &DMA_InitStructure);

  /* Enable DMA2 Channel3 */

  DMA_Cmd(DMA2_Channel3, ENABLE);

}

#stm32 #dac #noise #stm32f303
1 REPLY 1
Walid FTITI_O
Senior II
Posted on August 16, 2016 at 18:05

Hi , 

Be careful to these points :

+ Check if the 

PeripheralBaseAddr ''DAC_DHR12RD_Address;'' is correct . T think the corret one is ''DAC_DHR12R2_Address;''

+ Check the wave generation parameters which is set to none . I think it should be chaged to  

''DAC_WaveGeneration_Triangle''

-Hannibal-