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

pgen
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 7:14 pm     Reply with quote

Quote:
Why the LOOPCNT = 39?

How did you get that number?

With a 4 MHz oscillator, the PIC's internal clock for incrementing Timer0
is 1 MHz. That's 1/4 of the oscillator frequency. This is given in the PIC
data sheet.

Timer0 counts from 0 to 255 and rolls over to 0 and does it again.
When it rolls over from 255 to 0, it causes a Timer0 interrupt.
So it has 256 counts (at 1 MHz) per #int_timer0 interrupt.

So the Timer0 interrupt rate is:
Code:

  1 MHz
 ------- = 3906.25 Hz
   256

But you want 100 Hz, so that means 3906/39 = 100 Hz (approximately).


Quote:
I am trying to make a soft pwm 1 to 30 hz....

Normally, PWM has a constant frequency. The duty cycle of the pulse
controls the amount of output power (for motor speed, or light bulb
brightness, etc). For the example code given in this thread, the PWM
frequency is a constant 100 Hz.
matheuslps



Joined: 29 Sep 2010
Posts: 73
Location: Brazil

View user's profile Send private message MSN Messenger

PostPosted: Fri Dec 06, 2013 6:24 am     Reply with quote

Hum.... very clever this kind of code.

Liked it.

Thanks for the reply.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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