The 8-bit TMR2 timer has a pre-prescaler and a post-prescaler, and a cycle control register that works together with it to count the instruction cycles of the microcontroller.
TMR2 can only be used as a timer and cannot count external input pulses.
The biggest difference between TMR2 timer and TMR0 is that TMR2 has a cycle control register PR2. The PR2 register can set the upper limit of the timer. As long as the count value of TMR2 is equal to the set value of PR2, it will automatically return to 0 and generate an interrupt.
When the count value of TMR2 matches the value set in the PR2 register, the arrival of a count pulse should cause TMR2 to overflow to 0. Note: After a count overflows to 0, the TMR2IF interrupt flag is not necessarily generated immediately. When the interrupt flag is generated depends on the division ratio of the post-divider. If the selected post-divider ratio is 1:8, an interrupt will be generated only after TMR2 overflows 8 times.
//Pre-divider
//T2CKPS1 T2CKPS0
// 0 0 1 division TMR1 clock is crystal clock/(4*1)
// 0 1 4 division TMR1 clock is crystal clock/(4*4)
// 1 x 16 division TMR1 clock is crystal clock/(4*16)
//Post-divider
//TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0
// 0 0 0 0 1 division
// 0 0 0 1 2 division
// 0 0 1 0 3 division
// 0 0 1 1 4 division
// 0 1 0 0 5 division// 0 1 0
1 6 division
// 0 1 1 0 7 division
// 0 1 1 1 8 division
// 1 0 0 0 9 division
// 1 0 0 1 10-way division
// 1 0 1 0 11-way division
// 1 0 1 1 12-way division
// 1 1 0 0 13-way division
// 1 1 0 1 14-way division
// 1 1 1 0 15-way division
// 1 1 1 1 16-way division
Previous article:PIC16F877A Watchdog Timer Experiment
Next article:PIC16F877A TIMER1 counting operation
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Ultra-low standby power consumption DC-DC controller chip
- I need a simulation diagram of a car reversing radar system (paid)
- SVPWM Program
- TI C2000 interrupt service function
- Rumor has it that DJI is laying off 14,000 employees? PR Director: 14,000 in total
- About GDDFU Mode Application
- Summarize the commonly used communication interfaces of microcontrollers
- Considerations for using PMOS tube as power switch
- "Circuit Garden" by artist Kelly Heaton
- Newbie help, the light flashes five times, the buzzer sounds once, now it flashes and sounds