Skip to main content
Rect Cream
Visitor II
January 28, 2017
Solved

STM32F4 DAC not working

  • January 28, 2017
  • 3 replies
  • 907 views
Posted on January 28, 2017 at 23:40

hi,

   I am trying to use discovery board DAC module to adjust my external led's brightness by giving different level out voltage.

   I am sure that led is working on 3V, GPIOA.PA5 port also is working.

   But when I run the following my DAC module, the led has no light at all. Any ideas?

  void main()

  {

    uint32_t Ret;

    HAL_Init();

    __HAL_RCC_GPIOA_CLK_ENABLE();

    GPIO_InitTypeDef GPIOInitDef;

    GPIOInitDef.Pin = GPIO_PIN_4;

    GPIOInitDef.Mode = GPIO_MODE_ANALOG;

    GPIOInitDef.Pull = GPIO_NOPULL;

    GPIOInitDef.Speed = GPIO_SPEED_FREQ_LOW;

    HAL_GPIO_Init(GPIOA, &GPIOInitDef);

    DAC_HandleTypeDef DACHandleTypeStruct;

    DACHandleTypeStruct.Instance = DAC;

    Ret = HAL_DAC_Init(&DACHandleTypeStruct);

    DAC_ChannelConfTypeDef DACChannelConfStruct;

    DACChannelConfStruct.DAC_Trigger = DAC_TRIGGER_NONE;

    DACChannelConfStruct.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;

    Ret = HAL_DAC_ConfigChannel(&DACHandleTypeStruct,&DACChannelConfStruct, DAC_CHANNEL_1);

    Ret = HAL_DAC_Start(&DACHandleTypeStruct, DAC_CHANNEL_1);

    HAL_DAC_SetValue(&DACHandleTypeStruct, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 0x0FFF);

    while(1)

    {

      ;

    }

}

#dac
This topic has been closed for replies.
Best answer by Tesla DeLorean
Posted on January 29, 2017 at 01:24

>>Any ideas? 

An inability to source sufficient current? Try using a TIM pin in PP mode using PWM

3 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
January 29, 2017
Posted on January 29, 2017 at 01:24

>>Any ideas? 

An inability to source sufficient current? Try using a TIM pin in PP mode using PWM

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
January 29, 2017
Posted on January 29, 2017 at 08:45

Agree with Clive One, PWM has current strength while buffered DAC is intended for analog circuitry driving (and not direct LED). 

AvaTar
Senior III
January 30, 2017
Posted on January 30, 2017 at 07:52

A look at the datasheet would have revealed that the DAC output impedance is about 2 orders (buffered mode) or 5 orders of magnitude(unbuffered mode) too high.

And for dimming, analogue output is less suitable. As suggested, dimming / PWM is more energy efficient.