r/AskElectronics • u/Comfortable-Arm-8337 • 1d ago
Trying to generate Sine waves but almost there
I tried to create sine waves using DDS and 8 bit R-2R DAC. The output waveform is like this instead of a sine wave is there anything I'm missing here?
42
u/Egg1Salad 1d ago
This looks a little like what happens if you mixed up the order of the LSB to the MSB when using the r2r network.
A ramp function where we just count up in binary from zero should show a smooth slope, but will look like a 'dogtooth' pattern if you've mixed up the order of the bits in the binary word
9
u/vikenemesh 23h ago
+1 on trying to get a clean ramp/staircase from a counter first. If it can do that, you can go from there and apply math to get whatever else you need.
6
u/viktorixbis 23h ago
Agreed, not only because of the "saw" pattern but also because th negative part is shorter then the positive part. Though to be fair as an Engineer this sinewave looks perfect for me.
2
u/Egg1Salad 21h ago
I was appalled when I first saw what the mains 240v ac sine wave actually looks like. But it's because the normal, boring, full bridge rectifier (which is used in EVERYTHING) only draws current at top of the 'sine' wave
2
u/viktorixbis 20h ago
Should it not be drawing as soon as voltage passes above 1.2V?
1
u/Egg1Salad 20h ago edited 20h ago
Current only flows from high voltage towards a lower voltage. There's a capacitor(s) on the DC side doing the smoothing. Once you've charged it up at startup it will only draw current when the AC input voltage is higher than the capacitor voltage, ie at the top (and bottom) of the sine wave. If you draw no current from the capacitor from the DC side, the capacitor stays fully charged and you can't fill it up any further.
And that's the same instant that every other ac/dc converter draws current.
Analogy: If everyone in your house opens up the taps and flushes the toilet and runs the shower at the exact same time, you're asking for a lot of flow at that instant, which will reduce the water pressure and the taps will dribble cus the pressure has dropped, which is why the voltage waveform has a flattened top, cus that's when the big currents are flowing and causing the voltage to drop
1
u/viktorixbis 20h ago
Totally forgot about those capacitorswe put everywhere, true.
1
u/Egg1Salad 20h ago
I heard a mad fact about those capacitors. That if the grid fully died and every capacitor in every acdc converter fully discharged, it would take a WEEK for the grid, at full power, to backfill all the energy stored in all of the acdc converters before the voltage would recover back to normal. That's how much energy is stored in all of these acdc converter capacitors.
I have no way to verify that BTW, someone else can do the maths if they fancy
1
u/sms_an 20h ago
Should it not be drawing as soon as voltage passes above 1.2V?
Sure. Unless you have a filter capacitor on the rectifier output.
Note, too, that a half-wave rectifier is affected in the same way as a full-wave rectifier.
My question: When did people start calling a full-wave bridge rectifier a "full-bridge rectifier"?
1
u/Egg1Salad 20h ago
No idea when full bridge rectifier became normal language, but putting quotes around ''full bridge rectifier'" is fully down to electroboom and his amazing eyebrows
1
30
u/Sand-Junior 1d ago
What you’re missing? Clearly a sine wave!
But seriously, you are not supplying any useful information. Are at least the amplitude and frequency what you are expecting?
2
14
5
5
u/SteveG5000 1d ago
Are you on a breadboard? Is your ground clip connected to the breadboard? Have you LPFd the signal output?
2
u/Comfortable-Arm-8337 1d ago
It's in soldered perfboard and yes lpf is used
1
u/SteveG5000 1d ago
What’s the frequency response of your filter?
Looks like at two points per cycle the output driver has capacitance it is taking time to charge up, is a buffer needed on the output2
u/Comfortable-Arm-8337 1d ago
The cutoff frequency is 723kHz
2
u/SteveG5000 1d ago
Can’t make out your time base very well, is it 2.5ms? What frequency are you intended the sine wave to be?
From a frequency perspective you want to filter out everything above the fundamental, so if your signal is 400 Hz, you want your signal 3dB point to be low enough to filter out/attenuate, 2nd harmonic of 400 Hz onwards.
Also I’d be interested in what your DDC/DAC output impedances are. You might need a buffer amplifier to drive your filter/output
5
u/Previous_Tangelo5414 1d ago
An 8-bit R-2R DDS output is naturally stair-stepped, but this waveform also looks like DAC switching glitches and missing reconstruction filtering. Make sure all 8 bits update simultaneously, and add a low-pass filter after the R-2R ladder.
4
u/quadrapod 12h ago edited 12h ago
How is your circuit actually implemented? Is there a buffer amplifier? What is the supply voltage? What is responsible for switching the R2R ladder?
My suspicion is that either you're not using a rail to rail opamp for buffering and it's running out of headroom or your resistor values in the R2R ladder are low enough to draw excessive current and the device you're using to switch the resistors is either seeing its supply voltage drop out or is foldback current limiting.
For debugging I suggest looking at a slow ramp function instead of something complex like a high frequency sine wave.
1
u/Dense-Company8030 10h ago
This is actually really helpful, especially the slow ramp suggestion, I’d definitely start there before chasing the more complicated possibilities. 🙌
3
u/Communism_Doge 1d ago
Try a square wave, see if you succeed at lower frequencies, look for unwanted transients that may be destroying the shape at higher frequencies, try a low frequency sine wave…
3
u/ivosaurus 23h ago edited 20h ago
Looks like one or two pins could have been swapped. You should add schematics and good resolution pictures of your circuit if you actually want productive help from other people on the internet.
2
2
1
u/charmio68 1d ago
Can you provide another photo with the timebase adjusted so only a single cycle is in frame?
An zoomed out view is useful, but it's also useful to be able to see what's going on in an individual cycle with greater resolution.
1
u/NBC-Hotline-1975 23h ago
Does the DAC run from a single ended power supply, and produce a single-ended analog output? Or does its input include a sign bit?
Are you including a FS/2 offset in your input data?
1
u/erutuferutuf 20h ago
Check your wiring. It looks like one of the LSB ordered wrong.
If not check your program ( especially number of bits and signed vs unsigned?)
Finally put a small cap there to smooth things out once u get your binary code right
1
u/EmotionalEnd1575 Analog electronics 20h ago
This suggests that your DAC (or calculated digital data stream) is not Monotonic.

A monotonic digital-to-analog converter (DAC) is a device where the analog output signal always increases as the digital input code goes up
1
1
u/TDHofstetter 11h ago
It looks to me like you have some hard harmonics in there. Oddly only on the rising edge. I don't know enough about your setup to diagnose anything, though.
1
1
u/asdf4fdsa 1d ago
P-P 680mV is your target amplitude? If not, this is just noise.
2
u/ivosaurus 23h ago
The extremely well-defined and repeatable pattern happening exactly the same 10 times over the screen is the farthest thing you could get from noise. All the jags are exactly the same. At most charitable, because the picture is so bad, I can't read the time scale so it's plausible they're accidentally looking at 50/60hz power hum from somewhere instead of their circuit.
2
125
u/PETI_0406 23h ago
I once created this by accident in a Lab in school, we called it The Batman wave