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

Timer2 on pic 18f4550 with PLL5 (USB)

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



Joined: 21 Dec 2011
Posts: 42

View user's profile Send private message

Timer2 on pic 18f4550 with PLL5 (USB)
PostPosted: Sun Feb 19, 2012 2:29 pm     Reply with quote

Hi,

I use a pic 18f4550 with a 20Mhz cristal... with fuses and code from CCS, I'm able to communicate in CDC mode with the pc (PLL for USB).

Code:
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,PUT,BROWNOUT
#use delay(clock=48M)


Now, i could use interruption of timer2 for generate a pwm signal... But i can't setting it correctly.

Code:
setup_timer_2(T2_DIV_BY_1,1,1);
      set_timer2(0);
      enable_interrupts(global);
      enable_interrupts(INT_TIMER2);



T2_div_by_1 or T2_div_by_16.... any change...I don't understand what happen...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 19, 2012 3:23 pm     Reply with quote

Don't enable interrupts for PWM. It's not necessary. Here is a sample
PWM program to get you started:
http://www.ccsinfo.com/forum/viewtopic.php?t=45185&start=1
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Feb 19, 2012 3:40 pm     Reply with quote

Also, as a comment, if you did want to use an interrupt off timer2 (nothing to do with PWM), the values used would prevent the chip doing _anything_ useful.
T2_DIV_BY_1 means run timer2, off the master oscillator/4 (one instruction per count). Then you are telling the timer to reset after just 2 counts (the '1' in the next location, plus one), and to interrupt every time the timer resets (the final '1'). Result, would be an interrupt every 2 instructions. Since it takes about 60 instructions to actually get into and out of an interrupt handler, the chip would sit permanently jumping into the interrupt handler.....
Ouch...

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