AnsweredAssumed Answered

DAC triangle waveform: DHR polluted, wrong output amplitude

Question asked by Antoine.PM on Jun 22, 2016
Hi again,

In my never-ending quest to understand the registers, I try some changes in the code I had to output a triangle waveform from DAC channel2 on STM32 F334R8.

I have several questions.

- I use PA_05 to output my signal, it corresponds to DAC1_OUT2, but also, refering to the pins definition here ,to LED2. It is configured as analog output, so I thought it was okay, but I can see a faint green light from the LED. Is there a leak or a flaw of any sort in the configuration? I'm pretty sure it is not supposed to glow even faintly if I don't ask it to do so.

- My code is supposed to send 0x100 as data (even though I have no idea what does it mean) to DHR12RD, but when I look into the registers, the value has been written pretty much everywhere. Why? Again, is there some flaw in my code?
dhr%20polluted.PNG


- Line 187, I specified the amplitude I wanted. The value was originally of 1023, and the output of 0.8 V. I wanted 3.3V, so I put 4095 (maximum), but that completely messed up my waveform on the oscilloscope, and the voltage is 2.00V, not 3.3. Why?
Also, when I do the math, following the formula here DACoutput = Vref * DOR/4095 (with Vref= 3.3 and DOR = 0x05DB = 1499), I don't find the value I have on the oscillo. What am I doing wrong?
EDIT: I think the formula I was using shows the instant value, while I first thought it was the amplitude. So ok. 
Anyway, I put 1023 as triangle amplitude, and 0xF00 (an arbitrary high value) for data, and I have now Ampl = 1.84 V and Freq = 137 Hz. And the waveform alternates now triangles and squares, like that:
   _    _    _    _    _
/\|  |/\|  |/\|  |/\|  |/\|  |

- Finally, what are datas in DAC? Setting a value too high makes my waveform going crazy, but that aside... I don't see the role of that parameter, or how it affects the result.

Thank you.

Outcomes