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%
(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)
}
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Sandia Labs develops battery failure early warning technology to detect battery failures faster
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- 【Beetle ESP32-C3】8. OLED clock and weather assistant (Arduino)
- R7F0C003/004 series, using IAR development environment, are there any tutorials?
- PWM wave problem
- Typical uses of voltage followers
- Electric energy measurement solution based on C2000 built-in 12-bit ADC
- How many memory wafers are used in STM32F0 and STM32F1 series?
- The stm32f103c8t6 core board is powered by two USB cables, and the program cannot start automatically
- [NUCLEO-F746ZG Learning] Construction Project-Based on RT-Thread
- Occupation and age
- I need help from a master who can use ADS software to make filters