PIC18F2550 PWM Square wave generator
I ended up changing my code to this. Now I am getting a 3khz PWM signal of square pulses.

The prescaler was increased from 4 to 16 and I assigned most bits individually. Im not 100 % sure yet what the mistakes were in my earlier code.

#include &lt;xc.h&gt;

/*Function prototypes*/
void initChip(void);
void initPWM(void);

void main(void) {
initChip();
initPWM();
while(1);
}

void initChip(void)
{
PORTB = 0x00; //Initial PORTB
TRISB = 0x00; //Define PORTB as output
PORTC = 0x00; //Initial PORTC
TRISC = 0x00; //Define PORTC as output
INTCONbits.GIE = 0; // Turn Off global interrupt
}

void initPWM(void)
{
PR2 = 0xFF;
CCPR2L = 0x7F; // 
CCP2CONbits.DC2B0 = 0;
CCP2CONbits.DC2B1 = 0;
TRISB = 0x00; // Clear Tris registers
TRISC = 0x00;
T2CONbits.T2CKPS1 = 1; // Timer 2 Prescaler = 16
T2CONbits.T2CKPS0 = 1;
T2CONbits.TMR2ON = 1; // Enable Timer 2
CCP2CONbits.CCP2M3 = 1; // Set CCP as PWM
CCP2CONbits.CCP2M2 = 1;
}