This series of articles written by muge0913, reproduced please note the Source: http://blog.csdn.net/muge0913/article/details/7389801
Author: Zhang tonghao, mail: muge0913@sina.com
There are five timers in the X, which generate internal interruptions. Timer0 and timer1 have PWM functions, while timer2, 3, 4 do not.
The processor 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 has two operation modes: automatic loading mode and one trigger mode. To implement the PWM function, the chip provides 16 function registers. These function registers are connected to the APB bus.
The overall architecture is as follows:
There are five timers in the X, which generate internal interruptions. Timer0 and timer1 have PWM functions, while timer2, 3, 4 do not. The timer has the double buffering feature, so that a new value can be loaded for the next timer operation without stopping the current timer operation. Although a new value is set for the timer, the current scheduled operation can be completed successfully. The value read by the timer from tcntbn is used for the next delay and does not affect the operation of the current timer. When tcntn is reduced to 0, the value of tcntbn is automatically copied to tcntn, which means the automatic loading operation. The current technical value of the timer can be read from the tcnton In the timer count Observation Register. If tcntn is 0 and the slave load is 0, tcntn will not perform the next operation.
Register introduction:
1. Total register ing Diagram
2. Tsung 0 register:
3. tcfg1 register:
4. tcon control register:
Mini6410 buzzer schematic diagram:
Definition register:
/* 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))
Compile the initialization function:
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}
In the main function:
init_pwm();while(1);
Program: http://download.csdn.net/detail/muge0913/4170428