[Menu]>[Guide to use the PIC]>[628 Hardware]
The PIC16F873 has a special feature as CCP.
Because a CCP function is the same as that of PIC16F873, so some part of pages for PIC16F873 are used in the following explanation.CCP is the initial of Capture/Compare/PWM(Pulse Width Modulation). PIC16F873 has one CCP module.
The timer resource of the capture and compare is timer1 and the timer resource of PWM is timer2. CCP1 register is comprised of two 8 bits registers : CCPR1L for low byte and CCPR1H for high byte. The CCP1CON register controls the operation of CCP1. The special event trigger is generated by compare match and will reset Timer1. Capture mode In Capture mode, CCPR1H : CCPR1L captures the 16 bits value of the TMR1 register when an event occurs on pin RB3/CCP1. In Capture mode, the RB3/CCP1 pin should be configured as an input by setting the TRISC register. If the RB3/CCP1 pin is configured as an output, a write to the port can cause a capture condition.
Timer1 must be running in timer mode or synchronized counter mode for the CCP module to use capture feature. In asynchronous counter mode, the capture operation may not work. When the capture mode is changed, a false capture interrupt may be generated, You should keep bit CCP1IE of PIE register clear to avoid false interrupts and should clear the flag bit CCP1IF of PIR1 register following any such change in operating mode. Compare mode In Compare mode, the 16 bits CCPR1 register value is constantly compared against the TMR1 register pair value.
Timer1 must be running in timer mode or synchronized counter mode for the CCP module to use compare feature. In asynchronous counter mode, the compare operation may not work. PWM mode In PWM(Pulse Width Modulation) mode, the CCP1 pin produces up to a 10 bits resolution PWM output.
The PWM period is specified by the value of the PR2 register, the clock oscillation period and the prescaler value of Timer2. The PWM duty cycle( the output stays high ) is specified by the value of CCPR1L register, the clock oscillation period and the prescaler value of Timer2. The CCPR1L contains the eight MSbs and CCP1X:CCP1Y contains the two LSbs. The shortest duty cycle is the period time of the oscillator. In case of 10MHz oscillator, it is 0.1 microseconds. The maximum PWM resolution of the duty cycle is 1024. If the PWM duty cycle value is longer than the PWM period, the CCP1 pin will not be cleared. Also, if the value of PWM duty cycle register( CCPR1L+CCP1X+CCP1Y ) is set to zero, the CCP1 pin will not be set. For the details about PWM period and PWM duty cycle, refer to the page of PIC16F873. |