Esempio n. 1
0
void SetPWM(u8 dutycycle){
    T2CON=0x00;
    SetPeriod();
    SetDutyCycle(dutycycle);
    IO_CONFIG_OUT(PWMport,PWMpin);
    T2CON=0b110;
}
Esempio n. 2
0
static char SetSpeed(int motor, unsigned int speed) {
    // TODO add error checking
    motorSpeed[motor] =  speed;
    //printf("\nPWM should be = %f", speed * 80.0);
 /*
    unsigned int pwm = 0;
    if (speed > 0) {
#ifdef USE_BATPWM
        int battery = (float)ReadADPin(BAT_VOLTAGE);
#else
        int battery = 0;
#endif
        float pwm_modifier = 100.0 * ((1.0 - 1.0*(battery/BAT_MAX)) * 2.15);
        printf("\nMultiplier =%f", max((int)pwm_modifier, 0));
        pwm = (unsigned int)(speed * 90.0 + max((int)pwm_modifier, 0));
        //pwm = speed;
    }
    motorPWMValue[motor] = pwm;
    //printf("\nPWM is=%i", pwm);
    pwm = min(pwm, 1000);
    pwm = max(pwm, 0);
*/
    unsigned int pwm = speed;
    motorPWMValue[motor] = pwm;
    pwm = min(pwm, 1000);
    pwm = max(pwm, 0);
    SetDutyCycle(motorPWM[motor], speed);
}
Esempio n. 3
0
//==========================================================================
// Class:			PWMOutput
// Function:		SetRange
//
// Description:		Sets the PWM range (resolution).  Default is 1024.
//
// Input Arguments:
//		range	= unsigned int
//
// Output Arguments:
//		None
//
// Return Value:
//		None
//
//==========================================================================
void PWMOutput::SetRange(unsigned int range)
{
	assert(range <= maxRange);

	pwmSetRange(range);
	this->range = range;
	SetDutyCycle(duty);
}
Esempio n. 4
0
//==========================================================================
// Class:			PWMOutput
// Function:		PWMOutput
//
// Description:		Constructor for PWMOutput class.
//
// Input Arguments:
//		pin		= int, represents hardware pin number according to Wiring Pi
//		mode	= PWMMode, indicating the style of PWM phasing to use
//
// Output Arguments:
//		None
//
// Return Value:
//		None
//
//==========================================================================
PWMOutput::PWMOutput(int pin, PWMMode mode) : GPIO(pin, DirectionPWMOutput)
{
	SetDutyCycle(0.0);
	SetMode(mode);

	range = 1024;
	
	// Set the frequency using the member method just in case something
	// outside of the class manipulated it before-hand.
	SetFrequency(pwmClockFrequency / range / minClockDivisor);
}
Esempio n. 5
0
char RightMtrSpeed(char newSpeed) {
    if ((newSpeed < -10) || (newSpeed > 10)) {
        return (ERROR);
    }
    if (newSpeed < 0) {
        RIGHT_DIR = 0;
        RIGHT_DIR_INV = ~RIGHT_DIR;
        newSpeed = newSpeed * (-1); // set speed to a positive value
    } else {
        RIGHT_DIR = 1;
        RIGHT_DIR_INV = ~RIGHT_DIR;
    }
    if (SetDutyCycle(RIGHT_PWM, newSpeed * 100) == ERROR) {
        return (ERROR);
    }
    return (SUCCESS);
}
Esempio n. 6
0
char LeftMtrSpeed(char newSpeed) {
    if ((newSpeed < -10) || (newSpeed > 10)) {
        return (ERROR);
    }
    if (newSpeed < 0) {
        LEFT_DIR = 0;
        LEFT_DIR_INV = ~LEFT_DIR;
        newSpeed = newSpeed * (-1); // set speed to a positive value
    } else {
        LEFT_DIR = 1;
        LEFT_DIR_INV = ~LEFT_DIR;
    }
    if (SetDutyCycle(LEFT_PWM, newSpeed * 100) == ERROR) {
        //puts("\aERROR: setting channel 1 speed!\n");
        return (ERROR);
    }
    return (SUCCESS);
}