示例#1
0
// 2 pin step function
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step2(uint8_t step)
{
    switch (step & 0x3)
    {
	case 0: /* 01 */
	    setOutputPins(0b10);
//	    digitalWrite(_pin[0], LOW);
//	    digitalWrite(_pin[1], HIGH);
	    break;

	case 1: /* 11 */
	    setOutputPins(0b11);
//	    digitalWrite(_pin[0], HIGH);
//	    digitalWrite(_pin[1], HIGH);
	    break;

	case 2: /* 10 */
	    setOutputPins(0b01);
//	    digitalWrite(_pin[0], HIGH);
//	    digitalWrite(_pin[1], LOW);
	    break;

	case 3: /* 00 */
	    setOutputPins(0b00);
//	    digitalWrite(_pin[0], LOW);
//	    digitalWrite(_pin[1], LOW);
	    break;
    }
}
示例#2
0
// 1 pin step function (ie for stepper drivers)
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step1(uint8_t step)
{
    // _pin[0] is step, _pin[1] is direction
    setOutputPins((_speed > 0) ? 0b11 : 0b01); // step HIGH
    // Caution 200ns setup time 
    // Delay the minimum allowed pulse width
    //delayMicroseconds(_minPulseWidth);
    setOutputPins((_speed > 0) ? 0b10 : 0b00); // step LOW

}
示例#3
0
// 1 pin step function (ie for stepper drivers)
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step1(long step)
{
    // _pin[0] is step, _pin[1] is direction
    setOutputPins(_direction ? 0b10 : 0b00); // Set direction first else get rogue pulses
    setOutputPins(_direction ? 0b11 : 0b01); // step HIGH
    // Caution 200ns setup time 
    // Delay the minimum allowed pulse width
    delayMicroseconds(_minPulseWidth);
    setOutputPins(_direction ? 0b10 : 0b00); // step LOW

}
示例#4
0
// 1 pin step function (ie for stepper drivers)
// This is passed the current step number (0 to 7)
// Subclasses can override
void step1(Stepper_t* motor, long step)
{
    // _pin[0] is step, _pin[1] is direction
    setOutputPins(motor, motor->_direction ? 0b10 : 0b00); // Set direction first else get rogue pulses
    setOutputPins(motor, motor->_direction ? 0b11 : 0b01); // step HIGH
    // Caution 200ns setup time
    // Delay the minimum allowed pulse width
    HAL_Delay(motor->_minPulseWidth / 100000); //delayMicroseconds(motor->_minPulseWidth);
    setOutputPins(motor, motor->_direction ? 0b10 : 0b00); // step LOW

}
示例#5
0
void AccelStepper :: stepBackward() { 
	// _pin[0] is step, _pin[1] is direction
    setOutputPins( 0b01); // step HIGH
    // Caution 200ns setup time 
    // Delay the minimum allowed pulse width
    //delayMicroseconds(_minPulseWidth);
    setOutputPins(0b00); // step LOW
	
	_currentPos--; 
	
}
示例#6
0
// 3 pin step function
// This is passed the current step number (0 to 7)
// Subclasses can override
void step3(Stepper_t* motor, long step)
{
    switch (step % 3)
    {
		case 0:    // 100
			setOutputPins(motor, 0b100);
			break;

		case 1:    // 010
			setOutputPins(motor, 0b010);
			break;

		case 2:    //001
			setOutputPins(motor, 0b001);
			break;
    }
}
// Prevents power consumption on the outputs
void    AccelStepper::disableOutputs()
{   
    if (! _interface) return;

    setOutputPins(0); // Handles inversion automatically
    if (_enablePin != 0xff)
        digitalWrite(_enablePin, LOW ^ _enableInverted);
}
// 3 pin step function
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step3(long step)
{
	switch (step % 3)
	{
		case 0:    // 100
			setOutputPins(0b100);
			break;

		case 1:    // 001
			setOutputPins(0b001);
			break;

		case 2:    //010
			setOutputPins(0b010);
			break;
	}
}
示例#9
0
// 4 pin step function for half stepper
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step4(long step)
{
    switch (step & 0x3)
    {
	case 0:    // 1010
	    setOutputPins(0b0101);
	    break;

	case 1:    // 0110
	    setOutputPins(0b0110);
	    break;

	case 2:    //0101
	    setOutputPins(0b1010);
	    break;

	case 3:    //1001
	    setOutputPins(0b1001);
	    break;
    }
}
示例#10
0
// 2 pin step function
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step2(long step)
{
    switch (step & 0x3)
    {
	case 0: /* 01 */
	    setOutputPins(0b10);
	    break;

	case 1: /* 11 */
	    setOutputPins(0b11);
	    break;

	case 2: /* 10 */
	    setOutputPins(0b01);
	    break;

	case 3: /* 00 */
	    setOutputPins(0b00);
	    break;
    }
}
示例#11
0
// 2 pin step function
// This is passed the current step number (0 to 7)
// Subclasses can override
void step2(Stepper_t* motor, long step)
{
    switch (step & 0x3)
    {
		case 0: /* 01 */
			setOutputPins(motor, 0b10);
			break;

		case 1: /* 11 */
			setOutputPins(motor, 0b11);
			break;

		case 2: /* 10 */
			setOutputPins(motor, 0b01);
			break;

		case 3: /* 00 */
			setOutputPins(motor, 0b00);
			break;
    }
}
示例#12
0
// 3 pin half step function
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step6(long step)
{
    switch (step % 6)
    {
	case 0:    // 100
	    setOutputPins(0b100);
            break;
	    
        case 1:    // 101
	    setOutputPins(0b101);
            break;
	    
	case 2:    // 001
	    setOutputPins(0b001);
            break;
	    
        case 3:    // 011
	    setOutputPins(0b011);
            break;
	    
	case 4:    // 010
	    setOutputPins(0b010);
            break;
	    
	case 5:    // 011
	    setOutputPins(0b110);
            break;
	    
    }
}
示例#13
0
// 3 pin half step function
// This is passed the current step number (0 to 7)
// Subclasses can override
void step6(Stepper_t* motor, long step)
{
    switch (step % 6)
    {
		case 0:    // 100
			setOutputPins(motor, 0b100);
			break;

		case 1:    // 110
			setOutputPins(motor, 0b110);
			break;

		case 2:    // 010
			setOutputPins(motor, 0b010);
			break;

		case 3:    // 011
			setOutputPins(motor, 0b011);
			break;

		case 4:    // 001
			setOutputPins(motor, 0b001);
			break;

		case 5:    // 101
			setOutputPins(motor, 0b101);
			break;
    }
}
示例#14
0
// 4 pin step function for half stepper
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step4(uint8_t step)
{
    switch (step & 0x3)
    {
	case 0:    // 1010
	    setOutputPins(0b0101);
//	    digitalWrite(_pin[0], HIGH);
//	    digitalWrite(_pin[1], LOW);
//	    digitalWrite(_pin[2], HIGH);
//	    digitalWrite(_pin[3], LOW);
	    break;

	case 1:    // 0110
	    setOutputPins(0b0110);
//	    digitalWrite(_pin[0], LOW);
//	    digitalWrite(_pin[1], HIGH);
//	    digitalWrite(_pin[2], HIGH);
//	    digitalWrite(_pin[3], LOW);
	    break;

	case 2:    //0101
	    setOutputPins(0b1010);
//	    digitalWrite(_pin[0], LOW);
//	    digitalWrite(_pin[1], HIGH);
//	    digitalWrite(_pin[2], LOW);
//	    digitalWrite(_pin[3], HIGH);
	    break;

	case 3:    //1001
	    setOutputPins(0b1001);
//	    digitalWrite(_pin[0], HIGH);
//	    digitalWrite(_pin[1], LOW);
//	    digitalWrite(_pin[2], LOW);
//	    digitalWrite(_pin[3], HIGH);
	    break;
    }
}
示例#15
0
// Prevents power consumption on the outputs
void disableOutputs(Stepper_t* motor)
{
    if (! motor->_interface) return;

    setOutputPins(motor, 0); // Handles inversion automatically

    if (motor->_enablePin != 0xff) // If enable pin used
    {
        //Arduino: pinMode(motor->_enablePin, OUTPUT);
    	GPIO_InitTypeDef GPIO_InitStruct;
		GPIO_InitStruct.Pin = motor->_enablePin;
		GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
		GPIO_InitStruct.Pull = GPIO_PULLUP;
		GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
		HAL_GPIO_Init(motor->_GPIOxEnablePin, &GPIO_InitStruct);

        //Arduino: digitalWrite(motor->_enablePin, LOW ^ motor->_enableInverted);
        if (0x00 ^ motor->_enableInverted) HAL_GPIO_WritePin(motor->_GPIOxEnablePin, motor->_enablePin, GPIO_PIN_SET);
        else HAL_GPIO_WritePin(motor->_GPIOxEnablePin, motor->_enablePin, GPIO_PIN_RESET);
    }
}
示例#16
0
// 4 pin step function
// This is passed the current step number (0 to 7)
// Subclasses can override
void AccelStepper::step8(uint8_t step)
{
    switch (step & 0x7)
    {
	case 0:    // 1000
	    setOutputPins(0b0001);
            break;
	    
        case 1:    // 1010
	    setOutputPins(0b0101);
            break;
	    
	case 2:    // 0010
	    setOutputPins(0b0100);
            break;
	    
        case 3:    // 0110
	    setOutputPins(0b0110);
            break;
	    
	case 4:    // 0100
	    setOutputPins(0b0010);
            break;
	    
        case 5:    //0101
	    setOutputPins(0b1010);
            break;
	    
	case 6:    // 0001
	    setOutputPins(0b1000);
            break;
	    
        case 7:    //1001
	    setOutputPins(0b1001);
            break;
    }
}