Exploration of AVR Timer

Publisher:熙风细雨Latest update time:2018-07-16 Source: eefocusKeywords:AVR  Timer Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


Keywords:AVR  Timer Reference address:Exploration of AVR Timer

Previous article:Use of AVR MCU ATMEGA8 USART
Next article:AVR counter - how to calculate the initial value of the count

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号