How to control a stepper motor using SD02B?

Autonomous Robot, Manual Robot, DC Motor Driver, Stepper Motor Driver, Servo, Multi PWM chip.....

Re: How to control a stepper motor using SD02B?

Postby bspin » Mon Nov 07, 2011 2:30 pm

Hey, don't strain yourself to hard Sich.
I am really happy to hear that the code works.
I've migrated this weekend to controlling the motor with PULSE, DIR, EN. And it works !
Really happy about it. Still wish it would have worked with UART.

The code that I am playing with now is below:

CODE: SELECT_ALL_CODE
// this takes the motor through these steps:
// enable motor, keep like this 1 sec
// turn motor one revolution in one direction ( should start with CCW )
// disable motor, keep like this for 1 sec
// enable motor, keep like this 1 sec
// turn motor one revolution in the other direction (CW second time)
// disable motor, keep like this for 1 sec
// repeat the loop

// since I have to use 400 steps to get a full rev, it makes me believe that SD02B is in half step
// One NEEDS to CONNECT the GND from Arduino to GND on SDO2B !!! ( next to Vmotor )

const int PULSE = 2;
const int DIR =  3;
const int EN =  4;

void setup()
{
  pinMode(PULSE, OUTPUT);
  digitalWrite(PULSE, LOW);
  pinMode(DIR, OUTPUT);
  digitalWrite(DIR, LOW);
  pinMode(EN, OUTPUT);
  digitalWrite(EN, LOW);
}

void loop()
{
  for (int direction=0; direction<=1; direction++ )
  {
    digitalWrite(EN, HIGH);
    delay(1000);
    digitalWrite(DIR, direction);   // set direction

      for (int i=0; i<400 ; i++) 
    {
      digitalWrite(PULSE, HIGH);
      delay(1);
      digitalWrite(PULSE, LOW);
      delay(1);
    }
    digitalWrite(EN, LOW);  // disengage the motor
    delay (1000);
  }

}


Questions:
(1)
How do I set micro stepping to None / 2 / 5 / 10 while using PULSE, DIR, EN.? It's on page 5 in the manual. PULSE.
(2)
I know that maximum accepted speed for SD02B is 1Khz or 1000 steps/second.
That's why if I set delays like 0.5 it wont work ? Maybe delays have to be int. Have to look some more into this.

I wish I would be able to turn the motor at higher speeds. Not crazy high. One way is to get it to work in full step. Then if I could send 2Khz that would double it. Not such a big problem though. Some cogs will solve the speed problem.

Thanks again Sich !
bspin
Freshie
 
Posts: 6
Joined: Sun Nov 06, 2011 2:36 pm

Re: How to control a stepper motor using SD02B?

Postby bspin » Mon Nov 07, 2011 3:02 pm

Hi there !
I've tried your code as posted and I don't get any results. Will try again tomorrow. I played tonight with the PULSE DIR EN.
I've tried at some point the write function, instead of print, but gave up on that pretty soon.

How would I figure out the frequency of stepper motors ? Specs sheet ? Trial and error ? Push it till I max it ?
Specs one motors are attached as well !

My PSU has the following specs and there is no current limiting feature. See pics attached.

Thanks again! Sorry for the flood of pics. I am a photographer .. :)
Attachments
IMG_0662.JPG
IMG_0665.JPG
specs_01.JPG
SOYO motor.JPG
motor2.JPG
bspin
Freshie
 
Posts: 6
Joined: Sun Nov 06, 2011 2:36 pm

Re: How to control a stepper motor using SD02B?

Postby sich » Mon Nov 07, 2011 4:03 pm

bspin WROTE:I've migrated this weekend to controlling the motor with PULSE, DIR, EN. And it works !

Good to hear that :D

bspin WROTE:(1) How do I set micro stepping to None / 2 / 5 / 10 while using PULSE, DIR, EN.? It's on page 5 in the manual. PULSE.

Ops...you will need to go back to UART again to change the settings.

bspin WROTE:(2) I know that maximum accepted speed for SD02B is 1Khz or 1000 steps/second.
That's why if I set delays like 0.5 it wont work ? Maybe delays have to be int. Have to look some more into this.

