cancel
Showing results for 
Search instead for 
Did you mean: 

Sine wave stability

ionutF
Associate III
Posted on July 10, 2017 at 07:49

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-waveform
17 REPLIES 17
Posted on July 11, 2017 at 15:50

Yes. I considered that. I powered the thing from a battery in order to avoid mains hum. 

Posted on July 11, 2017 at 16:17

The STM32 DAC implementation outputs a voltage (when observing proper impedances).

To create a proper analog signal from PWM, you need a PWM frequency of usually about two orders of magnitude higher than the signal frequency, and appropriate low-pass filters.

IMHO your accuracy requirements are easier to fulfill with a DAC.

But if you have time, try both. In the worst case, you learn something.

Posted on July 13, 2017 at 12:13

I must be mssing something.  You cannot generate a sine wave from PWM without post-filtering, and a filter is an 'analog thing', is it not?

AVI-crak
Senior
Posted on July 16, 2017 at 19:34

The input impedance of the amplifier should be more than 100K.

Additionally - a low-pass filter (RC enough) must be used, with a cutoff frequency three times lower than the sampling rate. In the case where the RC circuit is between the DAC and the op amp - the resistance of the resistor should be 100K or more.

Amplifier with an input resistance of more than 10MΩ. Using a standard op-amp has limitations, it should not be overloaded !!! It is acceptable to use the op-amp as a single buffer - with the Rail-to-Rail technology for 3.3V power supply.

Additionally.

The DAC module has a nonlinear dynamic distortion dependence on the current vector at the repeater input. The rate of voltage rise from the midpoint to the top or bottom is noticeably lower than the rate of voltage drop from the extreme points to the mean. The static voltage has a smaller deviation, but there are more distortions in the dynamics.

This kind of distortion is easiest to eliminate with a simple 1-20 MΩ resistor (pick up) - between the chip leg and the midpoint (enough R-R divider).

Distortions at the most extreme points of the output range can not be eliminated. Output is a limitation of 6% of the range.

And probably the most important thing is that the signal quality can be achieved in two ways: by increasing the bit density of the DAC, and by increasing the sampling rate.

Posted on July 16, 2017 at 18:39

Yes, I have filters; and they are analog , but because they are external  I can control these filters, the DAC is internal to the MCU and not so much configurable. 

Anyway , through some series of experiments, indeed PWM performance regarding the stability of sine wave is poorer that the performances obtained if I use the DAC (+/- 100mV with PWM and +/-35mV with the DAC).

The next thing I will try to do is to calibrate the sys clock, perhaps use  an external  precise clock.

Also the experiences confirmed what AvaTar said, the dynamic behaviour is the problem: if I output a constant duty cycle PWM or a constant voltage on DAC, the amplitude of that voltage is very stable +/- 0.5..1 mV  deviation from setpoint.

Posted on July 17, 2017 at 09:25

My suggestion would be to design/use a proper external output amplifier for the DAC. Non-buffered mode should give you better results than +- 35mV, provided you are using an adequate design. The 1 MOhm output impedance of the DAC is a bit of a challenge - an instrumentation amplifier is probably be helpful here.

A 50 Hz signal is far from the DAC bandwidth limits. With slew rates of a few microseconds per step, you could easily update the DAC at 500 Hz or 5 kHz.

I had (private) application with 100 kHz output rate and more. However, I was not too concerned about absolute accuracy in this cases.

Posted on July 17, 2017 at 13:12

But the magnetic field given off by mains-powered devices and power cables will induce voltages on any wiring loops you have in your circuit even if it is electrically isolated.

How might you test to see if mains hum is your problem?

 - Lock your signal generation to local mains (need to inject the mains in, then have a software phase-locked-loop to adjust your nominal-50Hz)

 - Generate something other than 50 Hz e.g. 60 Hz or 75 Hz. (If you have analog filters tuned for 50 Hz they might need changing, but if they're low-pass you should be fine)

 - Do the entire test far away from any source of mains including power-lines; out in a field or the car-park, using battery-powered test equipment

 - See how the level of beating changes as you wind your amplitude up and down at the DAC

ionutF
Associate III
Posted on August 01, 2017 at 14:34

I have used another board (TI) to generate a  sinusoidal PWM, I managed to obtain 0.1% amplitude stability just with a simple MCU , no battery (powered from EV board supply), no high precision voltage reference. Still that it is far from what I want. 

0.1% means +/- 3.3 mV from a 3.3V supply, I need maximum +/- 1mV 0.03% (ideally +/- 0.5 mV)

What was curious is that when I fed the TI MCU from that 2.495 high accuracy voltage reference, the sine wave stability went to +/- 30..40mV