Square Waveform Voltage and Frequency detection

Thread Starter

Ubermensch

Joined Oct 8, 2025
4
I have a square waveform with Positive Voltage of 17.5V and Negative Voltage of 3V with a Switching frequency of 40kHz and duty cycle of 0.5
This waveform is intended to drive a MOSFET.
But before connecting to MOSFETs in production line, I want to check the driver board for Positive voltage, Negative voltage, Switching Frequency.
I am thinking to use Peak detector to detect Positive and negative peaks. And Zero Crossing detector for Switching Frequency.
Is there any other methodology to detect same before connecting MOSFETs ?
 

MrAl

Joined Jun 17, 2014
13,689
I have a square waveform with Positive Voltage of 17.5V and Negative Voltage of 3V with a Switching frequency of 40kHz and duty cycle of 0.5
This waveform is intended to drive a MOSFET.
But before connecting to MOSFETs in production line, I want to check the driver board for Positive voltage, Negative voltage, Switching Frequency.
I am thinking to use Peak detector to detect Positive and negative peaks. And Zero Crossing detector for Switching Frequency.
Is there any other methodology to detect same before connecting MOSFETs ?
Hi,

An oscilloscope it good for this if it does not have to be automated.

If automated, your peak detectors are not too bad of an idea with zero crossing detection. You may want to use a light RC LP filter with it too to reduce false readings if there is an unusual transition between high and low levels.

A modern approach would be to use a microcontroller with ADC.
 

Thread Starter

Ubermensch

Joined Oct 8, 2025
4
Hi,

An oscilloscope it good for this if it does not have to be automated.

If automated, your peak detectors are not too bad of an idea with zero crossing detection. You may want to use a light RC LP filter with it too to reduce false readings if there is an unusual transition between high and low levels.

A modern approach would be to use a microcontroller with ADC.

Have you come across any standard implemented circuit which can detect both Positive and negative peaks ?
 

MrAl

Joined Jun 17, 2014
13,689
Have you come across any standard implemented circuit which can detect both Positive and negative peaks ?
Hi,

A standard peak detector circuit can detect a peak, and to detect a negative peak you would just use a second peak detector.
Typically a diode and capacitor and resistor for a peak detector, and what you want to do with it after that would tell us what the rest of the circuit would look like. For example, and ADC to measure the voltages.

Peak detectors like that work best when the peaks are repetitive, I am not sure if the peaks you are talking about repeat for several cycles.
 

Thread Starter

Ubermensch

Joined Oct 8, 2025
4
Hi,

A standard peak detector circuit can detect a peak, and to detect a negative peak you would just use a second peak detector.
Typically a diode and capacitor and resistor for a peak detector, and what you want to do with it after that would tell us what the rest of the circuit would look like. For example, and ADC to measure the voltages.

Peak detectors like that work best when the peaks are repetitive, I am not sure if the peaks you are talking about repeat for several cycles.
HI MrAI

Yes, the Square waveform is repetitive with 18V as Positive and 3.3V as Negative. And Switching Frequency of 40kHz duty 50% .
I need to display the voltages, fs with typical 7 Segment display for the operator to read after circuit detects it. Can I use attached circuit for peak detection? Or is there simpler circuit? And for Switching frequency detection Can I use Zero crossing detector?
 

Attachments

MisterBill2

Joined Jan 23, 2018
27,374
If this is for a production line test of an actual product then automated ACCEPT/REJECT testing will be needed to avoid operator errors. That is the sort of system that many years of my career were involved with.

"Window" sensors for both of the peak detectors, as well as the frequency counter are what you need. The operator will still need to do the other portion, the visual inspection.
 

panic mode

Joined Oct 10, 2011
4,949
the simplest circuit is digital using MCU. all you need is voltage divider. you can measure voltage continuously and in software determine peaks and frequency. same can be used to drive mentioned 7-segment displays (or a single LCD/OLED or character display)
 

schmitt trigger

Joined Jul 12, 2010
2,056
@Ubermensch
Do you require a solution, or do you want a circuit?

Two different approaches. Myself, I would opt for a hardware-ready solution. There are many low cost scopes with LAN, USB even Bluetooth, which you can connect to any low cost computer, which can be set to automatically pass/fail criteria and also log the values if desired.
 
Last edited:

MrAl

Joined Jun 17, 2014
13,689
HI MrAI

Yes, the Square waveform is repetitive with 18V as Positive and 3.3V as Negative. And Switching Frequency of 40kHz duty 50% .
I need to display the voltages, fs with typical 7 Segment display for the operator to read after circuit detects it. Can I use attached circuit for peak detection? Or is there simpler circuit? And for Switching frequency detection Can I use Zero crossing detector?
Do you need to display something like 17.8v and say -3.21v, or do you just have to acknowledge that they are within range?

If you intend to drive 7 segment displays then you are better off with a microcontroller.
It depends how you are going to approach that part of it though. If you are buying a ready-made voltmeter or two voltmeters that's different.

There are a lot of ways of approaching this so you might want to elaborate on what it is you can and cannot do with the implementation.

The simplest peak detector is a resistor in series with a diode, the diode in series with the capacitor, the output taken from across the capacitor, the input at the free end of the resistor. I'm not sure how perfect you want this to be either. If you need super good accuracy then you may want to use an op amp, but it has to be able to work with the frequency you need.
 

MisterBill2

