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

need one pin with 22kHz , it's possible ??

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



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

need one pin with 22kHz , it's possible ??
PostPosted: Wed Jul 05, 2006 12:20 pm     Reply with quote

i'm using an 16F870 and when i need i'll like to generate 22kHz on a pin, can any help me ?
Ttelmah
Guest







PostPosted: Wed Jul 05, 2006 3:01 pm     Reply with quote

It depends what clock rate you are running the chip at.
The CCP module, is designed to do exactly this, but the actual possible frequencies depend on the source. So if (for instance), you are running off 8MHz, you can generate a clock at 22222Hz or 21978Hz. However if you choose a crystal that is a nice multiple of 22000 (such as 8.8MHz), you can get the frequency exactly.

Best Wishes
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Thu Jul 06, 2006 2:37 am     Reply with quote

Yes, i know that .. but my problem is not the acuracy of the output but how can i generate this in C , if anybody could write some lines of code for i understand how to do it . THANK you ALL
Ttelmah
Guest







PostPosted: Thu Jul 06, 2006 4:23 am     Reply with quote

To actually 'give you the lines', we need to know the frequency.
However:

setup_ccp1(CCP_PWM);

sets the CCP, to run in PWM mode.

Then the frequency is set with:

setup_timer_2(T2_DIV_BY_1,90,1);

Which will set T2, to run from the master clock/4, and count from 0 to 90 (91 counts). With an 8MHz source,this will give 21978Hz.
Then to give a 50:50 mark space ratio, you would need:

set_pwm1_duty(182L);

Note the 'L'. The duty cycle, can count from the timer master clock, or from the actual source clock (at four times this frequency). If you give the 'duty' command, a _short_ integer, it is set in counts of the timer clock, and only has 1/4 the resolution. If you give it a 'long' integer, it is set in counts of the undivided master clock, so the possible counts are then 91*4.

I'd suggest you consider phrasing questions a bit more carefully. If you 'know' that the PWM/CCP, can give you the required frequency, then a question like:

"How do I set up the PWM, on a PIC 16F870, using C", is much more likely to get the answer. By asking for a specific frequency, and then not giving the data needed f the calculations (what frequency you are running off), you are not helping yourself get an answer quickly.

Look at ex_pwm, for an example of setting different frequencies.

Best Wishes
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Thu Jul 06, 2006 7:44 am     Reply with quote

thank you , and sorry for my phrase .

One more question .. with this code , where do i define a output pin for output this 22khz signal ?
Ttelmah
Guest







PostPosted: Thu Jul 06, 2006 8:21 am     Reply with quote

You don't. It is fixed in the hardware. On the 16F870, the CCP1 pin, is port C, pin 2. Look at the chip's data sheet. On some of the latter chips, the pin can be changed (this is normally a 'fuse' setting), but on the 870, there is only one pin supporting this feature.

Best Wishes
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