Author Topic: How to reshape this signal into a square wave.  (Read 3479 times)

0 Members and 2 Guests are viewing this topic.

Offline SteveThackery

  • Super Contributor
  • ***
  • Posts: 3270
  • Country: gb
  • 50 year novice
Re: How to reshape this signal into a square wave.
« Reply #50 on: June 30, 2026, 10:12:19 am »
Here's a different idea.. simple in that it doesn't use any current when it's not doing anything.

I've used 100K, 47K and 100pF just as a starting point.  The idea is that each half processes just one edge.  When the input changes rapidly enough to overcome the 100pF and 100K and it's more than 0.66v the output changes state.

It'll work with drifting input and also as long as there is more than 0.66v of change.

How does it latch its state, which is what you'd need to make a square wave?
 

Offline Chris Mr

  • Regular Contributor
  • *
  • Posts: 157
  • Country: gb
  • Where there's a will there's a way
Re: How to reshape this signal into a square wave.
« Reply #51 on: June 30, 2026, 10:58:03 am »
It latches it's state on the 10n.. for a while.. or a 100n if the while is longer..

or you could get rid of the 10n and stick it into a pair of series connected inverters where the output comes back to the input with a resistor to the transistors overcome the resistors and then the resistor does the rest.

That way the mid-point of the two inverters would be the right way up.

There's loads of possibilities!
 
The following users thanked this post: SteveThackery

Offline Chris Mr

  • Regular Contributor
  • *
  • Posts: 157
  • Country: gb
  • Where there's a will there's a way
Re: How to reshape this signal into a square wave.
« Reply #52 on: June 30, 2026, 11:52:07 am »
I'll describe what should happen:

The input is AC coupled to the two transistors so, starting with the PNP at V+ the voltage at the base will end up at V+ as it's being pulled there by the 100K.  When the input pulse goes positive nothing happens at the output because the PNP doesn't turn on, it's base goes even higher!.. but when the input pulse goes low, as long as the 100pF and 4K7 allow it, the base will turn on and so the output will go high and the 10n will be charged.

On the lower NPN side the base will average to 0v.  When the input goes low nothing happens but when it goes high the NPN turns on and  the output goes low, discharging the 10n.

Now, if you've tried it then just look at the base voltage.  If it doesn't get to 0.7v then increase the value of the 100pF - say 1n or 10n until the output changes.

That time constant, the 100pF and the 4K7, are the differentiation time of the input pulse and is why it will ignore the bounce - so it needs to be picked for the application.
 

Online ledtester

  • Super Contributor
  • ***
  • Posts: 4101
  • Country: us
Re: How to reshape this signal into a square wave.
« Reply #53 on: June 30, 2026, 12:03:45 pm »
LM393N

The circuit in Reply #24 assumes you are using a push-pull comparator. The LM393, however, has an open-collector output. At the very least you'll need a pull-up resistor on the output - I'd try 10k.

Also with a 393 the positive input is close to being outside the common-mode input range. You might bump R11 up to 577k or so.

The "RRIO/PP Comp available for 5V" list show comparators that have push-pull outputs and accept "rail-to-rail" inputs -- ie. the inputs can be anything between the power supply rails (here ground and +5V). By contrast, the inputs to the LM393 should be in the range of 0 to Vcc-1.5V (3.5V in this case.)

We haven't discussed the output impedance of your signal. What exactly is generating your signal?
« Last Edit: June 30, 2026, 12:18:47 pm by ledtester »
 
The following users thanked this post: PCB.Wiz

Offline corgonTopic starter

  • Contributor
  • Posts: 43
  • Country: sk
Re: How to reshape this signal into a square wave.
« Reply #54 on: June 30, 2026, 01:46:42 pm »
OK, I got to this point by using both comparators in an LM393.

The yellow trace represents the start of the pulse, while the purple trace represents the end of the pulse. At the moment, I have two positive-going pulses that effectively track the width of the blue signal.

The next step is to use these two pulses, likely with an RS latch, to generate a clean square-wave output.
 

Offline corgonTopic starter

  • Contributor
  • Posts: 43
  • Country: sk
