Author Topic: Measuring pulses, schmitt trigger advice?  (Read 1642 times)

0 Members and 1 Guest are viewing this topic.

Offline Bug2k17Topic starter

  • Contributor
  • Posts: 12
  • Country: gb
Measuring pulses, schmitt trigger advice?
« on: November 16, 2018, 06:55:40 pm »
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.
 

Offline aheid

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Measuring pulses, schmitt trigger advice?
« Reply #1 on: November 18, 2018, 10:47:17 am »
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...
 

Offline mvs

  • Frequent Contributor
  • **
  • Posts: 370
  • Country: de
Re: Measuring pulses, schmitt trigger advice?
« Reply #2 on: November 18, 2018, 01:57:19 pm »
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.
Add some debouncing code to your arduino application.

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.
Why do you think, that CMOS threshold voltage (Vcc/2) is not ok for this application?
 

Offline aheid

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Measuring pulses, schmitt trigger advice?
« Reply #3 on: November 18, 2018, 03:22:30 pm »
Why do you think, that CMOS threshold voltage (Vcc/2) is not ok for this application?

First 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".

 

Offline Bug2k17Topic starter

  • Contributor
  • Posts: 12
  • Country: gb
Re: Measuring pulses, schmitt trigger advice?
« Reply #4 on: November 18, 2018, 04:23:25 pm »
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.
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: Measuring pulses, schmitt trigger advice?
« Reply #5 on: November 18, 2018, 04:33:42 pm »
"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.
.  That took much longer than I thought it would.
 

Offline aheid

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Measuring pulses, schmitt trigger advice?
« Reply #6 on: November 18, 2018, 05:17:20 pm »
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.

Do 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.
 

Offline Bug2k17Topic starter

  • Contributor
  • Posts: 12
  • Country: gb
Re: Measuring pulses, schmitt trigger advice?
« Reply #7 on: November 18, 2018, 05:28:05 pm »
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.
 

Offline Bug2k17Topic starter

  • Contributor
  • Posts: 12
  • Country: gb
Re: Measuring pulses, schmitt trigger advice?
« Reply #8 on: November 18, 2018, 05:30:14 pm »
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.

Do 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.

I only have a few basic components around, circuit design isn't something I do very often. 'comparator chip'?
 

Offline aheid

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Measuring pulses, schmitt trigger advice?
« Reply #9 on: November 18, 2018, 07:10:06 pm »
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.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16607
  • Country: us
  • DavidH
Re: Measuring pulses, schmitt trigger advice?
« Reply #10 on: November 21, 2018, 04:36:43 am »
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.
 

Offline Bug2k17Topic starter

  • Contributor
  • Posts: 12
  • Country: gb
Re: Measuring pulses, schmitt trigger advice?
« Reply #11 on: November 21, 2018, 06:09:31 pm »
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.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Re: Measuring pulses, schmitt trigger advice?
« Reply #12 on: November 21, 2018, 06:22:15 pm »
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.html

1 - Both signals are high, output is low
2 - First signal goes low and sets the flop - the output goes high
3 - First signal restores high
.. some time later
4 - Second signal goes low and resets the flop - the output goes low
5 - Second signal restores high
.. repeat from step 1

I 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/

 

Offline Bug2k17Topic starter

  • Contributor
  • Posts: 12
  • Country: gb
Re: Measuring pulses, schmitt trigger advice?
« Reply #13 on: December 03, 2018, 09:47:55 am »
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.
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: Measuring pulses, schmitt trigger advice?
« Reply #14 on: December 04, 2018, 01:12:52 pm »
"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 a digital edge.
.  That took much longer than I thought it would.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf