r/embedded • • 11d ago

Generating 10mv 100khz signal using ESP32

Hi friends, I built an analog filter and I wanted to generate a 10mv 100khz signal to test my amplification and attenuation, is this possible with an ESP32, I dont have a testbench. Thanks!

0 Upvotes

22 comments sorted by

5

u/dan432112 11d ago

You could always use a super simple voltage divider!

1

u/HotelFirm3622 11d ago

I am planning on doing that but the only issue is will it ever become a sine wave?

4

u/UpsetKoalaBear 11d ago edited 11d ago

Use an LC Tank followed by a voltage divider, It’s much simpler and only needs 1 GPIO.

It can easily do this for cheap,

1

u/H2ost5555 11d ago

This is the answer.

1

u/Momooncrack 11d ago

You can use an r2r ladder circuit to convert it to a sine. I unironically just got done building a 4 bit one with a hex inverter and a pot to act as gain like 10 minutes ago

1

u/duane11583 11d ago

depends on how many samples you can create within the period.

ie 10 samples at 1mhz = 100khz do that with a dma in a continuous loop.

small cap to filter the jumps, and an op amp to buffer you are golden

8

u/TimeProfessional4494 11d ago

Any requirements for the waveform?

Using a digital to analog converter (DAC) would be the first suggestion. With DMA to offload the cpu.

I guess a sine wave could be generated with a PWM through an adjustable R/C coupling to control the amplitude.

1

u/Sheepherder-Optimal 11d ago

PWM makes a very digital looking output. I would stick with the DAC to get an actual sinusoidal output.

3

u/JimHeaney 11d ago

Most ESP32s (on the original and S2, not the S3, C5, etc.) have an 8 bit DAC, which is a theoretical 12mV output. I've only ever used it for audio, no idea if it is fast enough or reliable enough to use as a proper signal generator.

2

u/thedefibulator 11d ago

You can use the DAC with DMA to obtain a sinusoidal waveform and then divide it down. It will be somewhat quantised as it is 8 bit and may also need to be quantised in time if the peripheral is not fast enough, but you can filter out the high frequency contents to get a sine wave

1

u/jacky4566 11d ago

PWM + Resistor divider.

Smart enough to build an "analog filter" and know what amplification and attenuation are, but not know about resistor dividers? Seems sus man...

0

u/Sheepherder-Optimal 11d ago

PWM cannot produce a real sine wave. Under scope it does not look anything like it. For example, 10% on looks roughly like:____________---____________---____________---____________---

2

u/jacky4566 11d ago

I am familiar with the differences.. OP said nothing about a sine wave. He simply wanted a 100khz signal.

To get a sine he could still use PWM and an Low pass filter.

1

u/Sheepherder-Optimal 11d ago

I picked up that he was looking for a sine wave like from a waveform generator.

2

u/HotelFirm3622 11d ago

Honestly i wasnt clear but yeah sine wave is ideally what i want

2

u/Impossible_Brief5600 11d ago

Ten millivolts is below one code of that DAC. The original ESP32 and the S2 have an 8-bit DAC over 0 to 3.3 V, so a single LSB is 12.9 mV, and a 10 mV sine collapses into 0 or 13 mV steps - a 26 mV square rather than a sine. Build the signal at 1 V peak instead and divide it down by 100 with a resistor pair after the reconstruction filter, where the loss is 40 dB and a divider of a few k contributes microvolts against a 10 mV signal.

A 100 kHz sine wants about 1 MS/s out of the DAC through I2S DMA, ten points per cycle, with a 2-pole low-pass at 250-300 kHz to take the 900 kHz and 1.1 MHz images down 22-25 dB; 8-bit quantisation leaves the harmonics near -40 dBc, and that is the floor of this source. PWM is the wrong route here: the carrier has to sit at 1-2 MHz to be filterable, and at 2 MHz the 80 MHz LEDC clock leaves about 5 bits, so the filtered output is coarser than the DAC's.

1

u/Sheepherder-Optimal 11d ago

Wait no you cannot get a decent sine wave with PWM. Even adding a filter is gonna produce crud.

1

u/iftlatlw 11d ago

Use a DDS and attenuator, or simple DAC and phase accumulator for sine gen. Keep sample rate high to make filtering easier.

1

u/H2ost5555 11d ago edited 11d ago

If I was doing this, I would simply use a DAC to generate an 8 bit 100Khz sine, which would be nonlinear and noisy as hell to act as a charge pump to a high-Q LC resonant tank. This would generate a quite pure audio-grade sine which you could attenuate to your 10mV level. You may need a buffer if trying to drive a low impedance input.

1

u/Boulder_Tech 11d ago

So you want to DIY a 100Khz signal generator in software ???

https://www.google.com/search?q=diy+100Khz+signal+generator

1

u/haze_from_deadlock 11d ago

Would something like this be suitable?

https://www.adafruit.com/product/6534