Using timers to send pulses to a stepper motor, but only got vibrations on it.

Hello all.

I am trying to control a stepper motor's velocity with the integrated 8-bit timer2 in an Arduino Uno.

I had set the timer compare interrupt at 255Hz. The motor has 200 steps per revolution, so I was expecting 1,275 rounds per second but only got vibrations on the stepper.

here's my source code

unsigned long tiempo = 0;
int divisor = 0;

void setup() {
    // put your setup code here, to run once:
  // TIMER1 SETUP
  cli(); //PARO LAS INTERRUPCIONES

  //set timer2 interrupt at 255Hz
  TCCR2A = 0;// set entire TCCR2A register to 0
  TCCR2B = 0;// same for TCCR2B
  TCNT2  = 0;//initialize counter value to 0
  // set compare match register for 255hz increments
  OCR2A = 246;// = (16*10^6) / (255*255) - 1 (must be <256)
  // turn on CTC mode
  TCCR2A |= (1 << WGM21);
  // Set CS21 bit CS22 for 256 prescaler
  TCCR2B |= (1 << CS22 | 1 << CS21);
  // enable timer compare interrupt
  TIMSK2 |= (1 << OCIE2A);
  sei();

  Serial.begin(115200);
  tiempo = millis();
}

ISR(TIMER2_COMPA_vect){  
    digitalWrite(8,HIGH);         //here are the pulses to the motor 
    digitalWrite(8,LOW);
}


void loop() {

    // put your main code here, to run repeatedly:

}

What am I doing wrong?

The stepper motor is a NEMA17. Here's the technical details about it
https://reprapworld.com/products/motors/nema17_stepper_motor_1_8_degrees_step_4_8_kg_cm/

Thanks in advance and my apologies if I had grammar mistakes.

Zeke

What am I doing wrong?

In setup, you should declare

pinMode(8,OUTPUT);

Your Timer2 setup looks correct. Where is the output signal going?

What motor driver are you using? How are you powering the driver/motor?

Hi. I added the line

pinMode(8,OUTPUT);

but had no luck

The output signal is going directly to the step pin in the pololou driver DRV8824.

I am powering the motor with the 12v line from a PC power supply.

I guess the stepper is having trouble with the step frequency, but I don't know...

Thanks again

zeke

From the motor specification:
Voltage rating 3.1 V
Current rating 2.5 A

Usual motor specs would be for 2.5A per phase.

Review the specs for the DRV8824, but I don't think it is rated that high.

From the Polulu website Pololu - DRV8824 Stepper Motor Driver Carrier, Low Current

This stepper motor driver lets you control one bipolar stepper motor at up to 1.2 A output current per coil

so.... I need another driver.

any sugestion?

thanks for your time!!!

zeke