Here I'm using pic 16f877 MCU and mikroc for pic compiler to understand PWM signals.
The data sheet says that this MCU is having a 10 bit resolution in PWM. I cant understand what this resolution means. Does it mean that if I use it to power a motor I can get 1024 different speeds.
Here is a program I wrote in mikroc to gradully increase the light of a LED and again decrease it.
int i=0;
void blink_up(){
i++;
PWM1_Set_Duty(i);
Delay_ms(10);
}
void blink_down(){
i--;
PWM1_Set_Duty(i);
Delay_ms(10);
}
void main() {
trisc=0;
portc=0;
PWM1_Init(5000); //initilize PWM 1 at 5kHz
PWM1_Start();
PWM1_Set_Duty(i);
while(1){
while(i != 1023){
blink_up();
}
while(i!=0) {
blink_down();
}
}
But this wont give the expected results. The LED gradully bilnks up and suddenly switch off and again gradually blinks up. But when I change the line while(i != 1023)
to while(i != 255)
it gives the expected results.
So I want to know what the 10 bit resolution means, did I understand it wrong or am I doing anything wrong.
please help....
At last I got the solution. I'll give it because it may be helpful to somebody else.
The mikroc's pwm library don't support 10 bits. So PWM1_Set_Duty()
accepts only a number from 0 to 255. That's 0% duty to 100% duty cycle. If you want to use 10 bit resolution you should do it manually writing for registers.