Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Switch from 877A to 887 > PWM > open source

Status
Not open for further replies.

Eric_O

Advanced Member level 4
Joined
May 31, 2020
Messages
104
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
996
Chers programmeurs,
My 16F877 failed. I replaced it with 16F887 on the labdeck because I had in spare parts.
In order to save time do some body have the routines PWM_init() and PWM_setdutycycle(unsigned int dutycycle) in open source MikroC ?
While waiting, I try to use datasheets.
Merci beaucoup !
 

Hello Eric,

PWM_setdutycycle(unsigned int dutycycle) means you are looking for 10 bits mode ?
else dutycycle is only with 8 bits 0 to 255

this example for 18F26K22 , 10 bits dutycycle
Code:
Print_Cte_String(" Init PWM1 10bits at 1000Hz on RC2 \r\n");

     TRISC2_bit = 1; //set TRIS bit
   // CCPTMRS0: PWM TIMER SELECTION CONTROL REGISTER
    CCPTMRS0 = 0x00; //select timer resources, Timer2 for CCP1 and all others, page 208
    PR2 = 0xff; // load with PWM period value (fixed at 1 kHz at 16Mhz)
    //CCPxCON
    // bit 7-6 PxM<1:0>: Enhanced PWM Output Configuration bits
    //00 = Single output; PxA modulated; PxB, PxC, PxD assigned as port pins
    // bit 5-4 DCxB<1:0>: PWM Duty Cycle Least Significant bits
    //Half-Bridge ECCP Modules(1):
    //1100 = PWM mode: PxA active-high; PxB active-high
    CCP1CON = 0b00001100; // setup for PWM mode 5:4 are PWM Duty Cycle LSB
    CCPR1L = 0x00; // eight high bits of duty cycle
 //   T2CON = 0b00000101; // Timer2 On, 1:1 Post, 4x prescale at 8MHz
 // PWM at 1KHz
    T2CON = 0b00000110; // Timer2 On, 1:1 Post, 16x prescale  at 16MHz
  //   T2CKPS1_bit=1;// Timer2-type Clock Prescale Select bits  =1/16
  //  T2CKPS0_bit=1
    TRISC2_bit = 0;
    IRatio=0;
    CCP1CON.DC1B0 = IRatio & 1; //set low bit
    CCP1CON.DC1B1 = (IRatio >> 1) & 1;  //set second lowest
    CCPR1L = (IRatio >> 2); //set highest eight
  CRLF1();

// test cde PWM via clavier terminal
   // mode pooling SANS interrupt

   RCIE_bit=0;
   txt=&TEXTE[0];
   Print_Cte_String(" Entrer la consigne PWM via le clavier : valeur  0 à 1023  + terminaison <CR> \r\n");
   while(1) // do forever
    {
    if (UART1_Data_Ready())
     {
      UART1_Read_Text(txt,"\r",5);
      UART1_Write_Text(txt);
      CRLF();
      IRatio=atoi(txt);
      PWM1_Set_10b_Duty(IRatio);
      }
     txt=&TEXTE[0];
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top