Re: How to reshape this signal into a square wave.
« Reply #55 on: June 30, 2026, 02:22:05 pm »
Done, it was a fun exercise. Thanks to everyone for the advice and willingness to help.

The blue trace is the input signal, and the cyan trace is the resulting conditioned square wave output.
 

Online Benta

  • Super Contributor
  • ***
  • Posts: 7152
  • Country: de
Re: How to reshape this signal into a square wave.
« Reply #56 on: June 30, 2026, 08:05:57 pm »
I could not replicate the OP's original signal 100%, but that shouldn't make a big difference.
So, I tried replicating your suggested circuit. I used an LM393 and the passive components exactly as shown in the schematic.
However, the result isn't what I expected.

The blue trace is the input signal, and the yellow trace is the comparator output.

No wonder.
If your scope traces are correct, your input signal is at a different level than what you've told us and way outside the LM393 input voltage range.
Also, if you followed my schematic, you'll see that the supply voltage is 3.3 V. The LM393 won't work at that voltage. And even if your supply is 5 V, my first comment applies.
« Last Edit: June 30, 2026, 08:08:54 pm by Benta »
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3302
  • Country: au
Re: How to reshape this signal into a square wave.
« Reply #57 on: June 30, 2026, 09:57:25 pm »
LM393N

Here is a LM393 variant, using a simple web model.
Idle bias point is reduced to allow for the not-rail-rail in, and the Hyst band is recalculated, and resistor values are dropped for higher bias current of LM393



« Last Edit: July 01, 2026, 04:15:52 am by PCB.Wiz »
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3302
  • Country: au
Re: How to reshape this signal into a square wave.
« Reply #58 on: July 01, 2026, 12:21:07 am »
Here's a different idea.. simple in that it doesn't use any current when it's not doing anything.

That certainly has some appeal

or you could get rid of the 10n and stick it into a pair of series connected inverters where the output comes back to the input with a resistor to the transistors overcome the resistors and then the resistor does the rest.

Here is a work-up of that idea, using a pinkeep and with the circuit redrawn to support pre-biased transistors.
You can get PNP & NPN pairs in a single SOT363 package.
The feed-in C needs to be a little larger than 100pF to give enough impulse of overcome the b-e capacitance.
 

Online BillyO

  • Super Contributor
  • ***
  • Posts: 3168
  • Country: ca
Re: How to reshape this signal into a square wave.
« Reply #59 on: July 01, 2026, 05:28:40 pm »
Implemented using a CMOS 555, 3 resistors and a lowly 2N3904.  Two of the resistors and the transistor are needed to invert to output to align the rising edges of output with the positive going pulse.  If this is not required, then you need only the 555 and one resistor to set the control voltage.  Skew between the pulses and the output is 2.6 us.  This also improves if the inverter is not needed.
Bill
----
 

Offline mawyatt

  • Super Contributor
  • ***
  • Posts: 6048
  • Country: us
Re: How to reshape this signal into a square wave.
« Reply #60 on: July 01, 2026, 05:40:53 pm »
Bill,

Nice!!

Can't you just use the 555 discharge output with a 10k pull-up and eliminate the transistor?

Also, with the 555 output and inverter, you could replace the 2N3904 and 10K with just a NMOS (2N7000).

Best
« Last Edit: July 01, 2026, 05:45:04 pm by mawyatt »
Curiosity killed the cat, also depleted my wallet!
~Wyatt Labs by Mike~
 
The following users thanked this post: BillyO

Online BillyO

  • Super Contributor
  • ***
  • Posts: 3168
  • Country: ca
Re: How to reshape this signal into a square wave.
« Reply #61 on: July 01, 2026, 05:42:20 pm »
No, unfortunately.  It turns off when the output is high.
Bill
----
 

Offline mawyatt

  • Super Contributor
  • ***
  • Posts: 6048
  • Country: us
Re: How to reshape this signal into a square wave.
« Reply #62 on: July 01, 2026, 05:48:41 pm »
No, unfortunately.  It turns off when the output is high.

We mentioned using a 10K pull-up to the +5V, so when discharge is "OFF" output is High and when discharge is active it pulls the 10K to ground. You don't use the 555 output nor the 2N3904 and associated resistors and take the output from the 555 discharge.

