Hello,
Please could you check that this c code (microchip xc8) is ok to set up the ccp module for 25khz pwm?
pic18f65k22 datasheet..
https://ww1.microchip.com/downloads/en/DeviceDoc/39960d.pdf
Please could you check that this c code (microchip xc8) is ok to set up the ccp module for 25khz pwm?
Code:
//This function sets up the CCP module into PWM mode.
//The PWM frequency is set to 25KHz for the Sanyo Denki fan
//(9HV0848P1G001)
//Note FOSC= 4MHz
void setup_CCP(void) {
T2CON = 0x00; //prescalar = 1;
PR2 = 0x27; //(pwm period = 40us by equation page 255 of pic datasheet)
CCPTMRS2 = 0x14; //CCP8 based on TMR1/TMR2
CCP4CON = 0x00; //Disable CCP4
CCP5CON = 0x00; //Disable CCP5
CCP6CON = 0x00; //Disable CCP6
CCP7CON = 0x00; //Disable CCP7
//CCP9CON = 0x00; //Disable CCP9
//CCP10CON = 0x00; //Disable CCP10
CCP8CON = 0x0C; //Enable PWM on CCP8, also set lower 2 bits of on-time
CCPR8L = 0x00; //zero duty (fan off) to start off with.
T2CONbits.TMR2ON = 1; //Enable the timer and thus the PWM.
//Note the following duty cycle settings.....
//CCP8RL = 0x0A (decimal 40 = 0.25 dutycycle
//CCP8RL = 0x14 (decimal 80 = 0.5 dutycycle
//CCP8RL = 0x1E (decimal 120 = 0.75 dutycycle
//CCP8RL = 0xFF (decimal >512 = 100% dutycycle
pic18f65k22 datasheet..
https://ww1.microchip.com/downloads/en/DeviceDoc/39960d.pdf
Last edited: