Five working types of AVR microcontroller timer

Publisher:丝路老君Latest update time:2020-01-21 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

5 types of work

Normal mode WGM1 = 0 is similar to the normal mode of 51, with TOV1 overflow interrupt flag, which occurs when MAX (0xFFFF)


1. Use the internal counting clock for ICP capture input occasions - measuring pulse width/infrared decoding (the capture input function can work in multiple modes, not just the normal mode)


2. Use external counting pulse input for counting, frequency measurement and other applications. It is more convenient to use other modes without the trouble of 51.


Dual CTC mode [Compare match clear timer mode] WGM1=4, 12 is similar to 51 in auto-reload mode

Five working types of AVR microcontroller timer

1. Used to output square wave signal with 50% duty cycle


2. Used to generate accurate continuous timing signal. When WGM1=4, the maximum value is set by OCR1A, and the OCF1A compare match interrupt flag is generated when TOP. When WGM1=12, the maximum value is set by ICF1, and the ICF1 input capture interrupt flag is generated when TOP.

If TOP = MAX, a TOV1 overflow interrupt flag will also be generated during TOP.

Note: When WGM=15, square wave output from OC1A can also be realized, and double buffer function is available.

Calculation formula: fOCn=fclk_IO/(2*N*(1+TOP)) The variable N represents the pre-division factor (1, 8, 64, 256, 1024), and T2 has two more levels (32, 128).


3. Fast PWM mode WGM1=5, 6, 7, 14, 15 single ramp counting, used to output high frequency PWM signal (twice the frequency of double ramp), all have TOV1 overflow interrupt, when it occurs in TOP [not MAX, different from normal mode and CTC mode], after comparison match, OCF1x comparison match interrupt can be generated.

When WGM1=5, the maximum value is 0x00FF, 8-bit resolution

When WGM1=6, the maximum value is 0x01FF, 9-bit resolution

When WGM1=7, the maximum value is 0x03FF, 10-bit resolution

When WGM1=14, the maximum value is set by ICF1, and an ICF1 input capture interrupt is generated at TOP (single buffer)

When WGM1=15, the maximum value is set by OCRF1A, and OCRF1A compare match interrupt is generated at TOP (double buffering, but OCRF1A will not have PWM capability and can only output square wave at most). When changing the TOP value, it must be ensured that the new TOP value is not less than the value of all compare registers.

Note that even if OCR1A/B is set to 0x0000, a narrow pulse of a timer clock cycle will be output instead of being always low.

Calculation formula: fPWM=fclk_IO/(N*(1+TOP))


4. Phase correction PWM mode WGM1=1, 2, 3, 10, 11 dual ramp counting, used to output high-precision, phase-accurate, symmetrical PWM signals. All have TOV1 overflow interrupt, but when it occurs in BOOTOM, it can generate OCF1x compare match interrupt after compare match.

When WGM1=1, the maximum value is 0x00FF, 8-bit resolution

When WGM1=2, the maximum value is 0x01FF, 9-bit resolution

When WGM1=3, the maximum value is 0x03FF, 10-bit resolution

When WGM1=10, the maximum value is set by ICF1, and an ICF1 input capture interrupt is generated at TOP (single buffer)

When WGM1=11, the maximum value is set by OCRR1A, and OCFR1A compare match interrupt is generated at TOP (double buffering, but OCFR1A will not have PWM capability, and can only output square wave at most). When changing the TOP value, it must be ensured that the new TOP value is not less than the value of all comparison registers. A PWM signal with a duty cycle of 0% to 100% can be output. If the TOP value is to be changed during T/C operation, it is best to use the phase and frequency correction mode instead of the phase correction mode. If TOP remains unchanged, there is actually no difference between these two working modes.

Calculation formula: fPWM=fclk_IO/(2*N*TOP)


5. Phase and frequency correction PWM mode WGM1=8,9 dual ramp counting is used to output high-precision PWM waveform with accurate phase and frequency. There is TOV1 overflow interrupt, but when it occurs in BOOTOM, OCF1x compare match interrupt can be generated after compare match.

When WGM1=8, the maximum value is set by ICF1, and an ICF1 input capture interrupt is generated at TOP (single buffer)

When WGM1=9, the maximum value is set by OCR1A, and an OCF1A compare match interrupt is generated at TOP (double buffering, but OCR1A will not have PWM capability and can only output square waves at most) Phase-frequency correction The main difference between the corrected PWM mode and the phase-corrected PWM mode is the update time of the OCR1x register. When changing the TOP value, it must be ensured that the new TOP value is not less than the value of all comparison registers. A PWM signal with a duty cycle of 0% to 100% can be output. When using a fixed TOP value, it is best to use the ICR1 register to define the TOP. In this way, OCR1A can be used to output a PWM wave at OC1A. However, if the PWM base frequency is constantly changing (by changing the TOP value), the double buffering feature of OCR1A makes it more suitable for this application.


Calculation formula: fPWM=fclk_IO/(2*N*TOP)

Reference address:Five working types of AVR microcontroller timer

Previous article:Design of air detector based on AVR microcontroller
Next article:AVR microcontroller's CPU core structure and assembly language

Recommended ReadingLatest update time:2024-11-16 11:59

PIC32MZ tutorial -- 32-bit Timer
  The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has four 32-bit synchronous timers are available by combining Timer2 with Timer3, Timer4 with Timer5, Timer6 with Timer7, and Timer8 with Timer9. The 32-bit timers can operate in one of three modes: •Synchronous internal 3
[Microcontroller]
MSP430F149 TIMER_A (I)——16-bit timing counter
    TIMER_A has four optional clock sources. For convenience, ACLK and SMCLK are generally selected. A time base is generated through a frequency divider. Its structure diagram is as follows:   TIMER_A has three timing/counting modes: (1). Incremental counting mode: Counting cycle: TAR increases from 0 to TAC
[Microcontroller]
STM32 Timer PWM_Output
The pulse width modulation mode can generate a signal with a frequency determined by the TIMx_ARR register and a duty cycle determined by the TIMx_CCRx register. The following is an example of PWM mode 1. The PWM signal reference OCxREF is high when TIMx_CNT   Library function STM32F10x_StdPeriph_Lib_V3.3.0\Proje
[Microcontroller]
STM32 Timer PWM_Output
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号