Among them, 0, 1, 2, and 3 have PWM functions, and each has an output pin, which can be controlled by a timer to periodically change the high and low levels of the pin;
The timer has no output pins;
1. Timer clock source
The clock source of the timing component is PCLK, which is first reduced in frequency by two 8-bit prescalers;
Timers 0 and 1 share the first prescaler;
Timers 2, 3, and 4 share the second prescaler;
The output of the pre-divider will enter the second-stage divider and output 5 kinds of clock frequencies: 2-division, 4-division, 8-division, 16-division, and external clock TCLOK0/TCLK1;
The working clock of each timer can be selected from these 5 frequencies;
2. Working Principle of Timer
1. Set the two registers TCMPBn and TCNTBn, which represent the comparison value and initial count value of timer n;
2. Start timer n, and by setting TCON, the values of TCMPBn and TCNTBn are loaded into TCMPn and TCNTn.
At the operating frequency of timer n, TCNTn starts to count down by 1, and its value can be read through the TCNTOn register;
3. When the value of TCNTn is equal to the value of TCMPn, the output pin TOUTn of timer n is reversed;
TCNTn continues to count down by 1;
4. When the value of TCNTn reaches 0, its output pin TOUTn reverses again and triggers the interrupt of timer n (if the interrupt is enabled);
5. If timer n is set to "auto load" in the TCON register, the values of the TCMPB0 and TCNTB0 registers are automatically loaded into TCMP0 and TCNT0, starting the next counting process.
The output pin TOUTn of timer n is initially in high level. When the value of TCNTn is equal to the value of TCMPn or the value of TCNTn is equal to 0, a reversal will occur.
You can also set its initial level through the TCON register, so that the output of TOUTn is completely inverted.
By setting the values of TCMPBn and TCNTBn, the duty cycle of the output signal of pin TOUT can be set. This is called modulated pulse (PWM), so these timers are also called PWM timers.
3. Register Usage
1.TCFG0
[7:0] and [15:8] are used to control prescaler 0 and 1 respectively. The clock frequency output from the prescaler is: PCLK/(perscaler value + 1);
2. TCFG1
Set the second level frequency division,
【3:0】Set timer 0
【7:4】Set timer 1
【11:8】Set timer 2
【15:12】Set timer 3
【19:16】Set timer 4
0b0000——1/2
0b0001——1/4
0b0010——1/8
0b0011——1/16
0b01xx——External TCLK0/TCLK1;
3.TCNTBn
4.TCMPPBn
Without TCMPBn, Timer 4 has no output pin
5.TCNTOn
6. TCON
TCON has four functions:
(1) When the timer is started for the first time, the values of TCNTBn and TCMPBn are loaded into TCNTn and TCMPn;
(2) Start and stop the timer;
(3) Set up automatic reload;
(4) Set whether TOUTn is reversed;
【3:0】For timer 0
【11:8】For timer 1
【15:12】For timer 2
【19:16】For timer 3
【22:20】For timer 4, no output pin inversion bit
Bit 0: 0——stop the timer, 1——start the timer;
Bit 1: 1 - Load the values of TCNTBn and TCMPBn into TCNTn and TCMPn;
Bit 2: 0——TOUTn is not inverted, 1——TOUTn is inverted;
Bit 3: 0——do not load automatically, 1——load automatically;
When using the timer for the first time, you need to set "bit 1" so that the value of TCNTBn/TCMPBn is loaded into TCNTn and TCMPn.
Previous article:Design and implementation of an electric barrier controller
Next article:Design and implementation of intelligent controller for high-speed real-time data acquisition
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- [RVB2601 Creative Application Development] 5 Display letters AB at the same time, and eliminate them by long pressing and short pressing
- How to quickly test the continuity and sequence of wire harnesses using the ATX-100S wire harness tester?
- [FreeRTOS check-in station 5 opens] Interrupts and task switching, closing time is August 26
- How do satellite communications work from space?
- Important considerations in smart speaker design: pros and cons of design
- Domestic core TLSR8285 / TLSR8278 multi-protocol wireless chip
- Definition of priority order of MSP430 microcontroller interrupts
- Discuss power supply and design issues
- Introduction to the working principles of accelerometers and gyroscopes, and AlgoBuilder Tool
- Talking about Flyback Converter