AVR MCU Timer/Counter Study Notes (Part 2)

Publisher:科技小巨人Latest update time:2017-11-22 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

     Timer/Counter 1 (16-bit) has normal mode, CTC mode, fast PWM mode, phase correction PWM mode and other operating modes.

2. CTC mode (need to use OC1A and OC1B pins)

     Application: Used to generate a square wave signal with a duty cycle of 50%

              [Reprint] AVR MCU Timer/Counter Study Notes (Part 2)

                                   (N is the frequency division coefficient)

     Registers that need to be configured: Timer/C1 Control Register A (TCCR1A), Timer/C1 Control Register B (TCCR1B), Output Compare Register 1A (OCR1A).

     (1) Bit7 and bit6 of TCCR1A are used to set the comparison output mode of the OC1A pin, and bit5 and bit4 are used to set the comparison output mode of the OC1B pin. (Here we set it so that the OC1A and OC1B levels are inverted when the comparison matches)

     (2) Bit 4 and bit 3 of TCCR1B and bit 1 and bit 0 of TCCR1A are combined to set the waveform generation mode. (Here we set it to mode 4 - CTC mode)

     (3) Bit 2, bit 1, and bit 0 of TCCR1B set the clock frequency.

     (4) OCR1A is used to set the upper limit of the count

Routine:

#include

#include


void main()

{

   DDRD|=0X30; //PD4, PD5 are set as output

   

   TCCR1A=0X50; //Compare and match and invert

   TCCR1B=0X09; //CTC mode, no pre-scaling

   

   OCR1A=1999; //OC1A and OC1B both generate 2KHz square wave signals (system clock is 8MHz)

}


Keywords:AVR Reference address:AVR MCU Timer/Counter Study Notes (Part 2)

Previous article:AVR MCU Timer/Counter Study Notes (Part 3)
Next article:AVR MCU Timer/Counter Study Notes (I)

Recommended ReadingLatest update time:2024-11-15 18:47

ARM microcontroller core structure
The core of the ARM chip, the CPU core (ARM720T), consists of an ARMTTDMI 32-bit RISC processor, a single 8KB cache, and a memory space management unit (MMU). The 8KB cache has a four-way connected register and is organized into 52-line quad words (4×52×4 bytes). The cache is directly connected to the ARMTTDMI, so the
[Microcontroller]
Digital tube display 51 single chip microcomputer DS18B20 temperature measurement source program and simulation
This is a digital tube display 51 single-chip DS18B20 temperature measurement source program and simulation data, especially suitable for single-chip beginners to learn reference. This digital tube display 51 single-chip DS18B20 temperature measurement source program uses modular programming, which is convenient for d
[Microcontroller]
Digital tube display 51 single chip microcomputer DS18B20 temperature measurement source program and simulation
Serial communication based on 51 single chip microcomputer (PC sends characters)
Serial communication Selected chip: AT89S52 Function function: See the following code. /******************************************************************* Function: The PC sends data to the microcontroller, sending 3 bytes of data each time (each byte is 8 bits). The content of each byte is one of the unsigned inte
[Microcontroller]
Circuit design of intelligent lighting control system using single chip microcomputer
  This system is mainly composed of light detection circuit, pyroelectric infrared sensor and processing circuit, single chip system and control circuit. When working, the light detection circuit and pyroelectric infrared sensor collect information such as light intensity and whether there are people in the room and s
[Power Management]
Circuit design of intelligent lighting control system using single chip microcomputer
Single chip microcomputer beer bottle counting experiment source program
Experimental description: The initial value in the source program is calculated as 0xf7, and the program is counted using the timing counting method 2. When the program starts running, each time the button is pressed (i.e. each time a bottle of beer is loaded), the LED display count will increase by 1 until it reaches
[Microcontroller]
Serial port test module on PIC microcontroller
****************************************main.c********************************* #include #include "uart.h" #include "iocfg.h" uchar com_tx_buffer; void main( ) { OSCCON=0x7a; //Internal crystal oscillator 16MHz io_init(); //GPIO port initialization uart_init(9600); //Baud rate 9600 INTCON=0xe0; // Allow terminal whil
[Microcontroller]
Analysis of menu system source code in single chip microcomputer C language
When I was studying the menu system of the microcontroller recently, I found some codes that defined 4 buttons: the confirmation button, the return button, the up button, and the down button. I will paste them here first. They are built in vc. First, a structure KbdTabStruct is defined. Then a const array KBD is define
[Microcontroller]
Analysis of menu system source code in single chip microcomputer C language
Example program written in HI-TECH C to read and write 93LC46 using PIC12C508 microcontroller
/************************************************************  * Processes : Microchip PIC12C508 *  * Compiler : Hi-TECH PICC 8.00 PL2 *  * Writer : Jason Kuo *  * Description : It can read/write 93LC46 (64 x 16-bit organization) *  *************************************************************/ static volatil
[Microcontroller]
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号