示例#1
0
void carInit(car *c)
{
	c->ornt = &orient;
	c->pos = &mouz;
	c->route = &route;
	c->status = 0;
	
	initMotorControl();
	initSteering();
	startPID();	
	//initHorn();
}
示例#2
0
文件: pwm.c 项目: stealth07/LAB3_CODE
void initPWM(){
    
    initMotorControl();
    ANSELD = 0x0000;
    ANSELF = 0x0000;
    //-------------------------------------
    //FOR MOTOR 1 LEFT
    //-------------------------------------
    OC1CON = 0x0000; //Turn off OC1 while doing setup
    
    T2CONbits.TCKPS = 0;
    //PERIOD CONTROL
    PR2 = 1023;
    TMR2 = 0;
    //PULSE WIDTH CONTROL OCxRS / PR2 = duty cycle
    OC1RS = 255;    //REAL-TIME UPDATE
    OC1R = 0;       //UPDATED BY OCxRS EVERY CLOCK CYCLE
    
    T2CONbits.TON = 1; //ENABLE CN
    
    OC1CONbits.OCTSEL = 0;
    OC1CONbits.OCM = 6; //6
    OC1CONbits.ON = 1;
    OC1CONSET = 0x8000; //Enable OC1
    //-------------------------------------
    //FOR MOTOR 2 RIGHT
    //-------------------------------------
    OC3CON = 0x0000; //Turn off OC3 while doing setup
 
    T3CONbits.TCKPS = 0;
    //PERIOD CONTROL
    PR3 = 1023;
    TMR3 = 0;
    //PULSE WIDTH CONTROL OCxRS / PR2 = duty cycle
    OC3RS = 255;    //REAL-TIME UPDATE
    OC3R = 0;       //UPDATED BY OCxRS EVERY CLOCK CYCLE
    
    T3CONbits.TON = 1; //ENABLE CN
    
    OC3CONbits.OCTSEL = 1; //selects Timer to be used
    OC3CONbits.OCM = 6; //6
    OC3CONbits.ON = 1;
    OC3CONSET = 0x8000; //Enable OC3
}