Image

Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Measuring the peak voltage of a 1 kHz PWM/square wave using ESP32 ADC without peak detector

+1
−0

I need to measure the positive peak of a 1 kHz PWM/square wave using an ESP32 ADC. The waveform has variable duty cycle; the minimum positive pulse width is about 100 µs.

After scaling, the ADC input positive levels are approximately 2.2 V, 1.65 V, 0.68 V, and 0.30 V.

I only need to classify these levels, not measure with high precision. Can I sample the ADC at 20–50 kHz and take the maximum value over several PWM cycles, or should I convert the waveform to DC using a peak detector/sample-hold before the ADC?

I want to avoid unnecessary analog peak-detection hardware if firmware-based sampling is reliable enough.

History

1 comment thread

Oscilloscope shot of your square wave (1 comment)

1 answer

+1
−0

Doing peak-detection in firmware is a valid method. I have done similar things.

At the bare minimum, you want at least one sample guaranteed within the 100 µs pulse width. That means 100 µs sample period, which is 10 kHz sample rate.

However, you also have to take the acquisition time before each conversion into account. The signal is not point-sampled, but acquired over a finite interval. The overall sample rate needs to be fast enough so that there is always at least one whole acquisition interval in every 100 µs.

For example, let's say the acquisition time is 10 µs. That would require a sample period of 90 µs absolute maximum, which is a sample rate of 11.1 kHz.

In reality, I'd want two whole guaranteed samples over the minimum 100 µs period. That way at least one of them isn't near an edge. Using the 10 µs acquisition time example again, that leaves 45 µs for each sample, for a sample rate of 22 kHz. Fortunately, that seems to be well within the capability of your A/D, so the digital peak detection method should work fine given what you have told us.

History

0 comment threads

Sign up to answer this question »