How can I count the number of middle pulses from the given signal - Page 1
Forum section: electronics / projects

author: tranvannhancu
author_rank: Newbie
timestamp: July 05, 2024, 10:11:54 am
content: Hi all,I have the following signal where I need to design a circuit to count the number of pulses.The pulse is at the middle. There are valleys before and after each pulse.The amplitude of pulses are also different.Could anyone guide me on what kind of circuit I can use to do this?Thanks!

author: moffy
author_rank: Super Contributor
timestamp: July 05, 2024, 10:51:11 am
content: Use a small micro for logic and say a comparator with a threshold of 300mv and some hysteresis or just feed the signal into the ADC of a small micro and do all the filtering, detection and counting in code.

author: 2N3055
author_rank: Super Contributor
timestamp: July 05, 2024, 10:52:39 am
content: Quote from: tranvannhancu on July 05, 2024, 10:11:54 amOn that image, number of positive pulses in the middle of that negative pulse is same as all those groups...That whole valley before, pulse in the middle and valley behind repeats as a group.I would detect first negative going edge, ignore everything for a time length of a group, and then be ready to detect another one..Either AC couple the signal and use negative going zero pass detector, or if DC levels are stable a comparator (with some hysteresis) to detect edge. And then you can use microcontroler to read state, ignore changes for the short period, and count the groups..

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 06, 2024, 12:17:29 am
content: Quote from: tranvannhancu on July 05, 2024, 10:11:54 amYou have not said how that varies (aside from the middle peak) and if you need to reject any pulses.A simple scheme would be a comparator that slices on ~50% of the negative swings, feeding a counter, and you divide by 2 / shift right 1 bit, as you increment by 2 every pulse.Modern Rail-Rail comparators with push pull outputs, often have inbuilt hysteresis.Your signal looks quite slow, so you could add more noise filtering by adding a RC filter between the Comp output and a counter with a schmitt trigger clock.

author: CaptDon
author_rank: Super Contributor
timestamp: July 06, 2024, 02:01:15 pm
content: Trigger a one shot from the negative going leading edge (probably through a comparator) and set the one shot so it can't retrigger until after the duration of your total pulse width plus about 10%. The negative side of your pulses look uniform and of the same width within a few percent. What will be your time base? You say you want to count the number of pulses?? Total number? How many occur in a second, a minute, a year? You could build a reliable circuit with a comparator with adjustable threshold and a one shot 74LS121 with variable 'non-retrigger' timeout. 74LS123 won't be suitable because it is retriggerable during the current pulse. A 555 may work as I think they have to time out before being retriggerable. In any event I could do it with two very simple readily available I.C.'s and just a very few resistors and a couple of capacitors.

author: tranvannhancu
author_rank: Newbie
timestamp: July 08, 2024, 02:50:14 am
content: Thanks a lot to everyone who contributed to my question. I appreciate all your suggestions!I'm by no mean a professional EE engineer so please bear with me if I ask a dumb question.I should provide more scope to my original question.The signal you're seeing is from an IR receiver.The transmitter and receiver pair are approximately 3cm apart.They are used to detect a small and fast-moving subject.My goal is to generate an interrupt signal to the MCU (which is sleeping to save battery) every time the subject moves across the transmitter-receiver pair.I tried using an inverting comparator with hysteresis where I set my reference voltage to be slightly larger than the input voltage when there are no pulses.The input signal is subject to ambient light, i.e. signal amplitude will vary within around 200mV. That's why I can't use a fixed reference voltage.Do you know how I can make the reference voltage adapted to the ambient light?Thanks again.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 08, 2024, 03:57:25 am
content: Quote from: tranvannhancu on July 08, 2024, 02:50:14 amIR receivers usually have some inbuilt means for handling ambient light. What is the part number ?Usually that is a low frequency current feedback, that tracks slow light changes, but it needs care if you have fluorescent or LED lighting, or sunlight through tree leaves.Take some scope captures at varying light levels.

author: jbb
author_rank: Super Contributor
timestamp: July 08, 2024, 08:49:04 am
content: How about an analog band pass filter followed by a comparator?

author: CaptDon
author_rank: Super Contributor
timestamp: July 08, 2024, 01:21:44 pm
content: Can you show more revealing scope shots that show 'no subject in beam' and 'subject in beam'?? You want to count "The middle pulses". Every one of the negative pulses shown on your scope shot has a 'middle pulse'. Are you saying the only valid middle pulses to be counted are the ones above the reference line as you are showing one of the pulses is way more positive than the rest? If you want to detect a fast moving object you don't do it with a pulsed beam!!!! What if the object goes through the beam when the pulsing beam is off?? I think you need a total re-think of this detector scheme and we need more scope shots if we are to provide any sort of valuable insight to your project. 'Counting' the pulses? What will the count reveal since it is a pulsed beam? Why not use the normal LED with photodiode in the standard fashion like they do to count parts or pieces on a conveyor line. Putting a short piece of tubing in front of the LED and the photodiode can make the device less effected by ambient light.

