PWM configuration with Timer2

Thread Starter

ep.hobbyiest

Joined Aug 26, 2014
172
i want to use pwm in my project. I am using pic16f18875 controller and xc8 compiler.
i have configured the pwm and i was configuring timer 2 for that. But i am not getting the pwm output.

I am trying to understand the use of register TxRST in timer.I want to understand the use of TxRST register. currently i have set the register value as 0xFF.

here is my code for pwm and timer register

Code:
void PWM1_Initialize(void)
{
    // Set the PWM1 to the options selected in the User Interface
   
    // MODE PWM; EN enabled; CCP1FMT right_aligned;
    CCP1CON = 0x8F;  
   
    // RH 0;
    CCPR1H = 0x00;  
   
    // RL 0;
    CCPR1L = 0x00;  

    // Selecting Timer 2
    CCPTMRS0bits.C1TSEL = 0x1;
    CCP1PPS = 0x12;
}

void PWM1_LoadDutyValue(uint16_t dutyValue)
{
    dutyValue &= 0x03FF;
   
    // Load duty cycle value
    if(CCP1CONbits.CCP1FMT)
    {
        dutyValue <<= 6;
        CCPR1H = dutyValue >> 8;
        CCPR1L = dutyValue;
    }
    else
    {
        CCPR1H = dutyValue >> 8;
        CCPR1L = dutyValue;
    }
}

uint8_t PWM1_OutputStatusGet(void)
{
    // Returns the output status
    return(CCP1CONbits.OUT);
}

void initTimer2(void)
{
    T2CLKCON = 0x01;
    T2CON = 0x80;
    T2HLT = 0x00;
    T2RST = 0xFF;  
}
 
Last edited:
Top