I'm desperately seeking help using the PIC18F452 with the CCS C Compiler.
Heres my code:
I have the CCP1 port hooked into an NPN transistor which should control the motor, however, it only turns on the motor for a random amount of time, and there is a random amount of delay until it repeats again. I have a 270ohm resistor on CCP1 and a pulldown of 10k.
I've tried everything but I can't get it to run continuously.
I have the MCLR pin tied to high through a 10k resistor. I've also tried directly tieing it to high, but no luck.
Please help, thank you!!
Heres my code:
Code:
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#bit TMR2IF=0xF9E.1
void main(void)
{
output_high(PIN_A0);
SET_TRIS_C(0b00000000);
SETUP_TIMER_2(T2_DIV_BY_1,128,1);
SET_PWM1_DUTY(0);
SETUP_CCP1(CCP_PWM); // PUT THE CCP1 PORT INTO PWM MODE
TMR2IF=0;
while (TRUE) {
set_pwm1_duty(120);
while (TMR2IF==0);
}
}
I have the CCP1 port hooked into an NPN transistor which should control the motor, however, it only turns on the motor for a random amount of time, and there is a random amount of delay until it repeats again. I have a 270ohm resistor on CCP1 and a pulldown of 10k.
I've tried everything but I can't get it to run continuously.
I have the MCLR pin tied to high through a 10k resistor. I've also tried directly tieing it to high, but no luck.
Please help, thank you!!