Joined Jan 23, 2018
27,374
It is a lot simpler to use separate circuit modules for each of the peak detection segments BECAUSE then there is no compromise, and o mystery software to fight with. And no need to have the typical not quite linear A/D scheme to fight with calibrating. When accuracy and stability are more important than being state of the art and super compact, a separate circuit for each parameter can be verified and not need any compromise. AND, when one variable is changed, adjusting will not affect sensing of the others.
 

Thread Starter

Ubermensch

Joined Oct 8, 2025
4
It is a lot simpler to use separate circuit modules for each of the peak detection segments BECAUSE then there is no compromise, and o mystery software to fight with. And no need to have the typical not quite linear A/D scheme to fight with calibrating. When accuracy and stability are more important than being state of the art and super compact, a separate circuit for each parameter can be verified and not need any compromise. AND, when one variable is changed, adjusting will not affect sensing of the others.
What do you mean by Window Sensors? My requirement is that after peak detector detects the value I need to give it to ADC and uC needs to decide on Pass/Fail criterion
 

panic mode

Joined Oct 10, 2011
4,949
and what is stopping you from doing just that?

there are different ways to approach the problem. all of them have good and bad sides...

you can use simple peak detectors and zener clamping to condition signal to something MCU may use. simplicity is simple and easy but it has downside that captured value differs slightly due to diode non-ideal characteristic. depending on chosen values that means result may be off 30-100mV. one may try compensating for that in code as well. advantage is you do not have to worry about ADC conversion rates etc.

you can practically eliminate that issue by using more complex circuit that behaves like an ideal diode but you loose simplicity and testing/troubleshooting potential problems gets a bit harder.

or you can use sample and hold circuit...

or you can do it pretty much all in software if your chosen MCU and programming language can keep up. 40kHz may not be much but it is something that built in ADCs may not be able to keep up with.

so far you did not tell us much... that includeswhat are your tolerances or Pass/Fail criteria. what voltage levels your MCU uses, what is ADC conversion speed is, how many ADCs you have, what resolution etc.

here is the simple circuit. notice that obtained peak values V(pos) and V(neg) do get close but not exactly to actual peak values.
1760031731927.png
 

MisterBill2

Joined Jan 23, 2018
27,374
A "window sensor" is a circuit that delivers an output when a monitored voltage enters a "window" between two voltage levels. Often it is composed of two comparators and a means of setting those two voltage levels as references. It may also include amplifiers and even track and hold circuits, or even an A/D converter and a digital data latch.

In this application it would include both a peak latching A/D converter and a comparator to signal that the analog input signal had reached some level but not exceeded a second level. The benefit of using such a circuit as a module is that a spare unit can be calibrated off-line and available for immediate installation if the specification should change, or a failure occur. The accept/reject logic, data recorder, and operator interface can all be separate segments as well. The "window sensor" could even interact with a processor module handling the other functions, if that were a choice, without the lack of flexibility and the logic speed limitations that the tiny logic device imposes. Peak detection, at speed, is somewhat demanding.
 

panic mode

Joined Oct 10, 2011
4,949
btw, i don't see what is so complicated about few lines of code and doing everything in the MCU. here is some pseudo code:

Code:
for (;;){
  n++; // increment counter
  tick_start = GetCurrentMs();
  v = readADC();
  if (v>vMax) vMax=v; // capture peak+
  if (v<vMin) vMin=v; // capture peak-
  if (n>=1000) {
    tick_end = GetCurrentMs();
    period = tick_end-tick_start;
    freq = n/period;
    displayValues();
    // finally reset things to start collecting again    
    n=0;
    vMax=0;
    vMin=0;
  }
 
Last edited:

MisterBill2

Joined Jan 23, 2018
27,374
btw, i don't see what is so complicated about few lines of code and doing everything in the MCU. here is some pseudo code:

Code:
for (;;){
  n++; // increment counter
  tick_start = GetCurrentMs();
  v = readADC();
  if (v>vMax) vMax=v; // capture peak+
  if (v<vMin) vMin=v; // capture peak-
  if (n>=1000) {
    tick_end = GetCurrentMs();
    period = tick_end-tick_start;
    freq = n/period;
    displayValues();
    // finally reset things to start collecting again   
    n=0;
    vMax=0;
    vMin=0;
  }
If you say so!! Not every electronic tech or production line service person is skilled in whatever language that is. Nor would they be able to adjust it or diagnose any problem.
 

ronsimpson

Joined Oct 7, 2019
4,664
For factory work: I once made testers that sided too much.
Example: +peak= 17.503V , -Peak=3.011V Frequency= 40,032.8Hz
This is good for engineering. Bad for production.
Now I make test boxes that simple have a Red light and a Green light. There must be a Red bucket and a Green bucket to put the product into. Never underestimate the uneducated production workers.
 

MisterBill2

Joined Jan 23, 2018
27,374
For factory work: I once made testers that sided too much.
Example: +peak= 17.503V , -Peak=3.011V Frequency= 40,032.8Hz
This is good for engineering. Bad for production.
Now I make test boxes that simple have a Red light and a Green light. There must be a Red bucket and a Green bucket to put the product into. Never underestimate the uneducated production workers.
CERTAINLY!! The system must measure accurately, and the result is either green-light or red-light.
I designed many of those machines.
They ALSO DISPLAYED RESULTS, because that is how the responsible people can verify that they are still working as they should. AND that is how the manufacturing folks can spot trends!!!
If you can not see where you are heading it is difficult to stay on the right path.
 
Top