Author Topic: stepper motors and microcontrollers  (Read 5086 times)

0 Members and 1 Guest are viewing this topic.

Offline 555 timer chip guyTopic starter

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
    • Robots and Circuits
stepper motors and microcontrollers
« on: June 09, 2007, 04:54:59 PM »
I am building a robot that uses stepper motors and I am having some trouble, everything was working fine until I wonted to make the motors go faster. here is my PBASIC code for a BS2sx microcontroller I am using to drive my motors:



' {$STAMP BS2sx}
' {$PBASIC 2.5}

SETUP:
STEP1   PIN    0
STEP2   PIN    1
STEP3   PIN    2
STEP4   PIN    3

i     CON    100        'SPEED VALUE


MANE:
STEP1 = 1
PAUSE i
STEP1 = 0

STEP2 = 1
PAUSE i
STEP2 = 0

STEP3 = 1
PAUSE i
STEP3 = 0

STEP4 = 1
PAUSE i
STEP4 = 0

GOTO MANE

END




the only problem is that the pause time only gos down to 1 ms but it needs to be smaller for the motors to
go faster.


Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: stepper motors and microcontrollers
« Reply #1 on: June 09, 2007, 07:04:24 PM »
Have you tried overlapping the signal, ie half-stepping? I know using this technique increases the torque of the motor but it could also speed up the motor.

Also, why not create your own "delay" function? Make a function with a simple loop in it and call that in b/n steps. To change the timing of the delay, increase or decrease the number of loops in the function. You'll have to tune this by hand, or if you have a frequency counter or oscilloscope to verify the speed of the pulses.

- Rommel
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline 555 timer chip guyTopic starter

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
    • Robots and Circuits
Re: stepper motors and microcontrollers
« Reply #2 on: June 09, 2007, 09:52:59 PM »
I have tyred that but still the smallest period of time I could get it down to was still 1 ms

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: stepper motors and microcontrollers
« Reply #3 on: June 09, 2007, 10:29:35 PM »
I am assuming that you tried the "half-stepping" part and failed.


For the second part of my comment. If you write your own "delay" function, the actual delay will be a factor of your clock rate (ie how fast the MCU is processing instructions). Most MCU instructions do not execute in 1ms, unless your clock rate is 1 instruction per millisecond. You could do something like this in C:

Code: [Select]
void my_delay(int delay)
{
  int i = 0;
  int j = 0;

  for (i = 0; i < delay; i++)
     for (j = 0; j < delay; j++)

return;
}

So in your main code:

Code: [Select]
step(1);
my_delay(100);
step(2);
my_delay(100);

- Rommel
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline 555 timer chip guyTopic starter

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
    • Robots and Circuits
Re: stepper motors and microcontrollers
« Reply #4 on: June 10, 2007, 10:30:14 PM »
(E how fast the MCU is processing instructions). Most MCU instructions do not execute in 1ms, unless your clock rate is 1 instruction per millisecond.



my microcontroller is 50MHz and has a program execution speed of 10,000 instructions a second, plenty fast to time intervals under 1 ms the only problem is I don't know how :'(


please explain how to create my own delay function in PBASIC I don't know c very well


thanks

Offline frank26080115

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: stepper motors and microcontrollers
« Reply #5 on: June 10, 2007, 10:43:20 PM »
Code: [Select]
' {$STAMP BS2sx}
' {$PBASIC 2.5}
delayt VAR Word
counter VAR word

Main:
' do something here
delayt = 255 ' change this
GOSUB calldelay
GOTO Main ' loops

calldelay:
FOR counter = 1 TO delayt
delayt = delayt ' this does nothing but waste time
NEXT
return

something like that

can a sx chip drive a stepper on its own?

Offline 555 timer chip guyTopic starter

  • Full Member
  • ***
  • Posts: 105
  • Helpful? 0
    • Robots and Circuits
Re: stepper motors and microcontrollers
« Reply #6 on: June 13, 2007, 09:07:14 AM »
thanks

 


Get Your Ad Here