PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 28, 2006 4:01 pm |
|
|
The 18F452 doesn't have a Power PWM module. It only has a normal
PWM module.
Here is a thread which discusses using the PWM output as a clock source:
http://www.ccsinfo.com/forum/viewtopic.php?t=27712
If you take the code shown in that thread, and use an 8 MHz crystal
in 4x PLL mode (so it runs at 32 MHz), then you can get a 4 MHz clock
signal from the CCP1 pin. I tested this and it works.
You can't do it when running at 40 MHz (with a 10 MHz crystal) because
the Timer2 is clocked at Fosc/4, which is 10 MHz. To get a 4 MHz PWM
output, you would need to divide by 2.5, and you can't do that.
That's why you must run it at 32 MHz (with an 8 MHz crystal).
Example:
Code: |
#include <18F452.h>
#fuses H4,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=32000000)
//================================
void main()
{
setup_timer_2(T2_DIV_BY_1, 1, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(4L);
while(1);
} |
|
|