Issue driving a stepper trough an Attiny13

Hi , i hope someone here knows a bit or two about programming attiny13's.
because i hit a bump, i am not an expert and i am stuck now.

what i want to do is directly drive a micro stepper trough an attiny13.
i do not need to control the speed, only the motion , forward or backwards.
and the trigger from that comes from an RC signal on PB1.

but when putting power to this attiny13, the motor does not react in any way.
i tried with a similar code directly from the arduino and that did work.
but somehow in the translation to the attiny13 its goes wrong.

( yes i know best way is to use a driver, but i can't for this project)

#define INP PB1 // Define input pin as RCPIN
#define A PB0   
#define A_bar PB2                 
#define B PB3                   
#define B_bar PB4                   
#define x 4000 // Smaller values result in more speed
#define stepsPerRevolution 24 // You can find the number of steps required to make a complete revolution in the data sheet of your motor

int main(void) 
{
  // Set motor pins as outputs
  DDRB |= _BV(A) | _BV(A_bar) | _BV(B) | _BV(B_bar); 
  // Set input pullup for both INP and INP2
  PORTB |= (1 << INP); 

  while (1) 
  {
    // Stop timer
    TCCR0B = 0; 
    // Clear timer
    TCNT0 = 0; 
    // Wait for servo pulse to begin on INP2
    loop_until_bit_is_set(PINB, INP); 
    // Start timer and divide timer clock by 64
    TCCR0B |= (1 << CS01) | (1 << CS00);  
    // Wait for servo pulse to end on INP2
    loop_until_bit_is_clear(PINB, INP); 
    // Read timer to obtain pulse width
    byte pulse_width = TCNT0; 

    // If pulse width is greater than 120, rotate motor clockwise
    if (pulse_width > 120) {
      // Rotate motor for one quarter revolution
      for (int i = 0; i < (stepsPerRevolution / 4); i++) {
        digitalWrite(A, HIGH);
        digitalWrite(A_bar, LOW);
        digitalWrite(B, HIGH);
        digitalWrite(B_bar, LOW);
        _delay_ms(x);

        digitalWrite(A, LOW);
        digitalWrite(A_bar, HIGH);
        digitalWrite(B, HIGH);
        digitalWrite(B_bar, LOW);
        _delay_ms(x);

        digitalWrite(A, LOW);
        digitalWrite(A_bar, HIGH);
        digitalWrite(B, LOW);
        digitalWrite(B_bar, HIGH);
        _delay_ms(x);

        digitalWrite(A, HIGH);
        digitalWrite(A_bar, LOW);
        digitalWrite(B, LOW);
        digitalWrite(B_bar, HIGH);
        _delay_ms(x);
      }
    } 
    // If pulse width is less than 70, rotate motor counterclockwise
    else if (pulse_width < 70) {
      // Rotate motor for one quarter revolution
      for (int i = 0; i < (stepsPerRevolution / 4); i++) {
        digitalWrite(A, HIGH);
        digitalWrite(A_bar, LOW);
        digitalWrite(B, LOW);
        digitalWrite(B_bar, HIGH);
        _delay_ms(x);

        digitalWrite(A, LOW);
        digitalWrite(A_bar, HIGH);
        digitalWrite(B, LOW);
        digitalWrite(B_bar, HIGH);
        _delay_ms(x);

        digitalWrite(A, LOW);
        digitalWrite(A_bar, HIGH);
        digitalWrite(B, HIGH);
        digitalWrite(B_bar, LOW);
        _delay_ms(x);

        digitalWrite(A, HIGH);
        digitalWrite(A_bar, LOW);
        digitalWrite(B, HIGH);
        digitalWrite(B_bar, LOW);
        _delay_ms(x);
      }
    } 
    // If pulse width is between 70 and 120, stop the motor
    else {
      delay(1);
    }   
  }
}

If you also post the code that worked on the Arduino, someone can maybe spot the difference that made it fail on the Attiny13.

If you got away with that in the past, you were lucky. Perhaps the ATtiny is not so forgiving.

You can safely draw 20 mA from the port pins, but if the load is inductive, the pins MUST be protected from inductive voltage spikes.

Please post a link to the "micro stepper".

This will delay in milliseconds (so 4 seconds), not microseconds. So it turns so slow, that you won't see it. If I change it to 4 it works and I can start/stop the rotation of a steppermotor with a servo signal.

Stepper motor driver does not have to be too big. Here is one that I made a while ago that takes the RC signal on the left and has 4 outputs on the right.

Groeten/regards,
Hans

thank you, indeed that was the issue.
when lowered to 4 it worked.

even you suggested driver is to big, because i work with 1/87 rc, so i have not a lot of room to work with.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.