首页 > 其他 > 详细

MCF52259 实现PWM波级联

时间:2014-04-19 01:35:22      阅读:633      评论:0      收藏:0      [点我收藏+]

网上能找到一些ColdFire的PWM的驱动,但是找到的都是通道没有级联的。一般为了提高调节精度,我们都会使用级联的PWM波,下面就实现PWM级联的方法。

在MCF52259_PWM.h 中有如下定义:

#define MCF_PWM_PWMPER0   (*(vuint8 *)(0x401B0014))
#define MCF_PWM_PWMPER1   (*(vuint8 *)(0x401B0015))
#define MCF_PWM_PWMPER2   (*(vuint8 *)(0x401B0016))
#define MCF_PWM_PWMPER3   (*(vuint8 *)(0x401B0017))
#define MCF_PWM_PWMPER4   (*(vuint8 *)(0x401B0018))
#define MCF_PWM_PWMPER5   (*(vuint8 *)(0x401B0019))
#define MCF_PWM_PWMPER6   (*(vuint8 *)(0x401B001A))
#define MCF_PWM_PWMPER7   (*(vuint8 *)(0x401B001B))

级联以前的两个通道的PWM的周期寄存器和占空比寄存器都是8位的寄存器,但是相邻通道的周期寄存器的和占空比寄存器在地址上是连续的,比如通道0的周期寄存器地址为0x401B0014,通道1的周期寄存器的地址为0x401B0015,所以我们对通道0的地址做如下定义:

#define MY_PWMPER01 (*(vuint16 *)(0x401B0014))

这样我们调节级联之后的PWM的占空比课直接对MY_PWMPER01操作,而不用把占空比分成高八位和第八位分别赋给两个通道。

#define MY_PWMPER01 (*(vuint16 *)(0x401B0014))
#define MY_PWMPER23 (*(vuint16 *)(0x401B0016))
#define MY_PWMPER45 (*(vuint16 *)(0x401B0018))
#define MY_PWMPER67 (*(vuint16 *)(0x401B001A))

#define MY_PWMDTY01 (*(vuint16 *)(0x401B001C))
#define MY_PWMDTY23 (*(vuint16 *)(0x401B001E))
#define MY_PWMDTY45 (*(vuint16 *)(0x401B0020))
#define MY_PWMDTY67 (*(vuint16 *)(0x401B0022))

PWM的完整配置代码如下:

void PWM_Init(void)
{	
	//配置引脚功能为PWM输出
	MCF_GPIO_PTAPAR=MCF_GPIO_PTAPAR_ICOC0_PWM1
					|MCF_GPIO_PTAPAR_ICOC1_PWM3
					|MCF_GPIO_PTAPAR_ICOC2_PWM5
				 	|MCF_GPIO_PTAPAR_ICOC3_PWM7;
	
	//PWM波开始为高电平
	MCF_PWM_PWMPOL=(MCF_PWM_PWMPOL_PPOL1
					|MCF_PWM_PWMPOL_PPOL3
					|MCF_PWM_PWMPOL_PPOL5
					|MCF_PWM_PWMPOL_PPOL7);
	
	//01 45 ---> SA 
	//23 67 ---> SB
	MCF_PWM_PWMCLK=0XFF;
	
	//128MHz   A = B = 128/1=128MHz
	MCF_PWM_PWMPRCLK=MCF_PWM_PWMPRCLK_PCKA(0)
					|MCF_PWM_PWMPRCLK_PCKB(0);
	
 	//全部使用左对齐
	MCF_PWM_PWMCAE=0;
	
	//01级联  23级联  45级联  67级联
	MCF_PWM_PWMCTL = MCF_PWM_PWMCTL_CON01
					|MCF_PWM_PWMCTL_CON23
					|MCF_PWM_PWMCTL_CON45
					|MCF_PWM_PWMCTL_CON67;
	
 	//对AB进行分频得到SA = SB  = 128/(1*2) = 64MHz
	MCF_PWM_PWMSCLA=1;
	MCF_PWM_PWMSCLB=1;
	
	//frequency = 64MHz/10000 = 6.4KHz
	MY_PWMPER01=10000;
	MY_PWMDTY01=1000;
	
	MY_PWMPER23=10000;
	MY_PWMDTY23=4000;
	
	MY_PWMPER45=10000;
	MY_PWMDTY45=7000;
	
	MY_PWMPER67=10000;
	MY_PWMDTY67=9000;
	
	MCF_PWM_PWMSDN=MCF_PWM_PWMSDN_IF;
	
	//使能4个通道的PWM波
	MCF_PWM_PWME=MCF_PWM_PWME_PWME1
				|MCF_PWM_PWME_PWME3
				|MCF_PWM_PWME_PWME5
				|MCF_PWM_PWME_PWME7;
}


MCF52259 实现PWM波级联,布布扣,bubuko.com

MCF52259 实现PWM波级联

原文:http://blog.csdn.net/csu_stackoverflow/article/details/24035867

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!