// PWM frequency:
// 0 - 48 kHz
// 1 - 12 kHz
// 2 - 3 kHz
enum { MOTOR_FREQUENCY = 1 };
// Configure Timer 2 w. 250x period.
T2CON = 1 << 2 | MOTOR_FREQUENCY /* << 0 */;
Have i understood this right?
11111111 Arithmetic left-shift-by-two of 0 or 1 or 2
Means:
T2CON = 1 << 2 | 0 = 1111 1100
T2CON = 1 << 2 | 1 = 1111 1000
T2CON = 1 << 2 | 2 = 1111 0000
Kind Regards, Sonite
Context:
TCON2is a timer register on PIC MCUs, where the last two bits configure the prescaler.T2CKPS[1:0]=0b00= 0 => /1 prescalerT2CKPS[1:0]=0b01= 1 => /4 prescalerT2CKPS[1:0]=0b1x= 2 or 3 => /16 prescalerBit 2 actually switches the timer on, so it always needs to be set to do anything, hence the
1 << 2(which really should be written as1 << T2CON_TMR2ON_bitwithT2CON_TMR2ON_bitbeing defined in some CPU-configuration header)All said and done, the three settings are
0b100,0b101, and0b110, which turn on the timer, and tweak the prescaler to get those frequencies mentioned in the comments.Also, using an
enumwith one element is just about pointless; use#define.