智能车模块源程序+很详细(5)

1970-01-01 08:00

第三届全国大学生智能汽车大赛

PIDoutput=pParams->NegativePIDLimit;、

初始化程序 void RTI_Init(void) {

/* setup of the RTI interrupt frequency */

/* adjusted to get 1 millisecond (1.024 ms) with 16 MHz oscillator */

RTICTL = 0x1f;//5*2^16:48.8hz //0x1f // set RTI prescaler ::晶振16384分频;(低四位+1)*(2^(高三位+9)) CRGINT = 0x80; // enable RTI interrupts; //低四位:1-7,不可为零,否则分频器不工作 }

void SET_PLL(void) {

CLKSEL=0x00; PLLCTL=0xe1; SYNR=2; REFDV=1; PLLCTL=0x60; asm NOP; asm NOP; asm NOP;

while((CRGFLG&0x08)==0); CLKSEL=0x80;

} /*锁相环程序*/

20

第三届全国大学生智能汽车大赛

void ATD_Init(void)

{ ATD0CTL2=0xc0;//不开中断2; ////上电,标志位快速清零 ... ATD队列转换完成中断使能

ATD0CTL3=0x00;//sequence length:8 0; //转换队列长度8,非FIFO存储模式, ATD0CTL4=0x85; //8bus_clk/(2*(5+1))

位精度,AD

时钟为

ATD0CTL5=0x90; //右对齐,无符号数,单次转换队列模式,ch 1 begin,6 channels;多通道8路,从通道0开始

ATD1CTL2=0xc0;//ADPU,fast flag clear

ATD1CTL3=0x30;//sequence length:6,not fifo mode, ATD1CTL4=0x85;//8 clock:bus_clk/(2*(5+1))

bit

decision,ATD

ATD0CTL5=0x90; //右对齐,无符号数,单次转换队列模式,ch 1 begin,6 channels;多通道8路,从通道0开始

} /*ATD初始化程序*/

void Servo_Init(void) //舵机 16位PWM控制 {

PWME_PWME1=0; //disable PWM1 servo PWMPRCLK|= 0x03; //CLKA:8分频

PWMCLK|=0x00 ; //这就是默认值//通道1用clock A时钟源

//24MHZ/8=3M PWMPOL_PPOL1 = 1; //先高电平

PWMCAE=0x00;

21

//对齐方式默认 左对齐

第三届全国大学生智能汽车大赛

PWMCTL_CON01 = 1; //通道1:16BIT 连接

PWMPER01 = 30000;//30000:10ms;;;30000//舵机的周期是10ms 1/3M * x=1/100

//1ms 脉冲 到2ms 脉冲 //1.5ms脉冲对应0度

PWMDTY01 =4500;//4500:1.5ms; //控制3500左极限 5500右极限 4500正中央

PWMCNT01 = 0; //写计数寄存器,会使PWMDTYx,PWMPERx进入锁存器,同时使能通道时会从此值? PWME_PWME1= 1; //PWM通道1输出

} /*舵机初始化程序*/

void Forward_Init(void) // 假定前进方向,初始化函数 {

// PWM3:IN1 // PWM5:IN2 =1 // PWM7:EN

// DDRP = 0xff; //控制输出

PWME_PWME3= 0; PWME_PWME5= 0;

PWMPRCLK|= 0x20; //clock b总线频率的4分频

//通道3用clock B 时钟源

// 24MHZ/4=6M PWMPOL_PPOL5 = 0; //low electrical level first,,high electrical level first ,but high level makes mc33886 disabled

22

第三届全国大学生智能汽车大赛

PWMCAE

//对齐方式默认 左对齐

PWMCTL_CON45 = 1; //16BIT 连接 PWMPER45 = 750; //电机频率8k Hz 1/1.5M*x=1/2KHz

PWMDTY45 = 500; // 占空比精度 1/750 PWMCNT45 = 0;

PWME_PWME5 =1; //PWM通道3输出 }

/*电机初始化程序*/ void ECT_Init(void) //ECT初始化,使用输入捕捉功能 {

TSCR1_TFFCA=1; //automatically clear flag TSCR2 = 0x87; //Timer Overflow interrupt open,TCNT prescaler:24MHZ/128=187.5kHz计数频率

TIOS_IOS0=0; //The corresponding channel acts as an input capture

// ON CH0 PT0;

TCTL4_EDG0A=1; // capture on rising edge only on channel 0

TCTL4_EDG0B=0;

TIE_C0I=1; // Enable Ch1 Interrupts TSCR1_TEN=1; //ENABLE TIMER } 主程序

#include /* common defines and macros */ #include /* derivative information */

23

//启动PWM

第三届全国大学生智能汽车大赛

#pragma LINK_INFO DERIVATIVE \#include \#include\

#define AD_LEVEL 130 #define MID 4785 #define MAXTURN 750 #define DC_Limit 600

#define KP1 (-40) #define KI1 0 #define KD1 (0) #define SPEED 70

//变量定义

int times,exit,exit1,exit_flag;//停车用变量 char zanshi=0;//调速 int Sensor=4785;//舵机 int ave_weight[3]={0,0,0}; int count0=0; int AD_Value[14]; int i;

int atd_value[14];

char boma=0; //拨码开关 int zhidao_speed=0; int wangdao_speed=0;

int chongchu_speed=0;//速度设定 int cha0,cha1;//不完全微分

24


智能车模块源程序+很详细(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:毕业论文加多宝策略分析

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: