PIC16F1509 - PWM and LED fade
Posted: 15 Oct 2014 00:15
Hi everybody!
I'm trying making a led pulse on and off smoothly with PWM output of a PIC16F1509.
I write this code in mikroC:
I'm trying making a led pulse on and off smoothly with PWM output of a PIC16F1509.
I write this code in mikroC:
Code: Select all
unsigned int d;
void InitMain() {
ANSELA = 0;
ANSELB = 0;
ANSELC = 0;
C1ON_bit = 0;
C2ON_bit = 0;
PORTB = 0;
TRISA = 0x00;
TRISB = 0b00100000;
PORTC = 0;
TRISC = 0;
PWM1_Init(500);
Delay_ms(100);
}
void main() {
InitMain();
PWM1_Start();
while (1) {
for(d=0;d<1024;d++){
PWM1_Set_Duty(d);
Delay_ms(10);
}
for(d=1024;d>0;d--){
PWM1_Set_Duty(d);
Delay_ms(10);
}
}
}
- I noticed that when the d index is equal to 0 or 1024, the PWM signal is kinda mirrored vertically for a while...why does it happen?
- Anyway when I set PWM duty cycle to 0, the led never turn off at all and I cannot understand the reason of it. Any ideas?
- How to understand exactly what value insert in PWM1_Init() function (the PIC is working @0.5MHz)?