First, let's talk about the AVR8-bit general timer register T/C0:
There is one sentence that I don't quite understand: All interrupts can be individually masked through (timer interrupt mask register) TIMSK.
Explanation: The TIMSK register is a timer/counter interrupt mask register, which means that TIMSK can mask some interrupts individually.
The definitions for internal use are: BOTTOM: The counter reaches BOTTOM when it reaches 0x00 MAX: The counter reaches MAX when it reaches the maximum value
Clock source configuration: You can choose internal clock configuration or external clock configuration.
Counter operation: For the counter, the counter count always increases. When the counter value exceeds 0xff, it starts counting again from ox00. When the TCNT0 counter is set to 0, the overflow flag TOV0 is set.
TOV0 can be cleared by the timer overflow interrupt.
/* Now we will start to explore and study the timer*/
Timer operation: First, you must set the initial value. The general steps for setting the timer are: (1) configure the TIMSK register to enable the overflow interrupt for which timer; (2) configure the TCCRX register to set the clock source signal division rate; (3) configure the TCNTX register to set the initial value.
The most important point in using the interrupt function is to map the interrupt vector address to the correct place. Generally speaking, the interrupt vector address of the timer must be configured with the 0th bit - TVOX overflow flag in the TIFR register to determine whether to enter the timer interrupt. However, in AVR, directly mapping the interrupt overflow vector in the interrupt function name can also achieve this purpose:
interrupt [TIM2_OVF] void timer2_ovf_isr(void) //TIM2_OVF is the overflow flag of timer 2
After the timer interrupt is entered, it is generally necessary to reset the initial value of the timing TCNTX, and then write the code function.
So to summarize. Timer operation:
Initialization of the timer:
(1) Configure TIMSK interrupt overflow enable
(2) Configure TCCRX timer enable
(3) Configure TCNTX timer initialization
Timer interrupt settings:
(1) Function name configuration--must be consistent with the timer interrupt variable mapping
(2) After entering the function, it is best to initialize the initial value of the timer TCNTX
Previous article:Use of AVR MCU ATMEGA8 USART
Next article:AVR counter - how to calculate the initial value of the count
- Popular Resources
- Popular amplifiers
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
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Sandia Labs develops battery failure early warning technology to detect battery failures faster
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Chinese mobile phones continue to sell well in India, Vivo surpasses Samsung to become the second largest brand
- Share CC2541 Bluetooth learning about ADC
- Summary of frequently asked questions about oscilloscopes (Part 2)
- MSP430 LCD5110 driver programming example
- NUCLEO F446RE meets X-NUCLEO-IKS01A3
- A huge reward! Looking for someone who can crack the RSA2048 and factory protocol in the ECU!
- Family Pet Health Maintenance System
- How to solve the problem that the STM32 does not run at full speed when entering the simulation debugging interface?
- HF Antenna Analyzer(3MHz to 30MHz)
- 1. Previous Power Supply Competition Topics