c - CCP module - PWM mode -


I am trying to make PWM output with this code, but apparently something is missing. Because when I check logic analyzer in MPLab, nothing happens on the CCP2 output. I'm working with pic18f25k80.

  void main () {// PWM CCP2CON = 0b00001100 set up; // Enable PWM on CCP2, LSB part of bits 5: 4 Duty Cycle CCPTMRS = 0B 000000; // Use timer2 for all CCP modules CCPR2L = 31; // MSB part of duty cycle TRISC = 0b00000000; Set output port as // output PORTC = 0; // clear port c // set timer 2 pr2 = 24 9; // pwm duration = (PR + 1) * 4 * TC = 1 mms TCOON = 0B00000100; // PRECLER = 1 Enable TMR2 while (1) {}}  

I hope

  • TMR2 = PR2, CCP2 output toggle
  • TMR2 keeps counting until step 1 Reaches to

    I think what it should be automatically, I mean that I do not want to write code for it because it is the work of PWM module, right? What am I missing?

Additional information:

  • The count of TMR 2 is.
  • When I PORTC = 0xFF; Add to the loop and debug the code again. All signals on port C are set except for RC2 (RC2 = CCP2 related output).
  • When I try the same code for CCP3, all the signal sets are set on port C, corresponding to RC2 and RC6 (RC 6 = CCP3).
  • When I PORTC = 0xFF; to PORTCbits.CCP2 = 1; , then only RC1 is set high.

Does this last shot mean that CCP2 has been covered by RC1 instead of RC2?


Comments