PIC16(L)F1786 has 3 CCP modules. I need a PWM signal on RB5 pin which belongs to CCP3 module, as well as RC6 pin. BUT, when I am setting up the PWM according to the datasheet (page 277), I am getting PWM signal on RC6 instead of RB5, even though in APFCON2 register CCP3SEL bit is set to 1. Is it even possible to get PWM on RB5 instead of RC6. And one more "BUT": I am using Proteus to test the firmware, and I am do not know is it a bug in Proteus or I am missing something. I am 99% sure I am doing something wrong since this is my 2nd day of PIC micro controller programming.
Thanks.
Below I am listing configuration and my code in MPLAB X IDE using RC8 compiler:
#pragma config FOSC = INTOSC
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config MCLRE = ON
#pragma config CP = OFF
#pragma config CPD = OFF
#pragma config BOREN = ON
#pragma config CLKOUTEN = OFF
#pragma config IESO = ON
#pragma config FCMEN = ON
#pragma config WRT = OFF
#pragma config VCAPEN = OFF
#pragma config PLLEN = OFF
#pragma config STVREN = ON
#pragma config BORV = LO
#pragma config LPBOR = OFF
#pragma config LVP = ON
#include <xc.h>
void main(void) {
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISE = 0x04;
TRISBbits.TRISB5 = 0x01;
TRISCbits.TRISC6 = 0x01;
PR2 = 0x63; // PWMPeriod = (PR2(99)+1)*4*TMR2_Prescale_Value(1)/(f(8 000 000)) = 20kHz
CCP3CONbits.CCP3M = 0x00;
// CCP3M Mode Select bits 11xx = PWM mode
CCP3CONbits.CCP3M3 = 0x01;
CCP3CONbits.CCP3M2 = 0x01;
CCPR3L = 0x32;
CCP3CONbits.DC3B = 0x00; // CCP3L:DC3B = 0x32:0x00 = 00110010 00 = 200 DEC
PIR1bits.TMR2IF = 0x00;
APFCON2bits.CCP3SEL = 0x01; // CCP3SEL: CCP3 Input/Output Pin Selection bit, if 1 then CCP3 is on pin RB5
//Timer configuration
T2CONbits.T2CKPS = 0x00; // Timer prescale value 1:1
T2CONbits.T2OUTPS = 0x00; // Timer postscale value 1:1
T2CONbits.TMR2ON = 0x01; // Enable the Timer
while(!PIR1bits.TMR2IF) // Wait until the Timer overflows and set the TMR2IF bit of the PIR1 register
{
TRISBbits.TRISB5 = 0x00; // Enable the CCP3 pin output driver
}
while(1)
{
}
return;
}