author: selcuk
author_rank: Frequent Contributor
timestamp: July 08, 2024, 01:55:14 pm
content: If you cannot detect from amplitude difference, you can try frequency domain as suggested above. If it is possible to keep CPU running, you may use sliding window fast FFT algorithms.

author: nfmax
author_rank: Super Contributor
timestamp: July 08, 2024, 02:00:21 pm
content: It looks like you are trying to detect mostly opaque objects, but which have a hole in the middle that contains something that reflects or refracts the light passing through it. Are you trying to count the number of objects, or the number of holes? Do they all travel at the same speed? All in the same direction? At different angles?

author: ledtester
author_rank: Super Contributor
timestamp: July 09, 2024, 12:58:08 am
content: Here is a piecewise linear representation of the signal presented in the first post -- can be used for testing algorithms and/or circuit simulation.The "x" and "y" columns are pixel positions within the screenshot PNG - the "t" and "mv" columns are time in ms and signal voltage in mV.

author: CaptDon
author_rank: Super Contributor
timestamp: July 09, 2024, 10:00:49 pm
content: O.P. still hasn't given enough information about his signal to be of any use to us. Detect 'which' middle pulses?Every pulse shown has a middle pulse, some bigger than others. What is the 'go / no go' criteria? I'm not convinced the O.P. even knows and who detects 'fast moving objects' with a pulsed beam?

author: CaptDon
author_rank: Super Contributor
timestamp: July 10, 2024, 01:00:44 am
content: I guess I misunderstand. The beam itself isn't pulsed, the pulses shown are the actual objects passing through the beam. Please O.P., tell us more about the objects and which of the middle pulses you consider to be valid. Your original scope shot shows various heights of middle pulses.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 10, 2024, 09:29:17 am
content: I've been following this thread and waiting for the OP to refine the question.@CaptDon (#5)I was tempted to add a concurring comment. It seems the items give a complex signal, but all you need to do for an accurate count is detect the signal start and then use something to effectively inhibit response until the next item. A one-shot is one approach.Then I saw that the user wants to use simple on/off IR in what seems like an open area. That will be the problem, and I don't see an easy solution or why one would want to do that. Modulated IR modules are plentiful and cheap. They do not require an MCU to operate.

author: mino-fm
author_rank: Regular Contributor
timestamp: July 10, 2024, 10:40:32 am
content: Simply count all rising (or falling) edges and divide by 2.:-)

author: jpanhalt
author_rank: Super Contributor
timestamp: July 10, 2024, 11:09:12 am
content: Look at peaks #1 and #7 (as examples). The center peak is not a single peak sometimes -- probably due in part to using straight IR rather than modulated IR.

author: dietert1
author_rank: Super Contributor
timestamp: July 10, 2024, 01:31:51 pm
content: The posted csv file contains a reduction to piecewise linear data. I think that is the algorithm the OP is asking for. Probably a test question.Regards, Dieter

author: johnk0gcj@gmail.com
author_rank: Contributor
timestamp: July 10, 2024, 07:12:31 pm
content: How about a delayed sweep scope?

author: ledtester
author_rank: Super Contributor
timestamp: July 10, 2024, 10:10:13 pm
content: Here's an attempt using a data slicer circuit.It uses the digitized signal from my earlier post but in this case formatted to work as a PWL file.The Vdelta source is just an time-dependent offset to test how sensitive the detector is to slow changes in the DC offset.

author: tranvannhancu
author_rank: Newbie
timestamp: July 12, 2024, 04:45:29 am
content: Thanks for all your comments.I attached more photos to explain my setup.1st photo:The small object that I want to count is water droplets. It is transparent as one of you mentioned.2nd photo:Here the IR LED is not modulated. It is turned on all the time.Highlighted is what I meant by "middle pulse".The signal pattern is the same for every water droplet, only the amplitude is inconsistent.A few mentioned that I can detect the first falling edge and wait a bit until detecting the next fall egde.This is actually what I'm doing on the MCU.The disadvantage of this is that its average current is much higher than what I can allow, due to the fact that IR LED is not modulated.3rd photo:I've recently tried to modulate the IR LED.Here I'm doing 1kHz at 20% duty.Highlighted is the signal pattern on there is a water droplet passing by.In this case the average current is within my power budget.However, I'm not really sure if I can count the drops using this approach.I also attached the raw signal that I captured using modulated approach.Please let me know what what think how I should go from here.Thanks all!

