2017-07-09 10:49 PM
Hello
I want to generate a 50Hz stable sine wave which I will amplify in order to obtain AC and DC voltage and current.
The strategy is to generate the sine wave using DAC or PWM. I used one STM32 MCU with two DAC outputs....the MCU is supplied from a 2.5V voltage reference 0.24% accuracy because I want the sine wave to have an amplitude as constant as possible...
So far I get a sine wave with very poor performances (for example an amplitude of 1.27V with +/- 2% )...by both methodes (DAC and PWM) I guess this is due to internal DAC and timer errors...
Do you have any tips (software , hardware) in order to obtain a more stable sine wave?
#sine-waveform2017-07-09 11:34 PM
I never had sub-percent accuracy requirements when using the DAC, but a few things come to my mind.
First, which part you are using ?
A separate supply pin for analog peripherals (VDDA) would be essential. Not every variant has one.
Second, even with a separate supply, analog peripherals on high-frequency clocked digital circuitry are always a compromise. Check the DAC section of the datasheet for a realistically achievable accuracy.
The relatively high offset and temperature drift of the DAC with enabled output buffer is known.
2017-07-10 05:02 AM
Look at the schematics of a discovery board using DAC/PWM.
Start using a simple 3.3V supply for everything first. If the STM32 uses USB function, the supply must be >2.7V.
Some STM32 have various decoupled supply voltages. Read carefully the datasheet for the supply voltages and range.
If both PWM and DAC are clamped at 1.27V there is something so obvious on the HW side that it's probably an overseen bug.
2017-07-10 05:20 AM
MCU:STM32F103RFT6
The MCU job is just to generate the sine signal (DAC or PWM), it does nothing else, that is why i connected both VDD and VDDA to the precise 2.5V reference ; the current consumption is small enough ; yes I have the buffer enabled.
Should I read back the sine wave in order to implement a PID regulator?
2017-07-10 05:57 AM
Not sure what 2.5V reference you are using, but I'm pretty sure they are not intended for supply purposes.
Control dynamics play an important role as well.
And connecting the reference to both VDD and VDDA defeats it's purpose IMHO.
One of the rationales of a separate VDDA is a decoupling from VDD with it's drastic load changes, and the consequent voltage ripples.
Have you considered an external DAC ?
2017-07-10 09:07 AM
I intended to keep the current consumption of MCU small enough so the reference can fed it...
Anyway I dropped the DAC idea and I have returned to PWM so VDDA -VDD issue does not matter anymore.
I want to keep the system as simple as possible so I don't want to use external DAC (I want to explore and find other ways, if they exist)
Analysing the produced sine wave I observed it varies under 1.18 V RMS and 1.08VRSM , what is curious is that the variation (that 0.1V) is sinusoidal
2017-07-10 10:18 PM
I intended to keep the current consumption of MCU small enough so the reference can fed it...The reference gives 5mA. I cheked it, the voltage does not drop under load
Anyway I dropped the DAC idea and I have returned to PWM so VDDA -VDD issue does not matter anymore.
I want to keep the system as simple as possible so I don't want to use external DAC (I want to explore and find other ways, if they exist)
Analysing the produced sine wave I observed it varies under 1.18 V RMS and 1.08VRSM , what is curious is that the variation (that 0.1V) is sinusoidal .(rectified sinusoidal wave).
I will try to calibrate the internal clock, if nothing gets better, then I will use an external one.
2017-07-11 12:29 AM
With PWM you will IMHO have a hard time to come close to the accuracy of the internal DAC.
I intended to keep the current consumption of MCU small enough so the reference can fed it...The reference gives 5mA. I cheked it, the voltage does not drop under load
The problem is the dynamic behavior. How does your reference source react on drastic load changes (load regulation) ?
You need a scope to check VDD, for ripples in the millisecond and sub-millisecond range.
2017-07-11 04:01 AM
You might be getting some interference from 'mains hum'. There is a *lot* of it about, particularly if you have 'loops' - where the signal wire can take a different path from the earth wire; you effectively have a single-turn transformer which converts any mains magnetic field (from a power-supply, fluorescent lamp ballast or whatever) into a voltage induced between signal and ground.
What you could be seeing is the 'beating' of your intended 50 Hz and the local mains frequency (which in many parts of the world is 50 Hz). Neither the frequency you generate nor the mains is exactly 50 Hz, so they will drift in and out of phase.
It could be that you made an earth loop with your voltage-reference, so this has mains hum on it.
You might do better if you use screened wire for your signal and pay close attention to earthing. Or you could adopt differential drive from your microcontroller board to whatever amplifier you use.
Hope this helps,
Danish
2017-07-11 08:49 AM
I have a scope. Also a 220uF on VDD line. The reference is surprisingly good: +/- 0.1mV measured with a precise DMM.
I gave up on the DAC because my feeling was it is harder to obtain accuracy with DAC given that it uses current, instead with PWM there are less errors because there is no analog thing involved (just a feeling)