cancel
Showing results for 
Search instead for 
Did you mean: 

dac configuration

pedropbr
Associate II
Posted on November 30, 2010 at 00:07

dac configuration

22 REPLIES 22
lowpowermcu
Associate II
Posted on May 17, 2011 at 14:16

Thanks clive1 for this fast reply.

It is little bit confusing but it seems to work in both cases.

Herzlich,

MCU Lüfter

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:16

I think I have found it :)

In the configuration you are using channel2

and then when writing data you are using channel1

Try to change

DAC_SetChannel1Data(DAC_Align_12b_R, 0x100);

to

DAC_SetChannel2Data(DAC_Align_12b_R, 0x100);

MCU Lüfter

pedropbr
Associate II
Posted on May 17, 2011 at 14:16

Oh, sorry, It was just a misspell.

I was doing it right.

Still doesn't work. :(
Posted on May 17, 2011 at 14:16

With

DAC_SetChannel2Data(DAC_Align_12b_R, i);

I am able to drive my own wave form.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 17, 2011 at 14:16

int main(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

  DAC_InitTypeDef DAC_InitStructure;

    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

  /* Enable DAC and GPIOC clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM2, ENABLE);

  /* Configure PA.04/05 (DAC) as output -------------------------*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

#if 0

  /* TIM2 Configuration */

  TIM_TimeBaseStructInit(&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(TIM2, &TIM_TimeBaseStructure);

  /* TIM2 TRGO selection */

  TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);

  /* 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_2, &DAC_InitStructure);

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

     automatically connected to the DAC converter. */

  DAC_Cmd(DAC_Channel_2, ENABLE);

  /* TIM2 enable counter */

  TIM_Cmd(TIM2, ENABLE);

  while (1)

  {

  }

#else

  /* 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_2, &DAC_InitStructure);

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

     automatically connected to the DAC converter. */

  DAC_Cmd(DAC_Channel_2, ENABLE);

  while (1)

  {

        int i;

        for(i=0; i<4096; i++)

          DAC_SetChannel2Data(DAC_Align_12b_R, i);

  }

#endif

  /* does not exit - kind of important */

  return(1);

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pedropbr
Associate II
Posted on May 17, 2011 at 14:16

Hi clive1,

it worked, you're the guy! thank you very much. :)

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:16

Hi rbpeter,

What was the tip to make it working ?

MCU Lüfter

pedropbr
Associate II
Posted on May 17, 2011 at 14:16

The solution clive1 proposed generates an AC signal in the exit.

To generate a DC signal, you just have to set a value between 0 and 4095 on the DAC like:

DAC_SetChannel2Data(DAC_Align_12b_R, value);

and you don't have to put it into the loop, once the value is loaded to the register, the DAC keeps generating the corresponding voltage.

I was also debugging with the osciloscope in the wrong capacitor.

Thank you all
minhpc91
Associate II
Posted on December 04, 2014 at 14:03

Could you please check for me? It still doesn't work.

I'm using STM32F401VC Discovery.

I dont see the define ''RCC_APB2Periph_AFIO'' in the library I'm using. Is there anything else I can use instead?

I'm wondering if the PA4 and PA5 in my kit are out of order or not DAC1,2.

Please help me!!

int main(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

  DAC_InitTypeDef DAC_InitStructure;

  /* Enable DAC and GPIOC clock */

  RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC , ENABLE);

  // Configure PA.04/05 (DAC) as output -------------------------

  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_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* DAC channel1 Configuration */

  DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;

  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;

  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;

  DAC_Init(DAC_Channel_1, &DAC_InitStructure);

  DAC_Init(DAC_Channel_2, &DAC_InitStructure);

  DAC_Cmd(DAC_Channel_1, ENABLE);

  DAC_Cmd(DAC_Channel_2, ENABLE);

  while (1)

  {

        int i;

        for(i=0; i<4096; i++)

        {

        DAC_SetChannel1Data(DAC_Align_12b_R, i);

        DAC_SetChannel2Data(DAC_Align_12b_R, i);

        }

  }

  return(1);

}

Posted on December 04, 2014 at 14:59

This a four year old thread dealing with the STM32F1 parts, as I recall. The F4 pulls the AFIO functionality into the pin banks.

 RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

Should be AHB1 not APB2
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..