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 '1'on 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中断发生
VIC0INTENABLE |= 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;为下一个中断
上一篇:s3c6410 DMA 实现(入门级)
下一篇:s3c6410 的外部中断实现
推荐阅读最新更新时间:2024-03-16 15:04
设计资源 培训 开发板 精华推荐
- 非常见问题解答第223期:如何在没有软启动方程的情况下测量和确定软启动时序?
- 兆易创新GD25/55全系列车规级SPI NOR Flash荣获ISO 26262 ASIL D功能安全认证证书
- 新型IsoVu™ 隔离电流探头:为电流测量带来全新维度
- 英飞凌推出简化电机控制开发的ModusToolbox™电机套件
- 意法半导体IO-Link执行器电路板为工业监控和设备厂商带来一站式参考设计
- Melexis采用无磁芯技术缩小电流感测装置尺寸
- 千丘智能侍淳博:用数字疗法,点亮“孤独症”儿童的光
- 数药智能冯尚:ADHD数字疗法正为儿童“多动症”提供更有效便捷服务
- Vicor高性能电源模块助力低空航空电子设备和 EVTOL的发展
- 创实技术electronica 2024首秀:加速国内分销商海外拓展之路