Maker Pro
Maker Pro

Detecting positive and negative edges

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi all,
I need some advice. I have different sound patterns that are driven from a microcontroller. They vary in pulse width and duration according to the different alarm patterns. They are used to drive a piezo circuit.
I need to monitor the sound patterns to determine which alarm occurred, this needs to be done 24 hours a day and recorded. The pulse widths can vary from 20us to 100us.
I am looking at the possibility of using a differentiator circuit to catch the edges of the pulses and then cleaning the signal up (perhaps using Schmitt trigger). This then feeds into a second microcontroller which starts a timer on the first edge and stops it on the second edge. Hence determining the pulse duration and type of alarm sent.
I am not 100% sure if this looks feasible.
I would appreciate any help.
If you need more information, please let me know.
Best regards,
Rajinder
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Sounds feasable.

Use interrupts to start and stop a timer.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Yes, I'm looking at using a interrupt to detect the edge, start timer and then on next edge stop timer.
I wasn't sure if the Schmitt trigger would just clean up the edge or if it will give me a small pulse to represent the edge.
Any thoughts?
Best regards,
Raj
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
It will give you a fast edge. Note that many Schmitt Triggers also invert the signal, so if this is the case you'll want to count from a negative edge to a positive edge.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
I don't know why you need a differentiator. That would give you a positive going pulse at the start and a negative going one at the end. The microcontroller can detect the edges itself without a differentiator. And in fact, it would not like the negative going pulse at all.

In PIC microcontollers (and probably others,) you can interrupt on change. Just feed the signal to an input pin and set interrupt on change for that pin. Some PICs also have Schmitt trigger inputs, no need for an external one.

Bob
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
For some reason I read it as using a comparator as a Schmitt trigger.

I agree with bob. You need to ensure the signal going to the microcontroller is properly conditioned to be within the supply rails and preferably switching quickly between the supply rails. An external Schmitt trigger can help with this although it may not be required.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi,
The sound patterns vary in pulse width. So can I connect this straight to an pic I/O port that has interrupt on change. Would I need any circuitry at all? Where does the Schmitt trigger come into this?
My idea for the differentiator was to detect edges, clean them up then feed the to I/O of the PIC.
Best regards,
Raj
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
On a Picmicro you can use the capture feature which can be set for positive edge followed by negative edge and a timer capture used to determine the time between.
M.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
On a Picmicro you can use the capture feature which can be set for positive edge followed by negative edge and a timer capture used to determine the time between.
M.
Hi,
Thanks for your advice. The sound patterns are totally asynchronous, so I would need a interrupt to capture the first edge. Can I still do this with capture feature?
Best regards
Rajinder
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
it cleans up edges



A differentiator won't do that in the general case.
Hi Steve,
Thanks for your help.
My idea was to get the edges detected by differentiator, clean edges using Schmitt trigger, then feed this into PIC interrupt to detect high to low edge, start timer, detect low to high edge, stop timer. Calculate the width using timer value and then compare with known values to see if it was a smoke or heat alarm pattern.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
as I said, that's what a Schmitt trigger does.

a differentiator will add all sorts of extra transitions.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
And create negative pulses that you would have to suppress. It simply does not help you at all. The edges coming out of the other micro should be pretty clean already, but I was suggesting you use a Schmitt trigger input on the micro if one is available.

The capture feature that Minder mentioned is intended for this exact purpose, but it is a little more complicated to use than simply interrupting on the edges and doing the capture part yourself. Depends on the accuracy you need. The capture feature will give you 1 clock cycle resolution, which would be hard to achieve with software.

Bob
 

dorke

Jun 20, 2015
2,342
Joined
Jun 20, 2015
Messages
2,342
Rajinder,
It would be the best ,if you can show us the signal on a scope.
So we can see it's shape,amplitude,edges etc.
Can you do that ?
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Yes,
I can do that.
I will post some screenshots asap.
Thanks for your help.
 

jonathanscottjames

Jul 25, 2010
5
Joined
Jul 25, 2010
Messages
5
how many different length pulses are there? is it a 2wire differential signal? if it's a 2wire differential signal , use a 2 input + and - differential signal detector ic. other than that .. what is the minimum voltage level of the pulse signal? can you draw the shape of the pulse?.. if the "minimum" detectable voltage is above 1/2vdc and the signal line is unbalanced and its impedance is more than 10k ohms ,,,and the max signal is less than 5vdc ,, and it never goes more than -5vdc i would use a potentiometer to the interrupt pin. but if you got crazy parameters. i guess you need to use a potentiometer in series with a capacitor to ground and take the signal off the junction between the capacitor and resistor and feed the signal into the other end of the resistor . but you need to know the impedance of the signal and its and it's effective power level after considering other circuits on the line, other wise , i would start with a 100k potentiometer and a 10uf cap. then work my way up to an emitter follower decoupler then try to use the previously described filter and after that i would work my way toward a +5v and -5v supply on the emitter follower freeing the potentiometer filter then translate it up above ground with a peak detector if nessessarry.

can you use a free sound-blaster based scope program to record the signal pulses and show us?

there are too many different standard signal types and genaric signal types that it could be.. without knowing the origin of the signal or it's waveform. the potentiometer and capacitor design is probly the answer if it's a simple system. but other than that , it could require an attenuator and a adc with a bias correction circuit and a decoupler stage
 
Last edited:

Pascal Xavier

Jun 8, 2016
2
Joined
Jun 8, 2016
Messages
2
What you could do is to connect an IO card to your PC, connect your sound signal on an IO, measure the time between the edges, and repeat this measure several times to be sure of the repetitivity (and eliminate bad measures in case they would have been interrupted); on an IO card there is generally a timer which is very precise, you can read this timer at the raising and falling edges of the sound signal; the difference between the two readings of the timer gives the duration of the signal; repeat this measure several times, eliminate the measures which are far from the other ones, and make an average of the good measures.
 

Pascal Xavier

Jun 8, 2016
2
Joined
Jun 8, 2016
Messages
2
Another solution, may be still simpler, would be to connect the sound signal on a counter, and to read the count of pulses on a given period.; that's the way we count the frequency of a tacho signal.
 
Top