智能车电机测试程序.doc

上传人:自*** 文档编号:126241846 上传时间:2020-03-23 格式:DOC 页数:4 大小:42.95KB
返回 下载 相关 举报
智能车电机测试程序.doc_第1页
第1页 / 共4页
智能车电机测试程序.doc_第2页
第2页 / 共4页
智能车电机测试程序.doc_第3页
第3页 / 共4页
智能车电机测试程序.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《智能车电机测试程序.doc》由会员分享,可在线阅读,更多相关《智能车电机测试程序.doc(4页珍藏版)》请在金锄头文库上搜索。

1、/* * Motor_Test* (c) Copyright 2009-2010, DEMOK * All Rights Reserved * V1.1.0 */#include /* common defines and macros */#include derivative.h /* derivative-specific definitions */unsigned int CurrentVelocity=0;unsigned int WholeVelocity=0;unsigned int vTmpPIT=0;unsigned int flag=0;/* FunctionName:

2、PLL_Init* FunctionDiscription: Clock Initialization* FunctionStatement:BusClock is 48MHz*/void PLL_Init(void) /PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1) CLKSEL=0x00; PLLCTL_PLLON=1; SYNR=0XC0 | 0X05; REFDV=0X80 | 0X01; POSTDIV=0X00; _asm(nop); _asm(nop); while(0=CRGFLG_LOCK); CLKSEL_PLLSEL=1;/* FunctionNam

3、e:PIT_Init* FunctionDiscription:PeriodicInterruptTimer Initialization* FunctionStatement:Interrupt Time is 20ms*/void PIT_Init(void)/定时中断初始化函数 0.01s=10ms定时中断设置 PITCFLMT_PITE=0; PITCE_PCE0=1; PITMTLD0=240-1; PITLD0=2000-1; PITINTE_PINTE0=1; PITCFLMT_PITE=1;/* FunctionName:PWM_Init* FunctionDiscriptio

4、n:PulseWidthModulation Initialization* FunctionStatement: PWM1 is assigned to MotorIn1 PWM3 is assigned to MotorIn2*/void PWM_Init(void) /CH01 Motor In1 /CH23 Motor In2 /SB,B for ch2367 /SA,A for ch0145 PWME = 0x00; PWMCTL = 0x70; PWMCAE = 0x00; PWMPOL = 0xFF; PWMPRCLK = 0x33; PWMSCLA = 0x03; PWMSCL

5、B = 0x03; PWMCLK = 0xFF; PWMPER01=12000; PWMDTY01=0; PWMPER23=12000; PWMDTY23=0; PWMCNT01 = 0; PWMCNT23 = 0; PWME = 0x2A; /* FunctionName:Main* FunctionDiscription:Main Function*/void main(void) /* put your own code here */ PLL_Init(); PWM_Init(); PIT_Init();EnableInterrupts; DDRB=0XFF; for(;) _FEED

6、_COP(); /* feeds the dog */ /* loop forever */ /* please make sure that you never leave main */* FunctionName:Periodic Interrupt Timer* FunctionDiscription:*FunctionStatement:MotorCotrol Block* */#pragma CODE_SEG _NEAR_SEG NON_BANKED void interrupt 66 PIT0(void) flag+; PITTF_PTF0=1; /-Motor is stopi

7、ng for 1s-/ if(flag=100) PWME = 0x00; PWMDTY01=0; PWMDTY23=0; /-Motor is turning for 2s-/ if(flag=300) PWMDTY01=6000; PWMDTY23=0; PWME = 0x2A; /-Motor is stoping for 1s-/ if(flag=400) PWME = 0x00; PWMDTY01=0; PWMDTY23=0; /-Motor is turning for 2s-/ if(flag=600) PWME = 0x00; PWMDTY01=0; PWMDTY23=6000; if(flag=700) PWME = 0x00; flag=0; /-LEDFlag-/ vTmpPIT+; if(vTmpPIT=10) PORTB=PORTB; vTmpPIT=0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 机械/制造/汽车 > 机械/模具设计

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号