Best
« Last Edit: July 01, 2026, 05:51:12 pm by mawyatt »
Curiosity killed the cat, also depleted my wallet!
~Wyatt Labs by Mike~
 

Online BillyO

  • Super Contributor
  • ***
  • Posts: 3168
  • Country: ca
Re: How to reshape this signal into a square wave.
« Reply #63 on: July 01, 2026, 05:53:05 pm »
Yes, I tired that.

As mentioned, when the output is high the discharge transistor is off allowing the 10K resistor to V+ to pull the discharge pin high.  When the output is low, the discharge transistor is on, pulling the discharge pin low.  So, output and discharge pin are in phase.  In order to get the rising edge to go high with positive pulse, you need the inverter regardless of if you use pin 3 or pin 7 with a pull-up.
« Last Edit: July 01, 2026, 05:55:49 pm by BillyO »
Bill
----
 
The following users thanked this post: ledtester, mawyatt

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 2247
Re: How to reshape this signal into a square wave.
« Reply #64 on: July 01, 2026, 07:03:00 pm »
Hi,
I'm trying to find the simplest way to convert the signal shown by the blue trace into a square wave while preserving the pulse width "exactly".
The output should go high on the positive edge of the signal and return low on the negative edge, so the pulse width always matches the time between these two edges.
The pulses width is variable, therefore the circuit must accurately track it.
What is the simplest way to achieve this?

Hi,

I like solutions that are guaranteed to work with no question about it.  Here is one that will work along with some notes.

First, I would not use any series capacitors to develop a new signal to work with.  That makes up a high pass filter/differentiator that is subject to noise interference from unknown sources.
Second, I would not use any parallel capacitors except as a low pass filter tuned to pass the required frequencies and reject the higher ones.  A slight amount of input filtering adds reliability, but it can not be too much or it might reject some of the input pulses.  I am not sure if you specified the min and max pulse times and required resulting pulse widths but that would be good to know in order to design the front end correctly.

Third, this can be done with one LM339 and some resistors, and that one capacitor on the front end to reject higher frequency noise.
That IC has four independent comparators that are open collector so you can set the output voltage easily.  There may also be a solution with one of the two comparator versions.

The idea with the LM339 is to form a SET/RESET latch with two sections of the IC, then use the other two to detect the high going input pulse and the low going input pulse.
The reason I suggest this is so that you can set the detect voltages to ANY value, provided they are within the range of the allowed input voltages for the LM339.  This would mean the detect part would need 4 resistors if you want to make adjustment really simple, or 3 resistors if you don't mind a little more complicated adjustment.
The Latch part would require 2 more resistors in order to make two digital inverting amplifiers which when cross coupled forms a set/reset latch.
I'm sure anyone can draw this circuit up in a minute or two.

The advantages are:
1.  Easy to adjust input detect levels if needed.
2.  Easy to filter out unwanted noise.
3.  The technology and circuit have no mysterious sections and is well known.
4.  Output voltage is independent of the input pulse voltages.
5.  Operation is definitive and repeatable.

There is one assumption here:  the input pulses are all ABOVE ground.  If one actually goes negative, we may have to add a diode clamp (like 1N4148).

It would help a lot to completely specify the input pulses and how they might change, in detail.  That means min/max voltage levels for both high and low going pulses, and min and max input pulse widths at say the 50 percent voltage levels for each pulse, and the min and max times of the output pulse.  The pulse min time will be more important, the max time could probably be infinite because the circuit will be DC coupled throughout.

Basic operation is very simple...
The input pulse goes high and flips the latch to digital state 1 with voltage at the output logic high state.  The input pulse goes back to nominal and nothing happens.  The input pulse goes below nominal and the other comparator detects it and flips the latch output state to a logic low state.  It's that simple and that is partly why it is guaranteed to work

The simplification, that should come later, is to use just two comparator sections as a latch and try to get the input pulses to control that directly.  It is best not to use any series capacitors to couple the signal into the latch inputs though, a DC coupled circuit is much more preferred.




 

