100 hz constant frequency with variable duty cycle?
Posted: Thu Jun 03, 2004 8:51 pm
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
Posted: Thu Jun 03, 2004 9:13 pm
Take a look at the PWM module. The device datasheet is a good starting point.
Guest
Posted: Sat Jun 05, 2004 9:41 pm
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
Posted: Sun Jun 06, 2004 6:50 pm
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.
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