710 PWM has two ways to output, generally by the output comparison to do PWM. It can choose Timer2 or Timer3 as its time base. The state of the output pin changes when the timer value matches the comparison register value
The output comparison module has 7 modes of operation
Low/High Active single event mode
- Flip Mode
- Delay Single Event mode
- Continuous Single Event mode
- PWM mode without fail-safe
- PWM mode with fail-safe
Ocm<2:0> to choose the comparison mode, how to choose to see the chip data bar, 178 pages
The detailed initialization code for the PWM is as follows (OC1 is selected, a total of 9. OC1-OC8)
1 //Initialize Output Compare Module2OC1CONBITS.OCM = 0b000;//Disable Output Compare Module3OC1R = -;//Write the duty cycle for the first PWM pulse4Oc1rs = $;//Write the duty cycle for the second PWM Pulse5Oc1conbits.octsel =0;//Select Timer2 As output compare time base6OC1R = -;//load the Compare Register value (load compare memory values)7OC1CONBITS.OCM = 0b110;//Select the PWM mode8 9 Ten //Initialize and enable Timer2 OneT2conbits.ton =0;//Disable Timer AT2conbits.tcs =0;//Select internal instruction cycle clock (select internal instruction cycle clocks)) -T2conbits.tgate =0;//Disable Gated Timer mode -T2CONBITS.TCKPS = 0b00;//Select 1:1 prescaler the -TMR2 =0x00;//Clear Timer Register -PR2 = -;//load the period value (load cycle value) - +Ipc1bits.t2ip =0x01;//Set Timer2 Interrupt Priority level -Ifs0bits.t2if =0;//Clear Timer2 Interrupt Flag +Iec0bits.t2ie =1;//Enable Timer2 Interrupt A atT2conbits.ton =1;//Start Timer
Only the first half of the PWM can be initialized. The back allows Timer2 to be put in other places.
"Single-Chip" "710" PWM