0240; pwm_config; 002C; MOVLB 0xC; 0241; ; 30FF; MOVLW 0xFF; 0242; ; 0092; MOVWF 0x12; PWM1DCH 0243; ; 0095; MOVWF 0x15; PWM2DCH 0244; ; 0098; MOVWF 0x18; PWM3DCH 0245; ; 009B; MOVWF 0x1B; PWM4DCH 0246; ; 0191; CLRF 0x11 ; PWM1DCL 0247; ; 0194; CLRF 0x14 ; PWM2DCL 0248; ; 0197; CLRF 0x17 ; PWM3DCL 0249; ; 019A; CLRF 0x1A ; PWM4DCL 024A; ; 3000; MOVLW 0x0 ; 024B; ; 0093; MOVWF 0x13; PWM1CON 024C; ; 0096; MOVWF 0x16; PWM2CON 024D; ; 0099; MOVWF 0x19; PWM3CON 024E; ; 009C; MOVWF 0x1C; PWM4CON 024F; ; 0020; MOVLB 0x0 ; 0250; ; 1091; BCF PIR1, 0x1; Priority Interrupt 0251; ; 30FF; MOVLW 0xFF; 0252; ; 009B; MOVWF PR2 ; timer 2 period = 4.096ms 0253; ; 3007; MOVLW 0x7 ; prescaler set to 64 0254; ; 009C; MOVWF T2CON; timer 2 control 0255; ; 0008; RETURN;
Microcontrollers vary the speed of a motor through Pulse-Width Modulation (PWM). The code above sets the largest possible pulse width for Timer2. The duty cycle of that Pulse Width is then set proportionally by the value given to PWMxDCH and PWMxDCL.