Measuring pulses, schmitt trigger advice? - Page 1
Forum section: electronics / beginners

author: Bug2k17
author_rank: Contributor
timestamp: November 16, 2018, 06:55:40 pm
content: I'm using an arduino to count and/or measure pulses (still working on which) to calculate the speed of a bicycle wheel used on an indoor trainer. The roller the wheel spins has 4 equal spaced gaps on a cylinder that creates the pulses as it spins (3.3v peak).As I've found, in practice this works but is not a clean stable speed reading. This looks like it might be caused by the slow and noisy rise of the pulse, as when I've used a frequency generator to send nice relatively clean pulses to the arduino, the speed reads correctly and is stable. From what I've read a schmitt trigger sounds like a solution, but all the through hole parts seem to be 14 or 16 pin packages which seems overkill for just 1 signal.I'm really not an electronics guy, but have bodged a circuit together that seems to work for my needs, just looking for advice on a part which would be best suited for this.Thanks.

author: aheid
author_rank: Regular Contributor
timestamp: November 18, 2018, 10:47:17 am
content: The Atmega328p powering the Arduino has a built-in analog comparator. You could use it to trigger when pulse voltage rises above some threshold voltage given on a second pin.In addition the analog comparator can trigger the input capture unit of timer 1, to capture a timestamp of when this happens.I have some code for this, but I can't recall if I ever got around to testing it properly before having to move...

author: mvs
author_rank: Frequent Contributor
timestamp: November 18, 2018, 01:57:19 pm
content: Quote from: Bug2k17 on November 16, 2018, 06:55:40 pmAdd some debouncing code to your arduino application.Quote from: aheid on November 18, 2018, 10:47:17 amWhy do you think, that CMOS threshold voltage (Vcc/2) is not ok for this application?

author: aheid
author_rank: Regular Contributor
timestamp: November 18, 2018, 03:22:30 pm
content: Quote from: mvs on November 18, 2018, 01:57:19 pmFirst off, the threshold voltage is not Vcc/2. Second, using the digital input could work using some low-pass filtering (either in hardware or software). With the analog comparator however you could set the threshold voltage yourself, and with the input capture you get the timestamp and low-pass filtering "for free".

author: Bug2k17
author_rank: Contributor
timestamp: November 18, 2018, 04:23:25 pm
content: Thanks for the replies.I'm already using the comparator interrupt to sync a pulse with an incoming AC signal.I'm just trying to get a nice steady speed reeding. The cycle trainer I have has a magnetic braking unit, so I'm basically making a new control unit for this which has the ability to transmit it's data via ANT+. So when linked up to a PC or tablet can be used to simulate different gradients. This is an old unit that never had a USB or ANT+ connection.

author: StillTrying
author_rank: Super Contributor
timestamp: November 18, 2018, 04:33:42 pm
content: "but is not a clean stable speed reading."?You're not going to get a very stable reading from a human powered wheel. As there's plenty of pulses you could average the timing of the last 4 or 8 pulses.

author: aheid
author_rank: Regular Contributor
timestamp: November 18, 2018, 05:17:20 pm
content: Quote from: Bug2k17 on November 16, 2018, 06:55:40 pmDo you have a comparator chip around? You could make your own Schmitt trigger with just a few resistors. An opamp works as well, though not as good.

author: Bug2k17
author_rank: Contributor
timestamp: November 18, 2018, 05:28:05 pm
content: This is true, the speed reading will not be perfectly stable. I already have averaging of the last few readings which helps but is not a solution. Even with this every few seconds the speed will change by more than a few mph/kph and then slowly average back up (or down) to the correct reading before spiking again. The original trainer computer does not do this, not does a garmin picking up speed from an ANT+ wheel sensor.I'll pick up a cmos schmitt trigger ic and try it out, something like the CD40106BE looks like it might do the job.

author: Bug2k17
author_rank: Contributor
timestamp: November 18, 2018, 05:30:14 pm
content: Quote from: aheid on November 18, 2018, 05:17:20 pmI only have a few basic components around, circuit design isn't something I do very often. 'comparator chip'?

author: aheid
author_rank: Regular Contributor
timestamp: November 18, 2018, 07:10:06 pm
content: A comparator is a bit like a specialized op-amp. It has the same kind of inputs, but is made to strongly go to either rail depending on the voltage difference between the inputs.http://circuitcellar.com/ee-tips/op-amp-versus-comparator-ee-tip-128/But yeah, might as well pick up some Schmitt triggers, they'll come in handy in other cases I'm sure.

author: David Hess
author_rank: Super Contributor
timestamp: November 21, 2018, 04:36:43 am
content: Schmitt trigger inputs are more useful for handling signals with a slow transition time than noisy signals. If a noisy signal is filtered with a simple RC filter, then the transition time is slowed and a schmitt trigger would be used so place an RC filter in front of your schmitt trigger.

author: Bug2k17
author_rank: Contributor
timestamp: November 21, 2018, 06:09:31 pm
content: Thanks for the advice, I've got a few schmitt triggers on order, I'll see what the signal looks like with one in place.

author: rstofer
author_rank: Super Contributor
timestamp: November 21, 2018, 06:22:15 pm
content: If the Schmitt Trigger doesn't work out, come up with a quadrature encoder. Use two optical sensors spaced such that only one sensor can ever be active at one time. Then you can square up the signals by connecting the two negative going outputs to a pair of NAND gates connected as an SR Flip-Flop - search for it here:https://www.electronics-tutorials.ws/sequential/seq_1.html1 - Both signals are high, output is low2 - First signal goes low and sets the flop - the output goes high3 - First signal restores high.. some time later4 - Second signal goes low and resets the flop - the output goes low5 - Second signal restores high.. repeat from step 1I am assuming the optical signal goes low when the sensor sees the slot. If it goes high, use NOR gates.https://www.electronicshub.org/sr-flip-flop-design-with-nor-and-nand-logic-gates/

author: Bug2k17
author_rank: Contributor
timestamp: December 03, 2018, 09:47:55 am
content: Thanks for the advice, much appreciated.I picked up a few CD40106BE and sent the incoming speed sensor pusles throught this and it has resolved the speed reading changing erratically. The rise time of the unfiltered pulse at average cycling speeds was around 200us or so but looked to be reasonable clean. I presume the rising pulse edge was spending too much time in the undetermined voltage range. Adding the schmitt trigger has cleaned up the pulse and allowed the speed calculation to come up with a more constant reading, with a little bit of averaging it seems fine now.

author: StillTrying
author_rank: Super Contributor
timestamp: December 04, 2018, 01:12:52 pm
content: "The rise time of the unfiltered pulse at average cycling speeds was around 200us or so but looked to be reasonable clean. I presume the rising pulse edge was spending too much time in the undetermined voltage range."Yep, that'll be it, 200us is very slow for adigitaledge.