Skip to main content
Associate II
August 5, 2026
Question

DAC doesnt give 5 v output on oscilloscope

  • August 5, 2026
  • 1 reply
  • 38 views

#include "dac.h"
#include "main.h"

#define CURRENT_MIN    5
#define CURRENT_MAX    400

#define DAC_MIN        248      // 0.2 V
#define DAC_MAX        4095     // 3.3 V

void DAC_Init(void)
{
    HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);

    HAL_DAC_SetValue(&hdac1,
                     DAC_CHANNEL_1,
                     DAC_ALIGN_12B_R,
                     4095);
}

void DAC_SetCurrent(uint16_t current)
{
    uint32_t dac;

    if(current < CURRENT_MIN)
        current = CURRENT_MIN;

    if(current > CURRENT_MAX)
        current = CURRENT_MAX;

    dac = DAC_MIN +
          (((uint32_t)(current - CURRENT_MIN) *
            (DAC_MAX - DAC_MIN)) /
            (CURRENT_MAX - CURRENT_MIN));

    HAL_DAC_SetValue(&hdac1,
                     DAC_CHANNEL_1,
                     DAC_ALIGN_12B_R,
                     dac);
}

void DAC_OutputOff(void)
{
    HAL_DAC_SetValue(&hdac1,
                     DAC_CHANNEL_1,
                     DAC_ALIGN_12B_R,
                     0);
}
 

1 reply

AScha.3
Super User
August 5, 2026

Which CPU?

And expecting 5V from chip at 3v3 supply?

Kidding or what?

If you feel a post has answered your question, please click on " Best Answer ".