本系列文章由muge0913編寫,轉載請註明出處:http://blog.csdn.net/muge0913/article/details/7389801
作者:張同浩,郵箱:muge0913@sina.com
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 0rTCON &= ~2;//clear manual update bit}
在main函數中:
init_pwm();while(1);
程式:http://download.csdn.net/detail/muge0913/4170428