1 out of 1 members found this post helpful.
Did you find this post helpful?

|
Re: Infrared HPWM setup
why have we shifted?
CPRxL value is the upper 8 bits of the duty cycle word valueCCP1CON bit 4 and 5 are the lower two bits
(011010010) 210>>2 = 00110100 = 52 ;high 8bits
(011010010) 210 & 3 = 00000010 = 2 ;low 2 bits
00000010<<4 = 00100000
CCP1CON = 00100000 |12 to set low bits in pwmmode
C version from microchip
Code:
void PWM1_LoadDutyValue(uint16_t dutyValue)
{
// Writing to 8 MSBs of pwm duty cycle in CCPRL register
CCPR1L = ((dutyValue & 0x03FC)>>2);
// Writing to 2 LSBs of pwm duty cycle in CCPCON register
CCP1CON = ((uint8_t)(CCP1CON & 0xCF) | ((dutyValue & 0x0003)<<4));
}
Last edited by richard; - 1st June 2023 at 08:07.
Warning I'm not a teacher
Bookmarks