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

100 hz constant frequency with variable duty cycle?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mike picking away
Guest







100 hz constant frequency with variable duty cycle?
PostPosted: Thu Jun 03, 2004 8:51 pm     Reply with quote

This is probably an easy one and may have been asked before. I want use the PIC16F876A for a 100 hz const. freq. and vary the duty cycle. HELP

Thanks Mike
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu Jun 03, 2004 9:13 pm     Reply with quote

Take a look at the PWM module. The device datasheet is a good starting point.
Guest








PostPosted: Sat Jun 05, 2004 9:41 pm     Reply with quote

I have taken your advice and understand the PWM stuff now. BUT the results I'm calculating says I need to run the processor at 1 MHz to get a 104 Hz freq. Is this correct? I was hoping to stay at 4 MHz or higher for speed. Any thoughts?
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Sun Jun 06, 2004 6:50 pm     Reply with quote

Correct. The lowest PWM frequency you can get with a 4MHz crystal is 244Hz. To create a 100Hz signal you need to use the timer interrupts.
Configure Timer2 to interrupt every 1ms (1KHz). Have a counter in the interrupt routine to count the number of interrupts. Based on the value of the counter you can toggle your output pin to create the desired duty cycle. For example if you want a 40% cycle, when the counter reaches 3 set your output pin low and when it reaches 9 set it high and reset the counter.

Here's the code for setting up Timer2:

setup_timer_2(T2_DIV_BY_4,63,4);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
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