IAR For AVR timer interrupt initial value calculation method

Publisher:快乐的成长Latest update time:2016-10-06 Source: eefocusKeywords:IAR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Keywords:IAR Reference address:IAR For AVR timer interrupt initial value calculation method

Previous article:IAR For AVR Precision Delay
Next article:IAR For AVR USART Application

Recommended ReadingLatest update time:2024-11-16 23:37

AVR BOOTLOADER Technology Detailed Explanation
ATmega128 has the user program self-programming function supported by boot loading (In-System Programming by On-chip Boot Program), which provides a real system program self-programming update mechanism for the MCU itself to automatically download and update (using the "Read-While-Write" method) the program co
[Microcontroller]
AVR Development Arduino Method (VI) Memory Subsystem
  The Arduino UNO R3 main processor ATMega328P has three types of memory inside the chip: data memory, program memory and electrically erasable programmable memory; each of them has different uses. 1. Data storage   The data memory is a 2KB static random access memory (SRAM). Part of the space is allocated to genera
[Microcontroller]
AVR microcontroller drives digital tube display through 74HC595
A very simple simulation of an AVR microcontroller, using a 74hc595 chip to drive a single digital tube to display numbers. The following is the simulation schematic diagram   Source program: #include iom16v.h #include macros.h void delay(int k){          int i=0,j=0;          for(i=0;i k;i++){              for(j=
[Microcontroller]
AVR microcontroller drives digital tube display through 74HC595
High-precision position control of linear switched reluctance motor based on AVR microcontroller
1. Project Overview 1.1 Introduction The motor is an indispensable power equipment for industrial production. There are many types of motors and their functions are quite extensive. The linear switched reluctance motor is a new type of traction motor. It has the following main advantages: simple structure and low
[Microcontroller]
High-precision position control of linear switched reluctance motor based on AVR microcontroller
Design of multifunctional electronic scale based on AVR microcontroller
In recent years, the emergence of new single-chip microcomputers and the development of integrated circuit technology have provided conditions for updating product design and developing cost-effective weighing controllers. This design uses AVR single-chip microcomputer as the control core, combined with
[Microcontroller]
Design of multifunctional electronic scale based on AVR microcontroller
The problem of delay function being optimized when debugging stm8 microcontroller with IAR
When IAR optimization level is set to the highest, the compiler will directly optimize the following delay functions when they are called, and the delay effect cannot be achieved. void delay_n_ms(u32 time) {     u32 m = 0;     u16 n = 0;     for(;m time;m++)     {         for(n = 0;n 2720;n++) // 16Mhz         {
[Microcontroller]
IAR serial port debugging, dual serial port transparent transmission program design based on Nuvoton n76e003
After solving many bugs, I finally realized the mutual reception and transmission between the two serial ports. However, my supervisor said that the program I wrote was rubbish. But I am still very happy that it can finally be used. I will make further modifications under the guidance. If you just want to complete you
[Microcontroller]
Tunnel Environment Monitoring System Based on AVR32
1. Project Overview 1.1 Introduction The environment in the tunnel will bring some special problems to driving safety and the health of passengers and maintenance workers, mainly because of the temperature, humidity, light, and the content and accumulation of harmful gases in the tunnel. Therefore, understanding t
[Microcontroller]
Tunnel Environment Monitoring System Based on AVR32
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号