Back to timeline
school Apr 2024

A signal-level generator with an ESP32

Designprosjekt 1 in NTNU's electronic-systems design course. The brief: take an analog sinusoidal input X₁(t) and produce an output X₂(t) = A·X₁(t), where A is set by a knob the user can turn. The whole gain control runs through an ESP32 in the middle of the chain: analog in, analog back out, software in between.

The pipeline

Block diagram of the signal-level generator. Input 75 mV → LM741 22× amp → 1650 mV bipolar → level shift to 0–3.3 V → ESP32 ADC + DAC controlled by a potentiometer → output.
Full chain. LM741 to push the signal into the ADC window, ESP32 multiplies sample × pot, DAC reconstructs the output.

Numbers

The hot loop is a single line, intentionally:

void loop() {
  dacWrite(25, ((int)analogRead(35) * (int)analogRead(potPin)) >> 16);
}

Casting to int32 before the multiply, then bit-shifting 16 places, keeps the result in the DAC's 0–255 range without paying for a division. The whole thing runs as fast as the ADC will allow.

Detailed schematic showing the LM741 amplifier wiring, 22k and 20k feedback resistors, ESP32 power rails, and the potentiometer on pin 13.
Final wiring. LM741 around 22k/20k feedback, ESP32 ADC on the bipolar-shifted output, pot into pin 13.
The breadboard build: ESP32, op-amp, potentiometer, and a Digilent Analog Discovery cable.
Bench build. ESP32, LM741, potentiometer, Digilent Analog Discovery feeding the input.

Where it falls down, and the next step

At very low gain the DAC's quantisation dominates, and the output looks like a staircase between 0 and 6.47 mV. A passive smoothing stage on the output would clean that up considerably; that is the obvious next iteration.

Oscilloscope: smooth orange input sinusoid; blue DAC reconstruction follows it closely but with visible staircase steps at the peaks.
Mid-gain output. DAC steps are visible at the peaks but the shape tracks.
Same scope view at low gain: the DAC output is a coarse staircase oscillating between just a few quantisation levels.
Low-gain output, where staircase quantisation dominates. Passive smoothing on the output is the obvious next iteration.

Writeup

Back to timeline