Hi I'm doing PWM on my little project this Christmas eve and I'm hoping to finish it earlier. My hardware is done and same as with the software but I would like to add some PWM effects for it to look good. Can you help me out?
I'm trying to make LEDs fade and thought of using mikroC PRO for PIC's PWM. I used it but it is not that visible. I'm using PIC16f877a and a crystal OSC of 20Mhz. Can you check the problem on my source code?
On my schematic my PORTD was the output.
The problem is that even PortC.F2 was not set above as an output, it blinks (Is it because it is CCP1?) and it even shows a fade effect which was supposedly to be seen on PORTD because I used on them PWM1_Set_duty. LEDs on PORTD are just steady logic 1. They are not showing any fade effect.
I'm trying to make LEDs fade and thought of using mikroC PRO for PIC's PWM. I used it but it is not that visible. I'm using PIC16f877a and a crystal OSC of 20Mhz. Can you check the problem on my source code?
Rich (BB code):
void InitMain() {
Adcon1 = 6;
cmcon = 7;
TRISD = 0; // designate PORTD pins as output
PWM1_Init(1500); // Initialize PWM1 module at 5KHz
}
void main() {
InitMain();
PWM1_Start(); // start PWM1
while (1) { // endless loop
PORTD = 0xFF;
Delay_ms(1000);
PWM1_Set_Duty(85); //duty cycle = 85%
PORTD = 0xFF;
Delay_ms(1000);
PWM1_Set_Duty(40); //duty cycle = 40%
PORTD = 0xFF;
Delay_ms(1000);
PWM1_Set_Duty(5); //duty cycle = 5%
}
}
The problem is that even PortC.F2 was not set above as an output, it blinks (Is it because it is CCP1?) and it even shows a fade effect which was supposedly to be seen on PORTD because I used on them PWM1_Set_duty. LEDs on PORTD are just steady logic 1. They are not showing any fade effect.