author: nfmax
author_rank: Super Contributor
timestamp: July 12, 2024, 06:08:37 am
content: If you stick with the 1kHz pulsing of the LED to reduce power consumption, then the task is to detect a missing pulse in the output. Since you know when the LED is turned on, you can use an analogue peak detector, reset to 0V before the LED is turned on, and sample its output just before the next pulse. Then compare the sampled level with the average over the last few pulses. If it is less than ~50% you have found a droplet. Count it, and wait the ‘dead time’ for the droplet to pass before renabling sampling. You need to remember the average level, and only start updating it after the dead time, when the droplet has passed. To save a bit more power, you could stop pulsing the LED during the dead time.This could be done with a mixture of simple analogue circuits and microcontroller code.

author: KerimF
author_rank: Frequent Contributor
timestamp: July 12, 2024, 07:34:26 am
content: I guess it is known that a conventional IR receiver expects an IR 38 KHz signal. It has an internal BPF and a digital detector to output low (on) and high (off) levels only. (Such IR receivers are used in TVs and satellite receivers, controlled by IR remote control units).This reduces (almost eliminates) the side-effect of the ambient light.And the digital output will likely be cleaner.Also, as it was mentioned by others, driving the IR LED (38 KHz) doesn’t need to be continuous (to save power). And the driving current could be made relatively small in this application (because distance between TX and RX is rather short). Obviously, its optimum value could be found experimentally.Kerim

author: jpanhalt
author_rank: Super Contributor
timestamp: July 12, 2024, 09:30:58 am
content: Re: 1kHz modulated scanThat makes it relatively simple. Set up a a gated counter (missing pulse detector, as suggested by others earlier), count every time the pulse disappears, and then blank counting for whatever time it takes. From the scan, it looks like that blank needs to be at least 10 ms. About 20 ms might work well without missing a subsequent count.As your are not using a filter in the receiver yet, that approach will still be subject to ambient light.

author: ledtester
author_rank: Super Contributor
timestamp: July 12, 2024, 01:14:42 pm
content: From:https://forum.arduino.cc/t/counting-water-drops-dripping-from-iv-bottle/581542/12Quote

author: KerimF
author_rank: Frequent Contributor
timestamp: July 12, 2024, 05:11:40 pm
content: If it is my project, I would simply take advantage of the water’s conductance (assuming it is not pure).I mean, two electrodes and a small MOSFET can interrupt the MCU at each drop.The power consumption of such a counter is the lowest, I guess.Kerim

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 12, 2024, 09:03:17 pm
content: Quote from: tranvannhancu on July 12, 2024, 04:45:29 amAs long as you have a clear change in signal, you can certainly sense and count.You should repeat the captures for all expected ambient light conditions, as unwanted light will certainly affect this, and some mounting apertures would help reject stray light.It would help to have the LED and Photo transistor part numbers.Addit : if you need more immunity from lighting, you could also look at the IR receivers designed for Code Learning (or IR repeaters, they look similar)https://www.vishay.com/en/ir-receiver-modules/Those have wider bandwidth/faster response than the data burst IR receivers, and their shorter range of ~ 1.8m is still well above your target distance.Their Icc of 350uA gives you a reference point for your Photo transistor too.

author: Benta
author_rank: Super Contributor
timestamp: July 12, 2024, 09:43:01 pm
content: Simple solution:1: square up the signal (comparator, Schmitt trigger, whatever...)2: use a NON-retriggerable, positive-edge, monostable multivibrator (eg, 74HC221) and set the time to be longer than the spike and the following positive edge.Done.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 13, 2024, 05:54:30 am
content: I found the part I remembered - the Sharp IS471Fx - that's a IR Receiver, similar to any remote control RX, but with a couple of tweaks.Sharp add a 4th pin to drive a LED with narrow duty pulses. ~ 8kHzThe RX side includes a sync detector that gives high ambient light immunity.https://www.sharpsde.com/products/optoelectronic-components/model/is471fe/The Icc is not great, but you could use some to test with, to compare results.

author: ledtester
author_rank: Super Contributor
timestamp: July 14, 2024, 03:57:54 am
content: Another approach to eliminate the variation due to ambient light:https://forums.parallax.com/discussion/comment/794922/#Comment_794922QuoteAnd in a follow-up reply...https://forums.parallax.com/discussion/comment/795031/#Comment_795031Quote