CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

square wave frequency generator

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fedetouz



Joined: 01 Aug 2007
Posts: 14

View user's profile Send private message

square wave frequency generator
PostPosted: Tue Jun 17, 2008 4:35 pm     Reply with quote

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

View user's profile Send private message

Re: square wave frequency generator
PostPosted: Tue Jun 17, 2008 7:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 18, 2008 3:53 am     Reply with quote

http://www.scienceprog.com/avr-dds-signal-generator-v20 you can change to pic
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Jun 18, 2008 7:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 18, 2008 11:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 18, 2008 1:51 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 18, 2008 4:30 pm     Reply with quote

I will think about all the answers

Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group