cancel
Showing results for 
Search instead for 
Did you mean: 

Simple DAC application to generate Voltage on pin

luke514
Senior

I am using stm32f407g.

I wrote this simple code which (in theory) should give on pin PA4 the voltage set in "DACout_v" (in this case I set 2.8V)

Following this document (the section "Digital sine waveform pattern preparation") I derived DOR and then gave it to "HAL_DAC_SetValue".

With te oscilloscope I measure 2.60V. Why? I would like to understand what I am doing wrong.

 

float DACout_v = 2.8; //outside the main

while (1) {

DACout_d = DACout_v*(0xfff)/3.3; //DOR

HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, DACout_d);

}

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

VDD/VDDA/VREF+ is 3.0V on that board. That explains the issue.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

So ~10% error. Is your VREF+ 3.3V? What hardware is this?

If you feel a post has answered your question, please click "Accept as Solution".

I had not "calculated" the percentage error, in fact 10% error makes me think I was wrong in using 3.3V ... maybe I should put 3V. I do not have the microcontroller I am using (stm32f407g-disc1) with me at hand, but I am afraid of that Vref is 3V and not 3.3V

I'll check as soon as I can.

VDD/VDDA/VREF+ is 3.0V on that board. That explains the issue.

If you feel a post has answered your question, please click "Accept as Solution".