在线问答
登录
直播中
中科院
10年用户
208经验值
擅长:可编程逻辑 电源/新能源 MEMS/传感技术 嵌入式技术 连接器 光电显示 存储技术 接口/总线/驱动 控制/MCU RF/无线
私信
关注
【OK210试用体验】3.2 裸机驱动的编写---PWM篇
本帖最后由 中科院 于 2015-9-19 10:19 编辑
通过本程序的编写,大家会学习到如何使用S5P210的定时器
先说说芯片基本时钟情况
#define MP0_4CON (*(vola
ti
le unsigned long *)0xE0200340)
#define MP0_4DAT (*(volatile unsigned long *)0xE0200344)
#define GPD0CON (*(volatile unsigned long *)0xE02000A0)
#define GPD0DAT (*(volatile unsigned long *)0xE02000A4)
// clock
#define APLL_LOCK (*(volatile unsigned long *)0xE0100000)
#define MPLL_LOCK (*(volatile unsigned long *)0xE0100008)
#define APLL_CON0 (*(volatile unsigned long *)0xE0100100)
#define APLL_CON1 (*(volatile unsigned long *)0xE0100104)
#define MPLL_CON (*(volatile unsigned long *)0xE0100108)
#define CLK_SRC0 (*(volatile unsigned long *)0xE0100200)
#define CLK_SRC1 (*(volatile unsigned long *)0xE0100204)
#define CLK_SRC2 (*(volatile unsigned long *)0xE0100208)
#define CLK_SRC3 (*(volatile unsigned long *)0xE010020c)
#define CLK_SRC4 (*(volatile unsigned long *)0xE0100210)
#define CLK_SRC5 (*(volatile unsigned long *)0xE0100214)
#define CLK_SRC6 (*(volatile unsigned long *)0xE0100218)
#define CLK_SRC_MASK0 (*(volatile unsigned long *)0xE0100280)
#define CLK_SRC_MASK1 (*(volatile unsigned long *)0xE0100284)
#define CLK_DIV0 (*(volatile unsigned long *)0xE0100300)
#define CLK_DIV1 (*(volatile unsigned long *)0xE0100304)
#define CLK_DIV2 (*(volatile unsigned long *)0xE0100308)
#define CLK_DIV3 (*(volatile unsigned long *)0xE010030c)
#define CLK_DIV4 (*(volatile unsigned long *)0xE0100310)
#define CLK_DIV5 (*(volatile unsigned long *)0xE0100314)
#define CLK_DIV6 (*(volatile unsigned long *)0xE0100318)
#define CLK_DIV7 (*(volatile unsigned long *)0xE010031c)
#define CLK_DIV0_MASK 0x7fffffff
#define APLL_MDIV 0x7d
#define APLL_PDIV 0x3
#define APLL_SDIV 0x1
#define MPLL_MDIV 0x29b
#define MPLL_PDIV 0xc
#define MPLL_SDIV 0x1
#define set_pll(mdiv, pdiv, sdiv) (1<<31 | mdiv<<16 | pdiv<<8 | sdiv)
#define APLL_VAL set_pll(APLL_MDIV,APLL_PDIV,APLL_SDIV)
#define MPLL_VAL set_pll(MPLL_MDIV,MPLL_PDIV,MPLL_SDIV)
// PWM CLOCK
#define TCFG0 ( *(volatile unsigned long *)0xE2500000)
#define TCFG1 ( *(volatile unsigned long *)0xE2500004)
#define TCON ( *(volatile unsigned long *)0xE2500008)
#define TCNTB0 ( *(volatile unsigned long *)0xE250000C)
#define TCMPB0 ( *(volatile unsigned long *)0xE2500010)
#define TCNTO0 ( *(volatile unsigned long *)0xE2500014)
#define TCNTB1 ( *(volatile unsigned long *)0xE2500018)
#define TCMPB1 ( *(volatile unsigned long *)0xE250001C)
#define TCNTO1 ( *(volatile unsigned long *)0xE2500020)
#define TCNTB2 ( *(volatile unsigned long *)0xE2500024)
#define TCMPB2 ( *(volatile unsigned long *)0xE2500028)
#define TCNTO2 ( *(volatile unsigned long *)0xE250002C)
#define TCNTB3 ( *(volatile unsigned long *)0xE2500030)
#define TCMPB3 ( *(volatile unsigned long *)0xE2500034)
#define TCNTO3 ( *(volatile unsigned long *)0xE2500038)
#define TCNTB4 ( *(volatile unsigned long *)0xE250003C)
#define TCNTO4 ( *(volatile unsigned long *)0xE2500040)
#define TINT_CSTAT ( *(volatile unsigned long *)0xE2500044)
void init_clock(void)
{
CLK_SRC0 = 0x0;// close PLL
APLL_LOCK= 0x0000FFFF;
MPLL_LOCK = 0x0000FFFF;
// set PLL
APLL_CON0 =APLL_VAL;//FOUT= MDIV * FIN / (PDIV*2^(SDIV-1)) = 1000 MHz
MPLL_CON = MPLL_VAL;// FOUT = MDIV*FIN/(PDIV*2^SDIV)=667 MHz
CLK_SRC0= 0x10001111;// FOUT = MDIV*FIN/(PDIV*2^SDIV)=667 MHz
}
void init_timer(unsigned long tcntb,unsigned long tcmpb)
{
TCON = 0;
TCFG0= (TCFG0 & ~0xff00ff)|0x41;//设置预分频系数65
TCFG1 =(TCFG1 & ~(0xf<<0))|0x04;// 16分频 输入时钟= PCLK /(prescaler+ 1) /divider =62500hz
TCNTB0 = tcntb;
TCMPB0 = tcmpb;
TCON |= 1<<1;// 更新TCNTB0 TCMPB0
TCON &= ~(1<<1);// 清手动更新位
TCON |= (1<<0)|(1<<3);// 选择自动加载并启动timer0
//TINT_CSTAT |= 1;
}
static void Delay(long count)
{
volatile int i, j = 0;
volatile static int loop = 800000000/10000;
for(;count > 0;count--)
for(i=0;i < loop; i++) { j++; }
}
void main(void)
{
GPD0CON = (GPD0CON & ~(0xF << 0))|0x2;
MP0_4CON= (MP0_4CON & ~0xFFFF0000) | 0x11110000;
MP0_4DAT|= 0xF0;
init_clock();//初始化时钟
init_timer(62500,40000);//初始wttimer
while(1)
{
}
//TCON = 0;
}
更多回帖
rotate(-90deg);
回复
相关帖子
【
OK210
试用
体验】3.0
裸机
驱动
的
编写
---LED
篇
3614
【
OK210
试用
体验】3.1
裸机
驱动
的
编写
---UART
篇
3600
【
OK210
试用
体验】
裸机
篇
--
PWM
定时器
2442
【
OK210
试用
体验】
裸机
篇
-- WATCHDOG
2630
【
OK210
试用
体验】
裸机
篇
-- Nand Flash 读写
3749
【
OK210
试用
体验】
裸机
篇
-- DDR重定位
4858
【
OK210
试用
体验】
裸机
篇
-- 串口通信
2835
【
OK210
试用
体验】
裸机
篇
-- 系统时钟配置
3678
【
OK210
试用
体验】
裸机
篇
-- 点亮LED增强版
2612
【
OK210
试用
体验】
裸机
练习
2606
发帖
登录/注册
20万+
工程师都在用,
免费
PCB检查工具
无需安装、支持浏览器和手机在线查看、实时共享
查看
点击登录
登录更多精彩功能!
英国威廉希尔公司网站
william hill官网 版块
小组
免费开发板试用
ebook
直播
搜索
登录
×
20
完善资料,
赚取积分