Application of Atmega16 timer T0

Publisher:qiuxubiaoLatest update time:2016-08-17 Source: eefocusKeywords:Atmega16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The following part is from the data sheet,

Timer operating mode: Operating mode - T/C and output compare pin behavior - determined by waveform generation mode (WGM21:0) and compare output mode

The comparison output mode has no effect on the count sequence, while the waveform generation mode has an effect on the count sequence.

COM21:0 controls whether the PWM output is reverse polarity. In non-PWM mode, COM21:0 controls the output

The Compare Match Output Unit determines whether the bit should be set, cleared, or inverted when a compare match occurs (P113 "Compare Match Output Unit").

Normal mode: Normal mode (WGM21:0 = 0) is the simplest working mode. In this mode, the counter keeps accumulating.

After reaching the maximum value of the bit (TOP = 0xFF), the counter simply rolls over to the minimum value 0x00 due to the overflow and restarts.

In the same timer clock when TCNT0 is zero, the T/C overflow flag TOV2 is set. At this time, TOV2 is a bit like

Bit 9 can only be set but not cleared. However, since the timer interrupt service routine can automatically clear TOV2,

The timer resolution can be increased through software. In normal mode, there is nothing special to consider.

Write a new counter value at any time.

The output compare unit can be used to generate interrupts. However, it is not recommended to use the output compare to generate waveforms in normal mode because

It will take up too much CPU time.

T/C timing diagram:

8-bit T/C register description

Timer/C Control Register - TCCR2

?Bit 7 – FOC2: Forced Output Compare

FOC2 is only valid when WGM indicates non-PWM mode. However, to ensure compatibility with future devices, use

When PWM is in progress, writing TCCR2 must clear it to 0. After writing 1, the waveform generator will immediately perform a comparison operation.

The output pin OC2 will output the corresponding level according to the setting of COM21:0. Note that FOC2 is similar to a latch signal.

What really works for forced output comparison is the setting of COM21:0.

FOC2 will not cause any interrupts and will not clear the timer in CTC mode using OCR2 as TOP.

zero.

The return value of reading FOC2 is always 0.

? Bit 6, 3 – WGM21:0: Waveform generation mode

These bits control the counting sequence of the counter, the source of the counter's maximum value TOP, and what waveform is generated.

The supported modes are: normal mode, clear counter mode (CTC) when compare match occurs, and two PWM modes.

See Table 50 and P114 "Working Mode" for details.

? Bit 5:4 – COM21:0: Compare match output mode

These bits determine the level at the output pin OC0 when a compare match occurs.

OC0 works in the mode of compare match output. At the same time, its direction control bit should be set to 1 to enable output

drive.

When OC0 is connected to a physical pin, the function of COM01:0 depends on the setting of WGM01:0.

The function of COM01:0 when WGM01:0 is set to normal mode or CTC mode is shown.

2. Please pay attention when making corresponding applications

Do not assign an initial value to timer TO, otherwise the timing will be very inaccurate when the normal mode is applied.

The change of timing time can only be determined by the clock source and the frequency division coefficient

Finally, I would like to say that the Atmega16 data sheet is very well done, with a lot of information in Chinese, and it is very easy to learn! ! ! ! ! ! ! ! ! ! !

Keywords:Atmega16 Reference address:Application of Atmega16 timer T0

Previous article:AVR Serial Communication
Next article:AVR chip ISP complete guide and avr unlocking

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号