MCU PWM Timer

Publisher:cloudsousou6Latest update time:2014-08-15 Source: 21icKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
S3C2410 has 5 timers in total

Among them, 0, 1, 2, and 3 have PWM functions, and each has an output pin, which can be controlled by a timer to periodically change the high and low levels of the pin;

The timer has no output pins;

1. Timer clock source

The clock source of the timing component is PCLK, which is first reduced in frequency by two 8-bit prescalers;

Timers 0 and 1 share the first prescaler;

Timers 2, 3, and 4 share the second prescaler;

The output of the pre-divider will enter the second-stage divider and output 5 kinds of clock frequencies: 2-division, 4-division, 8-division, 16-division, and external clock TCLOK0/TCLK1;

The working clock of each timer can be selected from these 5 frequencies;

2. Working Principle of Timer

1. Set the two registers TCMPBn and TCNTBn, which represent the comparison value and initial count value of timer n;

2. Start timer n, and by setting TCON, the values ​​of TCMPBn and TCNTBn are loaded into TCMPn and TCNTn.

At the operating frequency of timer n, TCNTn starts to count down by 1, and its value can be read through the TCNTOn register;

3. When the value of TCNTn is equal to the value of TCMPn, the output pin TOUTn of timer n is reversed;

TCNTn continues to count down by 1;

4. When the value of TCNTn reaches 0, its output pin TOUTn reverses again and triggers the interrupt of timer n (if the interrupt is enabled);

5. If timer n is set to "auto load" in the TCON register, the values ​​of the TCMPB0 and TCNTB0 registers are automatically loaded into TCMP0 and TCNT0, starting the next counting process.

The output pin TOUTn of timer n is initially in high level. When the value of TCNTn is equal to the value of TCMPn or the value of TCNTn is equal to 0, a reversal will occur.

You can also set its initial level through the TCON register, so that the output of TOUTn is completely inverted.

By setting the values ​​of TCMPBn and TCNTBn, the duty cycle of the output signal of pin TOUT can be set. This is called modulated pulse (PWM), so these timers are also called PWM timers.

3. Register Usage

1.TCFG0

[7:0] and [15:8] are used to control prescaler 0 and 1 respectively. The clock frequency output from the prescaler is: PCLK/(perscaler value + 1);

2. TCFG1

Set the second level frequency division,

【3:0】Set timer 0

【7:4】Set timer 1

【11:8】Set timer 2

【15:12】Set timer 3

【19:16】Set timer 4

0b0000——1/2

0b0001——1/4

0b0010——1/8

0b0011——1/16

0b01xx——External TCLK0/TCLK1;

3.TCNTBn

4.TCMPPBn

Without TCMPBn, Timer 4 has no output pin

5.TCNTOn

6. TCON

TCON has four functions:

(1) When the timer is started for the first time, the values ​​of TCNTBn and TCMPBn are loaded into TCNTn and TCMPn;

(2) Start and stop the timer;

(3) Set up automatic reload;

(4) Set whether TOUTn is reversed;

【3:0】For timer 0

【11:8】For timer 1

【15:12】For timer 2

【19:16】For timer 3

【22:20】For timer 4, no output pin inversion bit

Bit 0: 0——stop the timer, 1——start the timer;

Bit 1: 1 - Load the values ​​of TCNTBn and TCMPBn into TCNTn and TCMPn;

Bit 2: 0——TOUTn is not inverted, 1——TOUTn is inverted;

Bit 3: 0——do not load automatically, 1——load automatically;

When using the timer for the first time, you need to set "bit 1" so that the value of TCNTBn/TCMPBn is loaded into TCNTn and TCMPn.

Keywords:MCU Reference address:MCU PWM Timer

Previous article:Design and implementation of an electric barrier controller
Next article:Design and implementation of intelligent controller for high-speed real-time data acquisition

Latest Microcontroller Articles
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号