S3C6410X中有5个定时器,这些定时器产生内部中断。其中,Timer0和Timer1具有PWM功能,而Timer2,3,4没有此功能。
The S3C6410X RISC microprocessorcomprises of five 32-bit timers. These timers are used to generate internal interruptsto the ARM subsystem. In addition, Timers 0 and 1 include a PWM function (PulseWidth Modulation),which can drive an external I/O signal. The PWM for timer 0and 1 have an optional dead-zone generator capability, which can be utilized tosupport a large current device. Timer 2, 3 and 4 are internal timers with no outputpins.
PWM具有两种操作模式:自动装载模式,一次触发模式。为实现PWM功能,芯片提供了16个功能寄存器。这些功能寄存器都连接APB总线。
总体架构图如下:
S3C6410X中有5个定时器,这些定时器产生内部中断。其中,Timer0和Timer1具有PWM功能,而Timer2,3,4没有此功能。定时器具有双缓冲特性,这样就能在不停止当前定时器操作的情况下,为下次定时器运行装入新的数值。尽管为定时器设置了新数值,但当前的定时操作能够成功完成。定时器从TCNTBn读取的值是为下次延时定时用的,并不影响当前定时器的运行。当TCNTn减小到0的时候,TCNTBn的值会自动复制到TCNTn中,这就是说的自动装载操作。定时器的当前技术数值可以从定时计数观察寄存器中TCNTOn读取。如果TCNTn为0且从装载也为0的话则TCNTn不在进行下次操作。
寄存器介绍:
1、总寄存器映射图
2、TCFG0寄存器:
3、TCFG1寄存器:
4、TCON控制寄存器:
mini6410蜂鸣器原理图:
定义寄存器:
- /* PWM Timer */
- #define rTCFG0 (*(volatile unsigned *)(0x7F006000))
- #define rTCFG1 (*(volatile unsigned *)(0x7F006004))
- #define rTCON (*(volatile unsigned *)(0x7F006008))
- #define rTCNTB0 (*(volatile unsigned *)(0x7F00600C))
- #define rTCMPB0 (*(volatile unsigned *)(0x7F006010))
- #define rTCNTO0 (*(volatile unsigned *)(0x7F006014))
- #define rTCNTB1 (*(volatile unsigned *)(0x7F006018))
- #define rTCMPB1 (*(volatile unsigned *)(0x7F00601c))
- #define rTCNTO1 (*(volatile unsigned *)(0x7F006020))
- #define rTCNTB2 (*(volatile unsigned *)(0x7F006024))
- #define rTCNTO2 (*(volatile unsigned *)(0x7F00602c))
- #define rTCNTB3 (*(volatile unsigned *)(0x7F006030))
- #define rTCNTO3 (*(volatile unsigned *)(0x7F006038))
- #define rTCNTB4 (*(volatile unsigned *)(0x7F00603c))
- #define rTCNTO4 (*(volatile unsigned *)(0x7F006040))
- #define rTINT_CSTAT (*(volatile unsigned *)(0x7F006044))
编写初始化函数:
- void init_pwm()
- {
- rGPFCON &= ~(0x3U << 28);
- rGPFCON |= (0x2U << 28);
- rTCFG0 &= ~0xff;
- rTCFG0 |= (50 - 1);
- rTCFG1 = 0x4;
- #define freq 800
- rTCNTB0 = (133000000/50/16)/freq;
- rTCMPB0 = rTCNTB0/2;
- rTCON &= ~0x1f;
- rTCON |= 0xb; //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0
- rTCON &= ~2; //clear manual update bit
- }
在main函数中:
- init_pwm();
- while(1);