Using chip AT Mega16 external crystal oscillator 4.00MHz
Timer 1 (16-bit timer) register TCCR1B = 0x04 Set 256 prescaler
To use the timer for 1 second
1, 4000000 / 256 = 15625 means the timer will trigger an interrupt every 1/15625 seconds
2, 65535 - 15625 = 49910 Calculate how many times to accumulate to trigger the overflow interrupt of timer 1 after 1 second
3, 49910 <==> C2 F6 Convert the calculated value into hexadecimal
4, TCNT1H = 0xC2; Assign register
TCNT1L = 0xF6;
================================================== ===========================
For example, using 16-bit timer TIMER1, 4MHZ crystal, 256 division, 100ms timing, how to get the initial value to assign to TCNT1?
65536-(4M/256)*0.1=63973.5
Among them, 4M is the crystal frequency, and 0.1 is the timing duration in seconds.
For an 8-bit timer,
T = (2^8-counting initial value) * crystal period * frequency division = (2^8-counting initial value) / crystal frequency * frequency division
Counting initial value = 2^8-T / crystal period / frequency division = 2^8-T * crystal frequency / frequency division
Because AVR one instruction one cycle
Previous article:IAR For AVR Precision Delay
Next article:IAR For AVR USART Application
Recommended ReadingLatest update time:2024-11-16 23:37
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Metronom Real-Time Operating System RTOS for AVR microcontrollers
- IAR fully supports the new industrial-grade PX5 real-time operating system
- Learn C language for AVR microcontrollers easily (with video tutorial) (Yan Yu, Li Jia, Qin Wenhai)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- 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
- Teaching flowchart template sharing
- Does anyone know why bluenrg_2 adds +2 to the feature value when subscribing to it?
- In the 51 MCU serial communication mode 1, what kind of clock does timer 1 provide to the serial port module?
- Why does the Ethernet interface circuit need to be connected to GND through resistors and capacitors?
- Features and main applications of TI wireless connectivity products
- (A-Current Signal Detection Device) First Prize of Shandong Province_Topic A_Qingdao University of Technology
- Read the good book "Operational Amplifier Parameter Analysis and LTspice Application Simulation" 05 Offset Voltage Case Analysis
- Automotive External Amplifiers
- Award-winning live broadcast | Firmware upgrade solution for Renesas MCU
- Into space: Solid-state power amplifiers aid space exploration