235 Stepper Motors - k3ng/k3ng_rotator_controller GitHub Wiki

Stepper Motors

The K3NG rotator project is able to drive stepper motors for both azimuth and elevation movement.

In the file rotator_features.h uncomment the line #define FEATURE_STEPPER_MOTOR

Note the comment regarding the use of Timerfive library. On an Arduino ATMEGA2560 it is desirable to use timer 5 for the timer interrupt facility as this avoids any possible issue with other Arduino functions that might use Timer 1.

The code is set up to drive the motors through an intermediary stepper motor controller. The K3NG rotator code code provides step (pulse) and direction signals and the stepper motor controller sequences the connection and polarity of currents to the motor windings. This assumes bipolar stepper motors, however different types of stepper could be controlled with the appropriate stepper motor controller device. The interface to the K3NG code on a microcontroller must not require anything more than step (pulse) and direction signals.

The relevant pins are defined in the file rotator_pins.h and for azimuth are -

#define rotate_cw 6 // goes high to activate rotator R (CW) rotation - pin 1 on Yaesu connector

#define rotate_ccw 7 // goes high to activate rotator L (CCW) rotation - pin 2 on Yaesu connector

#define az_stepper_motor_pulse 0

and for elevator are -

#define rotate_up 8 // goes high to activate rotator elevation up

#define rotate_down 9 // goes high to activate rotator elevation down

#define el_stepper_motor_pulse 0

Defined variables in rotator_settings.h for the stepper motors are -

#define AZ_VARIABLE_FREQ_OUTPUT_LOW 31 // Frequency in hertz of minimum speed

#define AZ_VARIABLE_FREQ_OUTPUT_HIGH 2000 // 100 // Frequency in hertz of maximum speed

#define EL_VARIABLE_FREQ_OUTPUT_LOW 31 // Frequency in hertz of minimum speed

#define EL_VARIABLE_FREQ_OUTPUT_HIGH 100 // Frequency in hertz of maximum speed

Closed loop control is implemented. The code does not simply count pulses to determine where the position of the stepper motor is. A position feedback device of some form is required - such as a potentiometer or attitude sensing device.

With the above definitions connect az_stepper_motor_pulse pin to the step/pulse pin of the stepper motor controller of the azimuth motor. The direction pin of the stepper motor controller can be connected to either the rotate_cw or rotate_ccw pin. One of those pins will provide a direction of rotation that is appropriate for your mechanical configuration and the other pin will provide rotation in the opposite sense. Select the one suitable for your implementation.

Similarly for elevator control with the rotate_up and rotate_down pins controlling the direction of rotation and el_stepper_motor_pulse providing the step/pulse signal.

How the stepper motor pulse is generated

The stepper motor pulse is created in a timer interrupt routine. This timer interrupt is triggered every 250us.

Externally to the interrupt routine a global counter variable is set which relates to the desired frequency of the pulse train and inside the interrupt routine another counter is incremented and compared with the global value. When the internal counter exceeds the global value it toggles the state of the pulse pin.

Since it is possible to toggle the pulse pin with every call to the interrupt routine (the global counter value would be 1 and exceeded by the internal counter with every interrupt call) a full on/off cycle of the pulse pin can occur every 500us and therefore the maximum rate of pulse generation is 2000Hz.

Global counter values (all the way up to 2000) will produce lower frequency pulse generation with frequencies as low as 1Hz being possible. The global counter is varied during the ramp up and slow down phases of motor movement, otherwise the motors will move at the maximum speed (maximum pulse frequency - see settings discussed below).

The values specified for AZ_VARIABLE_FREQ_OUTPUT_HIGH and EL_VARIABLE_FREQ_OUTPUT_HIGH must not be higher than 2000, as that value results in the maximum pulse frequency that the interrupt routine can produce. Specifying values higher than 2000 will result in no pulses being generated and the motor will not move.