[007] avr mcu Interrupt System

Source: Internet
Author: User
21 interrupt sources of the AVR Microcontroller

I/O port second function

There is a single AVR Microcontroller timer. The timer/Counter 1 is 16bit, and the rest of the timer/Counter 0 and Timer/Counter 2 are 8bit timers.

Timer Working Mode
  • Normal Mode
  • CTC Mode
  • Fast PWM mode
  • Phase Correction PWM mode
  • Phase frequency correction PWM mode
  • Input Capture Mode

Similar to the timer counter of 51 single-chip microcomputer, the Count register value is increased by 1 every time a clock exceeded according to the set clock frequency.

Registers used

T/C1 control register B: (controls the source and frequency of the clock)

Set the last three digits. 1 indicates that the timer is stopped, 2 ~ 6 indicates the internal clock of different frequencies, 7 ~ 8 indicates the external driver.

Count register

Calculate a pre-installed value based on the time of each interruption, and then start to count until 65535, resulting in overflow interruption, which is exactly the time we need. This time is the counting time from the pre-installed value to 65536.

Specific calculation:
Assume that the interrupt time is 1 second, that is to say, register overflow is required once every 1 second to generate an interrupt. Because the frequency of the AVR microcontroller is 8 MHz, that is, there are 8 m clock cycles per second, that is, the number of 8 m times per second. Let's assume that the first step we select is 001, that is, the selected clock frequency is 8 m/256 = 31250, that is, there are 31250 clock cycles per second, each clock cycle uses (1/31250) s, that is, every (1/31250) s counter plus 1. Therefore, the pre-installed value of the Register is 31250-65535 = 31250. convert it to hexadecimal notation 0x85edh.
Then, load the high and low bits of this number to the high and low ends of the register tcnt1.

Interrupt shield register and total interrupt

 

Toie1 = 1 is to enable t/C1 interrupt shielding.

When using an interrupt, you must first enable the total interrupt sreg | = bit (7)

[007] avr mcu Interrupt System

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.