欢迎来到天天文库
浏览记录
ID:51772533
大小:42.95 KB
页数:4页
时间:2020-03-15
《智能车电机测试程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、/*******************************************************************************************************Motor_Test**(c)Copyright2009-2010,DEMOK**AllRightsReserved****V1.1.0***************************************************************************************************/#include2、>/*commondefinesandmacros*/#include"derivative.h"/*derivative-specificdefinitions*/unsignedintCurrentVelocity=0;unsignedintWholeVelocity=0;unsignedintvTmpPIT=0;unsignedintflag=0;/*****************************************************FunctionName:PLL_Init**FunctionDiscription:ClockInitiali3、zation**FunctionStatement:BusClockis48MHz****************************************************/voidPLL_Init(void)//PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1){CLKSEL=0x00;PLLCTL_PLLON=1;SYNR=0XC04、0X05;REFDV=0X805、0X01;POSTDIV=0X00;_asm(nop);_asm(nop);while(0==CRGFLG_LOCK);CLKSEL_PLLSEL=1;}/********6、*****************************************************FunctionName:PIT_Init**FunctionDiscription:PeriodicInterruptTimerInitialization**FunctionStatement:InterruptTimeis20ms************************************************************/voidPIT_Init(void)//定时中断初始化函数0.01s=10ms定时中断设置{PITCFLMT_P7、ITE=0;PITCE_PCE0=1;PITMTLD0=240-1;PITLD0=2000-1;PITINTE_PINTE0=1;PITCFLMT_PITE=1;}/************************************************************FunctionName:PWM_Init**FunctionDiscription:PulseWidthModulationInitialization**FunctionStatement:PWM1isassignedtoMotorIn1PWM3isassignedtoMotorIn28、***********************************************************/voidPWM_Init(void){//CH01MotorIn1//CH23MotorIn2//SB,Bforch2367//SA,Aforch0145PWME=0x00;PWMCTL=0x70;PWMCAE=0x00;PWMPOL=0xFF;PWMPRCLK=0x33;PWMSCLA=0x03;PWMSCLB=0x03;PWMCLK=0xFF;PWMPER01=12000;PWMDTY01=0;PWMPER23=12000;PWMDTY23=0;P9、WMCNT01=0;PWMCNT23=0;PWME=0x2A;}/************************************************************FunctionName:Main**FunctionDiscription:MainFunction***********************************************************/voidmain(void){/*putyourowncodehere*/PLL_Init();PWM_Init();PIT_Init(
2、>/*commondefinesandmacros*/#include"derivative.h"/*derivative-specificdefinitions*/unsignedintCurrentVelocity=0;unsignedintWholeVelocity=0;unsignedintvTmpPIT=0;unsignedintflag=0;/*****************************************************FunctionName:PLL_Init**FunctionDiscription:ClockInitiali
3、zation**FunctionStatement:BusClockis48MHz****************************************************/voidPLL_Init(void)//PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1){CLKSEL=0x00;PLLCTL_PLLON=1;SYNR=0XC0
4、0X05;REFDV=0X80
5、0X01;POSTDIV=0X00;_asm(nop);_asm(nop);while(0==CRGFLG_LOCK);CLKSEL_PLLSEL=1;}/********
6、*****************************************************FunctionName:PIT_Init**FunctionDiscription:PeriodicInterruptTimerInitialization**FunctionStatement:InterruptTimeis20ms************************************************************/voidPIT_Init(void)//定时中断初始化函数0.01s=10ms定时中断设置{PITCFLMT_P
7、ITE=0;PITCE_PCE0=1;PITMTLD0=240-1;PITLD0=2000-1;PITINTE_PINTE0=1;PITCFLMT_PITE=1;}/************************************************************FunctionName:PWM_Init**FunctionDiscription:PulseWidthModulationInitialization**FunctionStatement:PWM1isassignedtoMotorIn1PWM3isassignedtoMotorIn2
8、***********************************************************/voidPWM_Init(void){//CH01MotorIn1//CH23MotorIn2//SB,Bforch2367//SA,Aforch0145PWME=0x00;PWMCTL=0x70;PWMCAE=0x00;PWMPOL=0xFF;PWMPRCLK=0x33;PWMSCLA=0x03;PWMSCLB=0x03;PWMCLK=0xFF;PWMPER01=12000;PWMDTY01=0;PWMPER23=12000;PWMDTY23=0;P
9、WMCNT01=0;PWMCNT23=0;PWME=0x2A;}/************************************************************FunctionName:Main**FunctionDiscription:MainFunction***********************************************************/voidmain(void){/*putyourowncodehere*/PLL_Init();PWM_Init();PIT_Init(
此文档下载收益归作者所有