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 support@ccsinfo.com

120 KHz Carrier Signal

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



Joined: 28 Jul 2009
Posts: 10

View user's profile Send private message

120 KHz Carrier Signal
PostPosted: Thu Feb 18, 2010 5:10 am     Reply with quote

Hi Everyone,

I try to obtain 120 KHz carrier signal with using pwm module of pic 16f877 . PWM uses timer2 and maximum frequency value is 250 Hz because pr2 maximum value is 255 and postscale maximum value is 16. And the formula is :

Tpwm=Tcommand*(pr2 + 1)*(tmr2 division ratio)

And here is the code below. How can i obtain 120KHz signal with pwm.

regards
Code:

#include <16f877.h>   

#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD

#use delay (clock=4000000)

#use fast_io(c)

void main ( )
{
   setup_psp(PSP_DISABLED);       
   setup_spi(SPI_SS_DISABLED);     
   setup_timer_1(T1_DISABLED);     
   setup_adc_ports(NO_ANALOGS);   
   setup_adc(ADC_OFF);             

   set_tris_c(0x00);

   setup_ccp1(CCP_PWM); 

   setup_timer_2(T2_DIV_BY_16,255,16);

   set_pwm1_duty(30);

   while(1);

}
monsters_inc



Joined: 18 Jan 2010
Posts: 14

View user's profile Send private message

PostPosted: Thu Feb 18, 2010 5:53 am     Reply with quote

Hi. With oscillator of 4MHz you can't obtain exact 120Khz. You can obtain 125Khz.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Feb 18, 2010 6:01 am     Reply with quote

A handy PWM calculator: http://www.micro-examples.com/public/microex-navig/doc/097-pwm-calculator.html
It will show you a table with all possible frequencies.



Code:
setup_spi(SPI_SS_DISABLED);
This is an invalid configuration and may cause problems. Change to
Code:
setup_spi(FALSE);
Ttelmah
Guest







PostPosted: Thu Feb 18, 2010 8:14 am     Reply with quote

I have a strange suspicion, he may be after 120Hz (not 120kHz...). 244Hz, is the _minimum_ frequency from the PWM (all dividers at maximum), with a 4MHz crystal, which is what he shows.
A search here will find some answers.
Generally the 'point' of the PWM, is to allow frequencies _above_ those that can be handled by other solutions, to be generated without too much processor overhead. A 120Hz PWM, can be generated by using a normal timer interrupt instead.
The 'answer' depends massively on what is really required. Number of resolution steps, what else the processor needs to do at the same time, etc. etc..

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