时钟操控逻辑给整个芯片供给3种时钟:FCLK用于CPU核;HCLK用于AHB总线设备,比方CPU核、存储器操控器、中止操控器、DMA和USB主机模块等;PCLK用于APB总线上的设备,比方WATCHDOG、IIS、IIC、PWM、MMC、ADC、RTC等等。
S3C2440 CPU核的作业电压为1.2V时,主频能够到达300MHz;作业电压为1.3V时,主频能够到达400MHz。开发板为12MHz,需求经过时钟操控逻辑的PLL进步体系时钟。
S3C2440有两个PLL:MPLL和UPLL。UPLL专用于USB设备,MPLL用于设置FCLK、HCLK、PCLK。
其间 m=MDIV+8, p=PDIV+2, s=SDIV
CLKDIVN寄存器:用于设置FCLK、HCLK、PCLK 三者份额。各种时钟份额对应的寄存器设置如下图所示:
现在咱们能够归结发动一个PWM功用能够分为以下几步:
由此能够看出,它有以下4个效果:
程序剖析如下:(这程序是赵春江教师的程序)
#include “2440addr.h”
#define U32 unsigned int
typedef unsigned char BOOL;
#define TRUE 1
#define FALSE 0
BOOL stop;
static void __irq Key3_ISR(void) /*暂停键,封闭蜂鸣器*/
{
rSRCPND = rSRCPND | (0x1<<2); /*界说EINT2*/
rINTPND = rINTPND | (0x1<<2);
rTCON &= ~0x8; /*制止定时器主动重载,即封闭定时器0111*/
stop = TRUE;
}
void __irq Key2_ISR(void) /*重启键,敞开蜂鸣器*/
{
rSRCPND = rSRCPND | 0x1; /*界说EINT0*/
rINTPND = rINTPND | 0x1;
stop = FALSE;
}
void delay(int a)
{
int k;
for(k=0;k
;
}
void Main(void)
{
int freq;
rGPBCON = 0x155556; /*B0为TOUT0,B5~B8为输出,给LED 0001 0101 0101 0101 0101 0110*/
rGPBUP = 0x7ff; /*0111 1111 1111封闭上拉使能*/
rGPFCON = 0xaaaa; /*F口为EINT,给按钮 1010 1010 1010 1010*/
/*按钮的一些必要装备*/
rSRCPND = 0x0f; /*中止设置*/
rINTMSK = ~0x0f;
rINTPND =0x0f;
rEXTINT0 = 0x2222; /*EINT0/EINT1均设置为下降沿触发*/
freq = 2500;
rTCFG0 &= 0xFFFF00;
rTCFG0 |= 0x31; /*prescal 是49 3*16+1=49 timer0 and timer1*/
rTCFG1 &= ~0xF; /*低四位清零 divider value=1/2,由于PCLK为50MHz,所以50MHz/50/2=500kHz/
rTCNTB0 = 5000; /*定时器计数初始值*/
rTCMPB0 = freq; /*定时器比较值*/
rTCON &= ~0x1F;
rTCON |= 0xf; /*死区无效,主动装载,电平回转,手动更新,定时器敞开*/
rTCON &= ~0x2 ; /*手动更新位清零,PWM开端作业*/
pISR_EINT0 = (U32)Key2_ISR;
pISR_EINT2 = (U32)Key3_ISR;
stop = FALSE;
rGPBDAT = ~0x60; /*两个LED亮*/
while(1)
{
/*频率递加*/
for ( ; freq<4950 ; )
{
freq+=10;
rTCMPB0 = freq; /*从头赋值*/
delay(20000);
while (stop == TRUE) /*是否暂停*/
{
delay(1000);
if (stop ==FALSE) /*判别是否重启*/
{
rTCON &= ~0x1F;
rTCON |= 0xf;
rTCON &= ~0x2 ; /*康复PWM功用*/
}
}
/*4个LED跟着频率的凹凸,时灭时亮。灯亮的数目4-3-2-1*/
if(freq == 100)
rGPBDAT = ~0x560; /*0001 1110 0000 取反之后1110 0001 1111*/
if(freq == 1300)
rGPBDAT = ~0x160; /*1110 0000取反之后 0001 1111*/
if(freq == 2500)
rGPBDAT = ~0x60; /*0110 0000取反之后 1001 1111*/
if(freq == 3700)
rGPBDAT = ~0x20; /*0010 0000取反之后 1101 1111*/
if(freq == 4900)
rGPBDAT = ~0x0; /*0000取反之后 1111111111*/
}
/*频率递减*/
for( ; freq>50 ; )
{
freq-=10;
rTCMPB0 = freq;
delay(20000);
while (stop == TRUE)
{
delay(1000);
if (stop ==FALSE)
{
rTCON &= ~0x1F;
rTCON |= 0xf;
rTCON &= ~0x2 ;
}
}
if(freq == 100)
rGPBDAT = ~0x560;
if(freq == 1300)
rGPBDAT = ~0x160;
if(freq == 2500)
rGPBDAT = ~0x60;
if(freq == 3700)
rGPBDAT = ~0x20;
if(freq == 4900)
rGPBDAT = ~0x0;
}
}
}
TOUT输出的波形是: