I am trying to generate a square wave on 50% Duty Cycle using my PIC18F2550. The signal is to be outputted through a loudspeaker. The frequency does not really matter, as long as it is in the hearing range (a few Khz should do).
This is my rather simplistic code;
#include "xc.h"
void PWM_init(void);
void Chip_init(void);
void main(void){
Chip_init();
PWM_init();
while(1);
}
void PWM_init(void) {
/****Set All PWM Registers*****/
PR2 = 0b11111111;
T2CON = 0b00000111;
CCPR2L = 0b01111111;
CCP2CON = 0b00111100;
}
void Chip_init(void){
/** Initialize all outputs ****/
LATCbits.LATC1 = 0;
TRISCbits.TRISC1 = 0;
LATBbits.LATB3 = 0;
TRISBbits.TRISB3 = 0;
}
This should give me a PWM signal of about 3Khz on either C1 or B3, atleast to my understanding. But i am getting nothing, unfortunately. Can anyone tell me where I went wrong?