您的位置 首页 数字

s3c6410 定时器中止的完成

6410手册中的相关内容five32-bittimersTimers0and1includeaPWMfunctionEachtimerhasitsown32-bitdown-count…

6410手册中的相关内容

five 32-bit timers
Timers 0 and 1 include a PWM function

Each timer has its own 32-bit down-counter which is driven by the timer clock. The down-counter is initially loaded
from the Timer Count Buffer register (TCNTBn). When the down-counter reaches zero, the timer interrupt request
is generated to inform the CPU that the timer operation is completed. When the timer down-counter reaches zero,
the value of corresponding TCNTBn can be automatically reloaded into the down-counter to start the next cycle.
However, if the timer stops, for example, by clearing the timer enable bit of TCONn during the timer running mode,
the value of TCNTBn will not be reloaded into the counter.

1 定时器0相关寄存器

1)TCON timer control register (与timer0相关的【3:0】,开关,手动更新初值,主动重装初值(
当TCNT0减到0后,从TCNTB0主动装到TCNT0)等)

2)TCNTB0 存着timer0的初值;
TCMPB0 存着timer0要比较的值(默以为0,则tcnt0和tcmp0比较,)
3)TINT_CSTAT Interrupt Control And Status Register) 定时器中止操控和timer0相关的就两位,【0】位Timer 0 Interrupt Enable.
【5】位Timer 0 Interrupt Status Bit. Clears by writing 1on this bit.(该位在ISR中需要写1清零)
4)TCFG0 Timer Configuration Register 0 that configures thetwo 8-bit Prescaler and DeadZone Length
设置各个timer的分频因子低八位是timer0 和timer1相关的
5)VIC0INTENABLE 中止使能操控 (32位对应32个中止源(留意是VIC0组的,timer0 在23位)

2timer0相关寄存器设置

Because an auto-reload operation of the timer occurs when the down counter reaches to 0, a starting value of the
TCNTn has to be defined by the user at first. In this case, the starting value has to be loaded by the manual
update bit. Take the following steps to start a Timer;
1) Write the initial value into TCNTBn and TCMPBn.
2) Set the manual update bit of the corresponding timer.
(Recommended setting the inverter on/off bit (whether using inverter or not)).
3) Set the start bit of the corresponding timer to start the timer and clear only manual update bit.

main.c中的timer0 init函数
void timer_init(void)
{
TINT_CSTAT |= 1<<0; //开timer0中止,答应timer0中止产生
V%&&&&&%0INTENABLE |= 1<<23; //开timer0的使能(相当于关掉mask)
TCFG0 = 0x42; //设置分频因子

TCNTB0 = 0x1000; //设初值
TCON |= 1<<1; //开Manual Update (Update TCNTB0,TCMPB0)设置初值后要更新TCNTB
TCON |= 1<<3; 、、//Auto Reload on 主动重装敞开
TCON |= 1<<0; //timer0 open; TCON &= ~(1<<1); 、//不再Update TCNTB0,TCMPB0

}
start.s 中的handler
irq_handler
;push rets to stack
stmfd sp!,{r0-r12,lr}

;handler
bl do_timer_irq //跳到相关履行函数
;pop stack to regs
ldmfd sp!, {r0-r12,lr}
subs pc, lr,#4

接下来的和外部中止类似了
当timer0中止产生时,程序到IRQ反常向量表的进口0x18,在这使程序跳转到IRQ_handler();在中止服务函数(ISR)中需要将TCON的5位在开端方位写1清0;为下一个中止

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/shuzi/274549.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部