PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 05, 2013 7:14 pm |
|
|
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. |
|