Talk About Network

Google





Electronic Equipment > Digital Signal Processing (DSP) > Re: Low pass fi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 13 Topic 14031 of 14426
Post > Topic >>

Re: Low pass filter on a PIC

by Tim Wescott <tim@[EMAIL PROTECTED] > Oct 9, 2008 at 09:06 PM

Manfred wrote:
> Hi all!
> 
> Maybe someone here might help me with a DSP problem that should be
> trivial, but to me, as a newbie to DSP, is not.
> 
> I'm developing a microcontroller-based speed controller for my small
> hydroelectric plant. I'm using a PIC 16F628 for this. I'm detecting the
> zero crossings of the 50Hz signal coming from the generator, and
measuring
> the duration of each half cycle, obtaining a signal at a rate of 100
> samples per second. The signal is in 16 bit format, and nominally 10000
> counts tall. Typical variations are a few tens of counts, and
occasionally
> as much as 1000 counts. I'm subtracting the 10000 reference, and using
the
> resulting error signal as input to a pro****tional-integral control
> function, whose output drives dump loads that burn off the excess output
> from the generator.
> 
> The little problem I have is that a small 420Hz signal on the power
line,
> apparently coming from the generator's internal voltage regulator, is
> causing jitter in the zero crossings, which is in turn causing the
> pro****tional function of my controller to imprint an unwanted modulation
on
> its output. So I would like to apply a low pass filter function to my
> signal, with a cutoff frequency of roughly 20Hz, before the P-I
function.
>   
> The question is: How can I implement this DSP low pass filter? It has to
> be in some simple way, because neither the PIC nor I can handle overly
> complex math! 
> 
> The only thing I can come up with is averaging the last several samples,
> perhaps with some weighing. But there must be some better method!
>  
> It is desirable that the time delay in the filter be as short as
> possible.
> 
> I would be most grateful for any help in this, be it with an explanation
> of how to implement the filter, or a hint as to where I can find this.
> 
> Manfred Mornhinweg 
> http://ludens.cl

You want a simple first-order lowpass IIR filter.  You can implement it 
in one line of C:

output = gain * (input - output);

(note that the 'output' variable here must have a static lifetime).

A 20Hz cutoff is pretty high for a sampling rate of 50Hz -- you're not 
going to get much attenuation of your noise.  But you can fiddle around 
with your gain parameter (lower gain = lower bandwidth) to a compromise 
between noise reduction and overall loop bandwidth (and hope it's a good 
one).

Keep in mind that as you lower the filter bandwidth you'll have to back 
off your pro****tional and integral gains to keep the loop stable.  You 
may also find that you need to use more than 16 bits in the filter to 
maintain enough precision (see the end of this article 
http://www.embedded.com/2000/0010/0010feat3.htm
for comments on data 
path widths).

You may find some of the other articles on my website interesting: 
http://www.wescottdesign.com/articles.html.

And of course, if you want to get the full meal deal, check out my book. 
  It puts the math back in, but I tried to keep it grounded in reality.

-- 

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" gives you just what it says.
See details at http://www.wescottdesign.com/actfes/actfes.html
 




 13 Posts in Topic:
Low pass filter on a PIC
"Manfred" <m  2008-10-09 22:19:19 
Re: Low pass filter on a PIC
Tim Wescott <tim@[EMAI  2008-10-09 21:06:31 
Re: Low pass filter on a PIC
HardySpicer <gyansorov  2008-10-09 21:22:55 
Re: Low pass filter on a PIC
Jerry Avins <jya@[EMAI  2008-10-10 11:13:59 
Re: Low pass filter on a PIC
Scott Seidman <namdies  2008-10-10 12:27:20 
Re: Low pass filter on a PIC
Vladimir Vassilevsky <  2008-10-10 08:54:05 
Re: Low pass filter on a PIC
Jerry Avins <jya@[EMAI  2008-10-10 11:33:04 
Re: Low pass filter on a PIC
Randy Yates <yates@[EM  2008-10-10 16:35:44 
Re: Low pass filter on a PIC
"Manfred" <m  2008-10-10 20:33:40 
Re: Low pass filter on a PIC
Randy Yates <yates@[EM  2008-10-10 22:13:39 
Re: Low pass filter on a PIC
Jerry Avins <jya@[EMAI  2008-10-10 23:39:27 
Re: Low pass filter on a PIC
Randy Yates <yates@[EM  2008-10-11 00:23:53 
Re: Low pass filter on a PIC
Jerry Avins <jya@[EMAI  2008-10-11 14:00:50 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Thu Jan 8 21:21:08 PST 2009.