2025-01-20 12:12 PM
Hi,
I've successfully generated a sine wave using stm32 DAC. The current generated sine wave has the following properties; where min amplitude is 0 to max amplitude 4096 and the zero crossing is at 2048. I'd like to shift the output sine wave amplitude to where min amplitude -2048 to max amplitude 2048 and zero crossing is at 0. Are there any registers or methods i can use to achieve this task?
Best Regards,
Vu
2025-01-20 01:39 PM
There are ways to get a zero-balanced output voltage - but not with an MCU that only has a positive supply voltage.
Let's think about this: your DAC output ranges from 0...4095 (not 4096, because zero also is one step), which corresponds to a full voltage swing, e.g. 0...3.3V. In order to shift the range by 2048 in the negative direction, you would have to be able to output a negative voltage - but where would this come from?
For this reason, there are electronic circuits such as a level shifter with an opamp that can achieve your goal using a simple differential amplifier, which can be found, for example, in the Wikipedia article on the topic opamp applications.
Hope that helps?
Regards
/Peter
2025-01-28 11:44 AM
Hi Peter,
Thanks for the insights. I came from the TI MSP430 uC, where the DAC supports both straight-binary and twos-complement data formats. In twos-complement data format, the range is shifted so that a DAC value of 0x0800 results in a zero output voltage, 0x0000 is the mid-scale output voltage, and 0x07FF is the full-scale voltage output. The offset voltage of the DAC output amplifier can be positive or negative.
Thanks,
Vu
2025-01-29 01:07 AM
Ah, now I've understood what you mean. However, the DAC has straight binary with left or right alignment. The MSP430 is still a 16-bit RISC with a rather low clock frequency, which is why a lot was still done in hardware. With the considerably more powerful STM32, however, you can easily convert two's complement to straight binary before passing it on to the DAC or the DMA buffer.
Regards
/Peter
2025-01-29 01:47 AM - edited 2025-01-29 01:51 AM
Hi,
the DAC itself alsways can only convert 0...0xFFF . ok ?
So you want to get the "zero data point " mid-scale , thats called "offset binary" and you can easy do it:
just invert the MSB (most left/upper bit) :
zero data: 0x0 -> 0x800 (at the DAC); -2048: 0x800 -> =x000; etc.
Invert the MSB, thats it, to use DAC with +/- values..