深入理解ARM體系架構(gòu)(S3C6410)---PWM實(shí)例
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.
本文引用地址:http://m.butianyuan.cn/article/201611/317827.htmPWM具有兩種操作模式:自動(dòng)裝載模式,一次觸發(fā)模式。為實(shí)現(xiàn)PWM功能,芯片提供了16個(gè)功能寄存器。這些功能寄存器都連接APB總線。
總體架構(gòu)圖如下:
S3C6410X中有5個(gè)定時(shí)器,這些定時(shí)器產(chǎn)生內(nèi)部中斷。其中,Timer0和Timer1具有PWM功能,而Timer2,3,4沒(méi)有此功能。定時(shí)器具有雙緩沖特性,這樣就能在不停止當(dāng)前定時(shí)器操作的情況下,為下次定時(shí)器運(yùn)行裝入新的數(shù)值。盡管為定時(shí)器設(shè)置了新數(shù)值,但當(dāng)前的定時(shí)操作能夠成功完成。定時(shí)器從TCNTBn讀取的值是為下次延時(shí)定時(shí)用的,并不影響當(dāng)前定時(shí)器的運(yùn)行。當(dāng)TCNTn減小到0的時(shí)候,TCNTBn的值會(huì)自動(dòng)復(fù)制到TCNTn中,這就是說(shuō)的自動(dòng)裝載操作。定時(shí)器的當(dāng)前技術(shù)數(shù)值可以從定時(shí)計(jì)數(shù)觀察寄存器中TCNTOn讀取。如果TCNTn為0且從裝載也為0的話則TCNTn不在進(jìn)行下次操作。
寄存器介紹:
1、總寄存器映射圖
2、TCFG0寄存器:
3、TCFG1寄存器:
4、TCON控制寄存器:
mini6410蜂鳴器原理圖:
定義寄存器:
- #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))
編寫初始化函數(shù):
- 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函數(shù)中:
- init_pwm();
- while(1);
評(píng)論