It's a misleading statement in the User Manual. Really sorry about it. The 1kHz is actually a safe range for most stepper motor, but not the max frequency the driver can detect. As far as I've tested, it can go up to 20kHz with my stepper motor. So it depends on your motor's performance.
About the delay, are you saying when you write delay(0.5); and it doesn't work? It has to do with the delay function. The argument of delay function is unsigned long. Have a look here. So it can't accept any parameter in float.

bspin WROTE:I've tried your code as posted and I don't get any results. Will try again tomorrow. I played tonight with the PULSE DIR EN.
I've tried at some point the write function, instead of print, but gave up on that pretty soon.

I just learnt that the User Manual hasn't been updated after the firmware update not long ago. After the update, any baudrate and microstepping changes to the driver will be saved in the flash. So may be after the 'unknown' string being received by the driver, the driver is operating at an unknown baudrate (may or may not 9600). The result is you can't communicate with the driver at 9600bps. One way of solving it is to send all possible baudrates to the driver, and at last, send the desired baudrate.
[EDIT]
CODE: SELECT_ALL_CODE
  Serial.begin(9600);
  Serial.print('U');  // set motor controller baudrate to
  Serial.write(1);    // 9600bps
  Serial.begin(19200);
  Serial.print('U');  // set motor controller baudrate to
  Serial.write(1);    // 9600bps
  Serial.begin(38400);
  Serial.print('U');  // set motor controller baudrate to
  Serial.write(1);    // 9600bps
  Serial.begin(57600);
  Serial.print('U');  // set motor controller baudrate to
  Serial.write(1);    // 9600bps
  Serial.begin(9600); // use 9600 to communicate after this
[/EDIT]

Hopefully you can set it back to 9600 and get my previous code running after that. If the UC00A can be used, it's even easier. With a few click on the GUI, you can set it back to your desired baudrate.

bspin WROTE:How would I figure out the frequency of stepper motors ? Specs sheet ? Trial and error ? Push it till I max it ?
Specs one motors are attached as well !

My way of doing it is through trial and error since most of the stepper I have don't come with the datasheet. By increasing the speed until it fails to run smoothly, the value before it is the max frequency. Please note that a free run and a loaded motor will give different values too.
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: How to control a stepper motor using SD02B?

Postby bspin » Tue Nov 08, 2011 1:25 pm

Really short one !
It works, still some strange, not quite as expected behaviors, but I think it is a matter of tuning to the motors now, and learning what does what.
BTW .. is there any order in which the commands should be sent to UART?
Like ( O / > / G ) or ( O / G ) or ( S(N) / O / > / G ) ?

Will do some tests, will post results in a few days.
The non-resetting of the baud rate with the reset button created all the confusion. At some point I did tried some different baud rates .. it never occurred to me that it will never default back to 9600 with reset button.
Thanks for all the help !
bspin
Freshie
 
Posts: 6
Joined: Sun Nov 06, 2011 2:36 pm

Re: How to control a stepper motor using SD02B?

Postby sich » Tue Nov 08, 2011 3:38 pm

bspin WROTE:BTW .. is there any order in which the commands should be sent to UART?
Like ( O / > / G ) or ( O / G ) or ( S(N) / O / > / G ) ?

The driver receives any command you send to it without taking care of the sequence. So to get it goes the way you want, sending the direction, speed & microstep commands first before run command is recommended. Anyway it's up to you on how you want the driver to react. If you command the driver to run without sending any direction and speed value, it'll run at what it has in its memory.

bspin WROTE:The non-resetting of the baud rate with the reset button created all the confusion. At some point I did tried some different baud rates .. it never occurred to me that it will never default back to 9600 with reset button.

Really sorry about that...will update the User Manual soon.

bspin WROTE:Thanks for all the help !

You're welcome! ;)
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: How to control a stepper motor using SD02B?

Postby winsonleesw » Thu Dec 15, 2011 4:31 am

Im using PIC 16F877A connected to Driver SD02B to control my two stepper motor LINIX Stepping Motor ( Product Code : 42BYGHD-439 ), i leave the UART open, mean not connect anything, i just want the the step pulse 0 degree to 90 degree, by using MPLAB, but failed to get the result and output, i try to using TRISC1 to be output and then CCP compare mode method to get the pulse, but i want 0 to 90 degree the motor should stop, it still keep continuous rotating. Why? what is the default stepping in this driver??? my motor is 1.8 degree per step, i used on bipolar way. pls help me.....
winsonleesw
Greenhorn
 
Posts: 3
Joined: Thu Dec 15, 2011 4:23 am

Re: How to control a stepper motor using SD02B?

Postby royalstorm7 » Thu Dec 15, 2011 8:52 am

hi winsonleesw
check again about the TRISC1...coz the output shoulb be PORTC...TRISC is the register for the pin direction...if that one is ok...what u do is using counter of 50count and subtract that counter for every step....then jump to stop if the counter is zero....so 1.8*50 = 90 deg....for the speed control u can call a delay between every step...have a try..
tq
roslan
royalstorm7@yahoo.com
find me in facebook
royalstorm7
Apprentice
 
Posts: 52
Joined: Sat Sep 04, 2010 1:37 pm

Re: How to control a stepper motor using SD02B?

Postby winsonleesw » Thu Dec 15, 2011 10:12 am

CODE: SELECT_ALL_CODE
#include <htc.h>
#include "delay.h"

__CONFIG(0x3f71);

unsigned char count, var_RC1;

static interrupt void isr()
{
   if( RD1 == 1 )
   {
      count++;
   }

   if(CCP1IF)     //Interrupts when Timer1 equals CCP1.
   {
      DelayMs(1);
      var_RC1 = !var_RC1;
      RC1 = var_RC1;

      CCP1IF = 0;
      TMR1H = 0;
      TMR1L = 0;
   }
}

void main(void)
{
   TRISC1=0;      //Pulse Voltage
   TRISD1=0;      //Enable Pin
   TRISD2=0;      //output left motor direction
   TRISD3=0;      //output right motor direction
   TRISD4=1;

   //Timer1 Setting
   T1CON = 0x00;   //Turn off Timer1.

   //CCP1 Setting
   CCP1CON = 0x0a;
   CCPR1H = 0x00;
   CCPR1L = 0xa0;

   CCP1IE = 0;   //Turn off CCP1.
   PEIE = 1;
   GIE = 1;

   RD1 = 1;

   //direction(front)
   RD2=1;
   RD3=0;
   count = 0;
   RC1 = 0;
   var_RC1 = 0;

   while(1)
   {
      T1CON = 0x01;   //Turn on Timer1.
      CCP1IE = 1;   //Turn on CCP1.
      
      if( count > 50 )
      {
         RD1=0;
      }
   }      
}


like this program suppose give me 50 step will give me 90 degree, i'm in bipolar method, but it is not working, and totally not using the UART, the driver i use is SD02B and motor is LINIX Stepping Motor ( Product Code :42BYGHD-439 ).this program was apply in MPLAB.
winsonleesw
Greenhorn
 
Posts: 3
Joined: Thu Dec 15, 2011 4:23 am

Re: How to control a stepper motor using SD02B?

Postby royalstorm7 » Thu Dec 15, 2011 12:02 pm

hi winsoonleesw...
it seem the code push RD1=1 for 50 count then RD=0...if yes that is wrong way to control the stepper motor....actually RD1 have to ..1,0,1,0,.....for 50 times.....have a try
tq
roslan
royalstorm7@yahoo.com
find me in facebook
royalstorm7
Apprentice
 
Posts: 52
Joined: Sat Sep 04, 2010 1:37 pm

Re: How to control a stepper motor using SD02B?

Postby winsonleesw » Thu Dec 15, 2011 4:52 pm

But the RD1 is enable pin not pulse output, the pulse output into the drive is RC1. my program is RC1 ....,1,0,1,0.... 50times and then change RD1 = 0 to disable the driver.
winsonleesw
Greenhorn
 
Posts: 3
Joined: Thu Dec 15, 2011 4:23 am

PreviousNext

Return to Robot Controller

Who is online

Users browsing this forum: No registered users and 5 guests

cron