Question

here im using pic 16f877 MCU and mikroc for pic compilerto understand PWM signels. the data sheet says that this MCU is having a 10 bit resolution in PWM. I cant understand what this resolution means. does it means 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 suddnly switch off and again gradully blinks up. but when i change the line while(i != 1023) to `while(i != 255) it gives the expected results.

so I want toi know whats the 10 bit resolution means, did i understand it wrong or am i doing enything wrong.

please help....

Was it helpful?

Solution

at last I got the solution. il give it because it may be helpful to somebody else.

the mokroc's pwm library dont support 10 bits. so PWM1_Set_Duty() accepts only a number from 0 to 255. thats 0%duty to 100% duty cycle. if you want to use 10 bit resolution you should do it manully writting for registers.

OTHER TIPS

Now that you have successfully managed to get your code working, try using the internal PIC registers. A resolution of 10 bits is way more powerful for, let's say, RGB led's than 8bit. It's not that hard to get it to work by yourself, it's written directly in the datasheet and there's a lot of website granting you with functions for calculating the duty cycle and the frequency of your PWM module.

The datasheet for CCP (PWM) mode from MicroChip: http://ww1.microchip.com/downloads/en/DeviceDoc/31014a.pdf

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top