The correct use of S3C2440A timer

Publisher:创新脑细胞Latest update time:2020-02-07 Source: elecfansKeywords:S3C2440A Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The S3C2440A has five 16-bit timers. Timers 0, 1, 2, and 3 have pulse width modulation (PWM) capabilities. Timer 4 is an internal timer with no output pins. Timer 0 also contains a dead zone generator for high current drive


Timers 0 and 1 share one 8-bit prescaler, and Timers 2, 3, and 4 share another 8-bit prescaler. Each timer has a clock divider that can generate 5 different divided signals (1/2, 1/4, 1/8, 1/16 and TCLK). Each timer module gets its own clock signal from the clock divider that gets the clock from the corresponding 8-bit prescaler. The 8-bit prescaler is programmable and divides PCLK by the load value stored in the TCFG0 and TCFG1 registers.


Each timer has its own 16-bit down counter driven by the timer clock. When the down counter reaches zero, a timer interrupt request is generated to notify the CPU that the timer operation has completed. When the timer counter reaches zero, the corresponding TCNTBn value will be automatically loaded into the down counter to continue the next operation.


There are two modes for using the timer. The first is normal timing and the second is PWM output.


Let's talk about ordinary timing first. The general use process of a timer will include these steps

1. Enable the corresponding timer peripheral in the low-power register

2. Set the clock division ratio to obtain the timer's count clock

3. Set the timer value (reload value), configure the middle end, and start the timer

4. Wait for the interrupt to occur and clear the interrupt in the interrupt handling function

Based on these steps, we need to pay attention to the following registers

The correct use of S3C2440A timer

First, set the division ratio of PCLK to timer. There are two clocks, 01 timer and 234 timer.

Then the second frequency division


You can choose 1/2%201/4%201/8%201/16 clocks. The clock source is divided from the previous register.


Set the timer to automatically reload and start the timer. Note that in this register, you must clear it again after manually updating it, otherwise the timer will not run.

The correct use of S3C2440A timer

I've encountered this problem before

The correct use of S3C2440A timer

Set the timer auto-reload value

Then set the interrupt according to the previous interrupt setting method. The timer has no secondary source. Take time0 as an example

1. Source hangs srcpend

The correct use of S3C2440A timer

2. Interrupt mode intmode

The correct use of S3C2440A timer

3. Interrupt mask intmask

The correct use of S3C2440A timer

4. Interrupt suspend intpend

The correct use of S3C2440A timer

After enabling the interrupt, the timer can be used normally

The specific code is as follows:

TImer.c

#include "TImer.h" u8TImer0Up = 0; void __irqTImer0() { rSRCPND " = (1 < < 10); // Clear source pending rINTPND | = (1 < < 10); // Clear interrupt pending timer0Up = 1; } // Timer initialization // prescaler8 is the divider value, 0-255 // mux timer's strobe input 01/211/421/831/16 // Timer reload value void InitTimer0 (u8prescaler, u8mux, u16count) { rCLKCON | = (1 < < 8); // Turn on timer clock rTCFG0 & = ~ 0xff; // Clear divider rTCFG0 | = prescaler; // Set prescaler rTCFG1 & = ~ (0x0f < < 0); rT CFG1|=(mux<<0);//Set the strobe input//Set the count value of the timer rTCMPB0=0x0; rTCNTB0=count;//Set the initial value//Start the timer rTCON|=(1<<1);//Update TCNTB0 and TCMPB0 rTCON|=(1<<3);//Start automatic reload rTCON&=~(1<<1);//Clear manual update rSRCPND|=(1<<10);//Clear source pending rINTPND|=(1<<10);//Clear interrupt pending rINTMOD&=~(1<<10);//Set the interrupt mode to IRQ mode rINTMSK&=~(1<<10);//Enable timer interrupt pISR_TIMER0=(unsigned)timer0;//Set interrupt address rTCON|=(1<<0);//Start timer 0 }

Timer.h

#ifndef__TIMER_H #define__TIMER_H #include "2440addr.h" #include "led.h" #include "uart0.h" externu8timer0Up; void InitTimer0(u8prescaler, u8mux, u16count); #endif

There are several other registers that need attention when outputting PWM waveforms.

First: PWM output does not need to enable interrupt, but the corresponding pin multiplexing function must be set to PWM function, as shown in the figure, TCLK

The correct use of S3C2440A timer

Second, to use the pwm function, the compare register must be enabled, that is

The correct use of S3C2440A timer

Third, see if you need to reverse according to your needs. What is reverse?

The correct use of S3C2440A timer

It’s TCNT

Pwm.c

#include "pwm.h" //compare the value of the compare register voidTimer0PwmInit (u8prescaler, u8mux, u16count, u16compare) {rGPBCON&=~3;rGPBCON"=2;//Set GPB0 to OUT0rGPBUP=0x0;//Enable pull-up rCLKCON|=(1<<8);//Turn on the timer clock rTCFG0&=~0xff;//Clear the divider rTCFG0|=prescaler;//Set the prescaler rTCFG1&=~(0x0f<<0);rTCFG1|=(mux<<0);//Set the strobe input //Set the count value of the timer rTCMPB0=compare;//compare register value rTCNTB0=count;//set initial value//start timer rTCON|=(1<<1);//update TCNTB0 and TCMPB0 rTCON|=(1<<3);//start automatic reload rTCON&=~(1<<1);//clear manual update rTCON|=(1<<0);//start timer 0 }

Pwm.h

#ifndef__PWM_H_ #define__PWM_H_ #include "2440addr.h" #include "def.h" //compare the value of the compare register voidTomer0PwmInit (u8prescaler, u8mux, u16count, u16compare); #endif

Keywords:S3C2440A Reference address:The correct use of S3C2440A timer

Previous article:ARM4412 bare board drives LED lights, buttons, and buzzers
Next article:Summary of assembly optimization for arm architecture 64-bit (AArch64)

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

PIC16F1829 TIMER1 Initialization Procedure
Introduction: Here I share with you a PIC16F1829 TIMER1 initialization program. Interested friends can take a look. //timer1 frequency division value #define TIMER1_DIV1 (0 4) #define TIMER1_DIV2 (1 4) #define TIMER1_DIV4 (2 4) #define TIMER1_DIV8 (3 4) //------------- #define T1_DARK (1 6) #define T1_FOS
[Microcontroller]
s3c6410 hardware WATCHDOG TIMER watchdog timer
  First, let's briefly describe the working process of the watchdog. The watchdog is actually a timer with a counter inside. Every time a clock signal arrives, the counter register decreases by one. If it decreases to 0, the system will restart; if the system sets the counter to a larger value before it decreases to 0,
[Microcontroller]
s3c6410 hardware WATCHDOG TIMER watchdog timer
MCU timer (timer0 working mode 2)
; Let the LED light change every R1ms COUNT EQU 92; for a crystal oscillator of 11.0592, 92 is equivalent to 100us LED EQU P1.1   ORG 0000H   MOV R0,#00H   DJNZ R0,$     MOV SP,#60H   MOV R1,#00H ; Use R1 as the overall count and use   MOV R2,#00H   //MOV A,TMOD   //ANL A,#11110000B    //CLR ACC.3   //CL
[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号