Searching \ for '[PIC]:standard algorithm?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'standard algorithm?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:standard algorithm?'
2001\02\15@171922 by Mike Mansheim

flavicon
face
Is there a "standard" algorithm for counting the number of cycles in a
signal based on the peaks and valleys in that signal?
We have a piston pump that is run by a crank; so when running at steady
rpm, there is a consistent variation in the running pressure.  The
pressure is already an a/d input that is used for control - as long as
that signal is already there, it would be useful to count the pump
strokes.  The signal looks *somewhat* like rectified AC (the valleys are
sharper than the peaks), and has some noise on it.
I looked at the discussion of dtmf tone detecting, but that is geared
towards finding a frequency - I just want to total up the cycles on a
continuous basis.  Also, not being a math whiz, I don't fully understand
that whole discussion right off the bat.  I also looked through "Numerical
Recipes in C", but didn't find anything there.
Thanks for any help.

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\02\15@172559 by Spehro Pefhany

picon face
At 04:05 PM 2/15/01 -0600, you wrote:
>Is there a "standard" algorithm for counting the number of cycles in a
>signal based on the peaks and valleys in that signal?

In analog electronics, this could be done by low-pass filtering the
signal, AC coupling it, and applying a zero-crossing detector with
some hysteresis. You can do the same thing digitally, assuming
the frequency isn't too high.

If the signal has multiple humps in it or is otherwise strange, you
may have to do a bit more work.

Best regards,
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam@spam@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2001\02\15@175934 by Drew Vassallo

picon face
>Is there a "standard" algorithm for counting the number of cycles in a
>signal based on the peaks and valleys in that signal?
>We have a piston pump that is run by a crank; so when running at steady
>rpm, there is a consistent variation in the running pressure.  The
>pressure is already an a/d input that is used for control - as long as
>that signal is already there, it would be useful to count the pump
>strokes.  The signal looks *somewhat* like rectified AC (the valleys are
>sharper than the peaks), and has some noise on it.

Why not take a value midway between the center point of your A/D result and
the lowest value, and take another point between the center point and the
highest value.  Then compare every sample you take for your A/D against
these values, toggling a flag bit every time you pass these points (once up
and once down).  After a full cycle (toggle high, then low) increment a
counter.  This should give you the number of cycles.

Seems simple - all you need is one bit and a few lines of code for
comparison.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2001\02\15@175946 by Drew Vassallo

picon face
>In analog electronics, this could be done by low-pass filtering the
>signal, AC coupling it, and applying a zero-crossing detector with
>some hysteresis. You can do the same thing digitally, assuming
>the frequency isn't too high.

This would require another input pin, however.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


2001\02\15@182621 by Spehro Pefhany

picon face
At 05:59 PM 2/15/01 -0500, you wrote:
>>In analog electronics, this could be done by low-pass filtering the
>>signal, AC coupling it, and applying a zero-crossing detector with
>>some hysteresis. You can do the same thing digitally, assuming
>>the frequency isn't too high.
>
>This would require another input pin, however.

No, I mean do it all with the same A/D values. Easy if you call the
measurement routine with a fixed period (Ts). Just code two low
pass filters (the first above the frequency of interest to get
rid of the high frequency noise, the second cascaded filter
below the frequency of interest to give the "AC coupling"
offset (or you *may* be able to use a fixed value for this).
Preload the second one so it starts up faster.

Subtract the two filter outputs and you have a cleaned-up signal
that has nice (hopefully) zero crossings. Look for the transition
+Vth if the output is currently low, for -Vth if the output is
currently high.

You need to pick Vth, and the filter frequencies (and types if
you don't use a simple first-order lag- but I'd try that first).

Pick those things so it works reliably. ;-)

Best regards,
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffspamspam_OUTinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\02\15@221134 by Bob Ammerman

picon face
Assuming the pump runs at a relatively reasonable speed (maybe 1800RPM = 30
pulses per second?) you might be able to do everything inside the PIC with
software based on the existing A/D value (if the PIC isn't too busy
already):

> >In analog electronics, this could be done by low-pass filtering the
> >signal

Low pass filtering in software is very easy. The simplest technique is
probably an IIR filter, for example:

NewFilteredValue = OldFilteredValue * (1-k) + NewSample*k

Values of K like 1/2, 1/4, 1/8, 1/16 make for a particularly efficient
implementation.

>> AC coupling it

This can be done by maintaining a longer term average (ie: a much slower
digital filter) to track the average value of the signal.

> and applying a zero-crossing detector with

Just compare the outputs of the two filters.

> >some hysteresis.

Before doing the compare of the two filters, add a small value to the one
which was higher on the last pass. This will help it continue to be higher,
hence adding hysteresis.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...