AnsweredAssumed Answered

Use DAC of STM32F103RET6 to create meaningful sound.

Question asked by neog.biswajit on Jul 14, 2014
Latest reply on Jul 24, 2014 by neog.biswajit
Hello Everyone , I am using STM32F103RETG to create a sound.I am also using elua and minicom to execute the program onto the uc. My plan is to -
*first use the DAC wave generator to create a simple noise. I will be using pin PA4 and TIM6.
*Secondly, once the code is working I would extend the same to create a noise using the DMA.
*Third I would use some wave files to integrate with the code to produce meaningful sound.

So far, i have used the codes present on the discussion board to create a simple noise. The code is listed below.However, it does not seem to be working. Please have a look at the code and tell me if i need to do it differently. Any advice will be much appreciated. Thank you.

static int omniexp_dac_pa4( lua_State *L )
  GPIO_InitTypeDef GPIO_InitStructure;
  DAC_InitTypeDef DAC_InitStructure;
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

  TIM_TimeBaseStructure.TIM_Period = 0xF;
  TIM_TimeBaseStructure.TIM_Prescaler = 0xF;
  TIM_TimeBaseStructure.TIM_ClockDivision =0x0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);

  /* TIM6 TRGO selection */
  TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);
  /* Enable DAC and GPIOC clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM6, ENABLE);
  /* Configure PA.04 (DAC) as output -------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  /* DAC channel1 Configuration */
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Triangle;
  DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_TriangleAmplitude_4095;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);

  DAC_Cmd(DAC_Channel_1, ENABLE);
  /* TIM6 enable counter */
  while (1)
  /* DAC channel1 Configuration */
  DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);