Online BillyO

  • Super Contributor
  • ***
  • Posts: 3168
  • Country: ca
Re: How to reshape this signal into a square wave.
« Reply #65 on: July 01, 2026, 07:13:23 pm »
Also, with the 555 output and inverter, you could replace the 2N3904 and 10K with just a NMOS (2N7000).

Best
Yes, that would work!

But you may get some of the Real Engineers™ here cry about not having a gate resistor.   :palm:
« Last Edit: July 01, 2026, 08:01:56 pm by BillyO »
Bill
----
 

Online BillyO

  • Super Contributor
  • ***
  • Posts: 3168
  • Country: ca
Re: How to reshape this signal into a square wave.
« Reply #66 on: July 01, 2026, 07:16:45 pm »
The idea with the LM339 is to form a SET/RESET latch with two sections of the IC, then use the other two to detect the high going input pulse and the low going input pulse.
So, basically make a 555?
Bill
----
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 2247
Re: How to reshape this signal into a square wave.
« Reply #67 on: July 03, 2026, 03:06:08 am »
The idea with the LM339 is to form a SET/RESET latch with two sections of the IC, then use the other two to detect the high going input pulse and the low going input pulse.
So, basically make a 555?

Hi,

Not really.  The 555 is more hard-wired.  Using an LM339 gives us more flexibility in the design because nothing is hard wired until we actually decide to wire it that way.  No voltage level fudging either.
 

Online BillyO

  • Super Contributor
  • ***
  • Posts: 3168
  • Country: ca
Re: How to reshape this signal into a square wave.
« Reply #68 on: July 03, 2026, 03:35:04 am »
I see what you're getting at, but voltage level fudging?  The 555 is specifically designed to allow for voltage level control.  It's not fudging, it's using a designed-in feature.   :-//

The 555 solution is the only one yet to put rubber on the road, so to speak.  All the other hypotheses so far are untested.  Sure, some actually seem to run in simulation, but as we all know, simulation is not reality.  I have no doubt you could get some of these to actually work, but it has yet to be shown here.

Others have the phase of the output wrong, even in simulation.   :--
Bill
----
 
The following users thanked this post: mawyatt

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3302
  • Country: au
Re: How to reshape this signal into a square wave.
« Reply #69 on: July 03, 2026, 06:03:42 am »
I see what you're getting at, but voltage level fudging?  The 555 is specifically designed to allow for voltage level control.  It's not fudging, it's using a designed-in feature.   :-//
Note however that the 'voltage control' of the 555 is only partial, as is it only a single pin on the upper 5k, so you cannot position VH+ and VH- independently.
 

Online BillyO

  • Super Contributor
  • ***
  • Posts: 3168
  • Country: ca
Re: How to reshape this signal into a square wave.
« Reply #70 on: July 03, 2026, 02:05:35 pm »
Note however that the 'voltage control' of the 555 is only partial, as is it only a single pin on the upper 5k, so you cannot position VH+ and VH- independently.
True, but you can center the thresholds on the signal.  If I were to do this for an actual project I'd use a 2K7 fixed resistor with a 5K pot to cover the range of the divider resistors in the 555.  The CMOS variety seem to have much better tolerance.  That way I'd be able to set it for best performance.  As it stands the input signal can be from 1.2Vpp up to whenever the lower pulse goes negative.
Bill
----
 

Offline mawyatt

  • Super Contributor
  • ***
  • Posts: 6048
  • Country: us
Re: How to reshape this signal into a square wave.
« Reply #71 on: July 03, 2026, 02:51:36 pm »
I see what you're getting at, but voltage level fudging?  The 555 is specifically designed to allow for voltage level control.  It's not fudging, it's using a designed-in feature.   :-//

The 555 solution is the only one yet to put rubber on the road, so to speak.  All the other hypotheses so far are untested.  Sure, some actually seem to run in simulation, but as we all know, simulation is not reality.  I have no doubt you could get some of these to actually work, but it has yet to be shown here.

Others have the phase of the output wrong, even in simulation.   :--

Seems to actually work :-+

See post #4 ;)

Best
Curiosity killed the cat, also depleted my wallet!
~Wyatt Labs by Mike~
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf