Skip to content

Instantly share code, notes, and snippets.

@ericfont
Created November 28, 2025 02:05
Show Gist options
  • Select an option

  • Save ericfont/a5cbebe84ebf81310eb8503693433d47 to your computer and use it in GitHub Desktop.

Select an option

Save ericfont/a5cbebe84ebf81310eb8503693433d47 to your computer and use it in GitHub Desktop.
with just comparator instead of lowpass opamp
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ericfont
Copy link
Author

sim

not quite as good...
image

So it seems lowpassing at the end helps quite a bit.

@ericfont
Copy link
Author

@ericfont
Copy link
Author

@ericfont
Copy link
Author

image

@ericfont
Copy link
Author

Screencast_20251129_021921.webm

green: original signal
brown: 1st-integral output
blue: 2nd-integral output (which includes a bit of first integral too)
yellow: lowpassed blue

Frequency of oscillations around 70kHz or so...

Todo: try to slew-rate limit the digital Q and Q' signals, so that they are guaranteed to be mostly within the bandwidth of the opamps and so they don't produce extra spikes. Hopefully this will also smooth the output a bit more. See https://www.ti.com/lit/ug/tidu026/tidu026.pdf for one possible method that uses two opamp stages to slew a digital input, though maybe there are simpler ways, such as just passing it through an opamp buffer whose specs have low slew.

@ericfont
Copy link
Author

I notice this particular setup fails at a 20kHz square wave (it just results in a 20kHz square wave for the PWM output).

The trapezia waveform is good for showing how it handles "slope overload" issue of delta modulation:

image

Buecause I'm actually encoding the 2nd derivative (plus a little of the 1st derivative), the resonstruction resembles the shape of a parabola (x^2) since that is the 2nd integral of a step. So as more time goes by the parabola gets steeper and steeper and so can better "catch up" to the occassional faster moving slope.

@ericfont
Copy link
Author

Screencast_20251129_024055.webm

@ericfont
Copy link
Author

Note about using slew limiting with opamp buffers: the MCP6004 is slow at .6 V/us, which means it could at best do around 60Khz for a 5Vpp triangle wave.

@ericfont
Copy link
Author

Note, could use simple RC to slow down the signal...the initial slope would be Vdd/(RC), so for 5V and a 100 ohm resistor and 1nF, would be 50 V/us

It sems 100 ohm and 100pF produces a nice 300 V/us slope:
image

@ericfont
Copy link
Author

that almost gets rid of distortion at the triangle peaks...still looks just a tad peaky, bu tnot much:
image

@ericfont
Copy link
Author

zooming in can see just a little glitch where the peak happens:

image

@ericfont
Copy link
Author

470 pF with 100 ohm seems to remove the peakiness entirely:

image image

one blue spike does seem to be exceeding the rails at the end of the slope...so that might be hittin ghte limit now.

@ericfont
Copy link
Author

actual input signal was offset to high from mid voltage...fixed now...here is 10 kHz sine:

image

@ericfont
Copy link
Author

Unfortunately now can't handle 20 Khz 1V (2Vpp) sine:

image

However, 20 Khz .75V (1.5Vpp) sine is dooable:

image
Screencast_20251129_032834.webm

@ericfont
Copy link
Author

Oscillation is still around 70 kHz. So the 100ohm 470pF RC slewlimiter doesn't seem to cause slowdown of frequency.

@ericfont
Copy link
Author

Single cycle test of 10kHz 2Vpp sine:

image

@ericfont
Copy link
Author

can't seem to center the final output ...it jumps to either rail at a low frequency (like under 20Hz)...can't seem to filter it out. Maybe double integration is too much.

Instead maybe try extra high frequency lowpasses. Eg:

image

where two high freq 159kHz lowpasses overlap to have 180 degree intersect around 140 kHz:

image

which is where the oscillations would occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment