View previous topic :: View next topic |
Author |
Message |
fedetouz
Joined: 01 Aug 2007 Posts: 14
|
square wave frequency generator |
Posted: Tue Jun 17, 2008 4:35 pm |
|
|
Hi, i have a problem, i need make frequency generator from 100Hz to 1200HZ with good resolution. Any idea?, i try with PWM but its not user friendly!!.
This generator depend of float value (GPS VTG sentence ) for generate the output freq.
Its for replace velocimeter (magnetic) with GPS.
Thanks! and sorry for my english! |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: square wave frequency generator |
Posted: Tue Jun 17, 2008 7:00 pm |
|
|
Do you want to total integrated number of pulses to represent GPS position? Or do you just want a frequency that represents velocity from the GPS? One parameter that you may want to relax to make your job easier is jitter. It is much easier to generate a specific high-resolution long-term frequency if you allow that frequency to have some jitter. That means the period of each pulse might be different, but the total number of pulses over a long enough time period (like one second) will be what you want it to be.
If that is the case, then I suggest using a CCP module in Output Compare Mode. Since the highest frequency is 1200 Hz, you have plenty of time to compute the next Compare event time. It gives you more flexibility and resolution and PWM. _________________ Robert Scott
Real-Time Specialties
Embedded Systems Consulting |
|
|
digitalmg
Joined: 12 Apr 2007 Posts: 2
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jun 18, 2008 7:45 am |
|
|
What you need is called a "numerically controlled oscillator". I wrote one years ago for a PIC16C58 clocked at 20MHz that produced output to 32kHz for sonar work.
Basically you have a long (16bit) phase accumulator register. The MSBit of this register will be your square wave output as the accumulator overflows. Every cycle you add a phase increment value to the phase accumulator. The bigger the increment value the more frequently the accumulator overflows and the higher your output frequency.
Google "numerically controlled oscillator" for more info. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Wed Jun 18, 2008 11:53 am |
|
|
I was about to say this doesn't sound right, but after a few seconds of thinking about it--it's an interesting way to generate a signal. You could get 32KHz by adding 0x8000 to the accumulator at a 64KHz rate. But what if you added 0x7FFF? Then you'd see a 32KHz output but with an occasional lengthened pulse. I wouldn't call that a "controlled frequency" though.
Not trying to be difficult, if I've misunderstood this, please enlighten an ignorant one. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jun 18, 2008 1:51 pm |
|
|
That is exactly right. "An occasional lengthened pulse" is the best approximation possible given a 64kHz master time cycle. Also any roundoff errors don't add up. You do get the right number of cycles over a long period. High end frequency synthesizers use a 24 or 32 bit phase accumulator and have a faster time cycle, all done in hardware. But 16 bits done with a PIC works very well for most things.
And if you want another wave shape besides a square wave the upper bits of the phase accumulator can go directly into a lookup table to generate whatever shape you imagine.
BTW if 0x8000 gives 32kHz, 0x7fff gives 31.99902 kHz. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
fedetouz
Joined: 01 Aug 2007 Posts: 14
|
|
Posted: Wed Jun 18, 2008 4:30 pm |
|
|
I will think about all the answers
Thanks! |
|
|
|