I have an Orangutan X2 with LCD and VHN2 that I am trying to use to drive a stepper motor. The stepper motor has a built in driver with the following pins:11
1 - Direction, 2 - Clock, 3 - On/Off, 4 - MS2, 5 - MS1, 6 - vcc, 7 - gnd. The Microstep resolution Truth Table Indicates Active Stepping if both MS1 and MS2 are Active. I have connected Pin6 to a power source that can supply enough amps and pin 7 to a ground pin in the 3 x 16 I/I header (outside pin row).
The following code activates the motor but never moves it. I am blinking the lights and sending outputs to the display to show that the program is moving. Also, changing the clock delay results in the encoder light flashing at a different frequency, but does not move the motor. Any help on what I am missing would be most appreciated:
void delay_100us( int d )
{
for( int i=0; i < d; i++ )
{
for ( int j = 0; j <10; j++ )
{
_delay_loop_1(67);
} } }
void motorDriverInit()
{
//Initialize PD1 = MS1, PD2 = MS2, PD3 = Direction, PD4 = Clock to outputs
PORTD |= 1 << PD5; //Turn the Motor to Active
PORTD |= 1 << PD1; // Turn on the MS1 for Full Stepping
PORTD |= 1 << PD2; // Turn on the MS2 for Full Stepping
PORTD |= 1 << PD3; // Turn the direction to clockwise
PORTD |= 1 << PD4; // Turn The clock to Active to go one step
motorStatus = 1; //the motor is now running
}
void cycleMotor( )
{
if ( motorStatus == 0 )
{
PORTD |= 1 << PD4; //generate a clock signal
motorStatus = 1; //the motor is now running
}
else
{
PORTD &= ~(1 << PD4); //generate a clock signal
motorStatus = 0; //the motor is now running
}
}
int main()
{
// the X2's user LEDs are located on PORTC, pins C0, C2, C3, C5, and C7
// so make these pins outputs to get blinking lights
DDRC |= (1 << PC0) | (1 << PC2) | (1 << PC3) | (1 << PC5) | (1 << PC7);
//Initialize PD1 = MS1, PD2 = MS2, PD3 = Direction, PD4 = Clock, PD5 = On/Off to outputs
DDRD |= (1 << PD1) | (1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5);
LCDInit(); // initialize the LCD
SPIInit(); // initialize communications between the two CPU's
motorDriverInit( );
while (1)
{
LCDHome();
LCDClear();
LCDMoveCursor( LCD_ROW_0 );
LCDAddString( "Counter: " );
LCDUInt( abs(counter) ); // print the loop number to the display
LCDMoveCursor( LCD_ROW_1 );
LCDAddString( "M1 Ch A : " );
motor1ChannelA_Revs = motor1ChannelA_Revs + encoders_get_counts_m1( ); //abs(encoders_get_counts_m1());
LCDUInt( abs(motor1ChannelA_Revs) );
LCDMoveCursor( LCD_ROW_2 );
LCDAddString( "M2, ChA : " );
motor2ChannelA_Revs = motor2ChannelA_Revs + abs(encoders_get_counts_m2());
LCDUInt( abs(motor2ChannelA_Revs) );
LCDMoveCursor( LCD_ROW_3 ); // get ready to print on the bottom row
LCDAddString( "GA " );
LCDUInt (global_last_M1A_val );
LCDAddString( "GB " );
LCDUInt (global_last_M1B_val );
PORTC = 0x01; // drive PC0 high, all other PORTC outputs low for blinking lights
//delay_ms(50); // delay here for 200 ms
counter = counter + 1;
int w = 6;
cycleMotor( );
delay_100us( w );
}