PWM Resolution

General discussion on mikroC.
Post Reply
Author
Message
abtinst
Posts: 1
Joined: 27 Oct 2009 17:01

PWM Resolution

#1 Post by abtinst » 27 Oct 2009 17:56

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.

marco
Posts: 57
Joined: 03 Jan 2008 20:34

#2 Post by marco » 09 Dec 2009 13:29

hello my freind!

I´m want to use 10 bits of PWM just like you.
have you done it all ready?
if any one coud explayne me how to configurate it !

thanks.

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#3 Post by anikolic » 11 Dec 2009 14:56

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
Web Department Manager

marco
Posts: 57
Joined: 03 Jan 2008 20:34

#4 Post by marco » 11 Dec 2009 17:59

ok

thanks once again my friend !

Madman07
Posts: 37
Joined: 06 Sep 2008 18:23
Location: Poland, Rawicz

#5 Post by Madman07 » 16 Dec 2009 09:07

There is easy way to get 10 bit PWM:

http://www.mikroe.com/forum/viewtopic.php?t=17449
P.S. Sorry for my bad English :)

dronology
Posts: 106
Joined: 29 Dec 2007 23:48
Location: istanbul
Contact:

#6 Post by dronology » 22 Dec 2009 11:18

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

Post Reply

Return to “mikroC General”