hi folks,
does any body know how can we use all 10 bits of PWM Mode in microC?
My microcontroller is PIC16F877A
i am working on a project witch needs pwm duty change with exactly 10 bit resolution, and i thing the " Pwm_Change_Duty " just use the 8 MSbs in CCPRxL, and this resolution is not enough for me. as mentioned in micro datasheet, the other 2 LSbs of PWM can be found in CC1PCON, bit 4 and 5, but i dont know how to use them in changing my duty cycle.
PWM Resolution
Hi,
Our developers are familiar of this problem (see: http://www.mikroe.com/forum/viewtopic.p ... 014#113014) and you will be informed when we come up with a complete solution to the issue.
Best regards,
Aleksandar
Our developers are familiar of this problem (see: http://www.mikroe.com/forum/viewtopic.p ... 014#113014) and you will be informed when we come up with a complete solution to the issue.
Best regards,
Aleksandar
Web Department Manager
here is the 10bit PWM code that I wrote 2 years ago for 18F8722. You can find information about PWM flags at microchip datasheet of 18f8722 p184-p186. I think it is very easy to rewrite this code for 16F877 as you require.
Code: Select all
/********************************************************
* 10-bit PWM code for PIC18F8722 IC *
* by Deniz ELMASLI *
* Version 2.2 *
* First Release : 24.10.2008 - 10:12 Thursday *
* Last Revision : 25.01.2008 - 12:59 Tuesday *
* Ide(s) : MikroC V7.0 *
* Target Platform: PIC *
* MCU : 18F8722 *
* Contact: elmasli@gmail.com *
* Web : www.dronology.com *
* *
* This code in intended to work with PIC IC. Its *
* purpose is using MCU's 10-bit PWM property. *
* ver 2.2: start function is optimized *
*******************************************************
*/
// initialization function
void PWM_10bits_init(){
PR2 = 0b11111111 ;
T2CON = 0b00000111 ;
}
// PWM1 port start (it will generate 0V on corresponded pin
void PWM_10bits_start4(){
CCPR4L = 0b00000000 ;
CCP4CON = 0b00001100 ;
}
// main PWM function. This function generates voltage output according to given parametric value
void PWM_10bits_duty4(int val){
int LSB2bits;
int MSB8bits;
if(val > 1023)
val =1023;
if(val < 0)
val =0;
LSB2bits = serials(val);
//check the datasheet.
if(LSB2bits ==0)
CCP4CON = 0b00001100;
else if(LSB2bits ==1)
CCP4CON = 0b00011100;
else if(LSB2bits ==2)
CCP4CON = 0b00101100;
else if(LSB2bits ==3)
CCP4CON = 0b00111100;
//PORTB=LSB2bits ;
MSB8bits = ((val-LSB2bits) >> 2);
//PORTD = LSB2bits;
CCPR4L = MSB8bits ;
}
R. Giskard Reventlov & R. Daneel Olivaw
http://www.circuitechs.com
http://www.dronology.com
http://www.circuitechs.com
http://www.dronology.com