Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:52 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Stepper Motors

     Page 2 of 2    
Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 03:05am 28 Jul 2023
Copy link to clipboard 
Print this post

The code I now have.
SETPIN 15,DOUT
 SETPIN 16,DOUT
 SETPIN 17,DOUT
 SETPIN 18,DOUT
 dim FWD%(3)=(&b0110,&b0101,&b1001,&b1010)
 dim REV%(3)=(&b1010,&b1001,&b0101,&b0110)
 
 do
   fOR x = 1 to 250              ' half a revolution FWD
   FOR STP=0 TO 3               'CW rotation
     PORT(15,4)=FWD%(STP)
     PAUSE 5                    'increase PAUSE value to SLOW rotation.
   NEXT STP
   next x
   Pause 50
   for y = 1 to 250              ' half a revolution REV
   FOR STP=0 TO 3               'CW rotation
     PORT(15,4)=REV%(STP)
     PAUSE 10                   'increase PAUSE value to SLOW rotation.
   NEXT STP
   next y
 LOOP


Two problems, with a Pause of 5 the motor does not turn, I can feel it trying but no go. I have to increase the Pause to 10, it then goes but too slowly but it does not reverse. I thought that by reversing the values the motor would reverse.
This stepper motor is geared down by 64:1, maybe the  motor wont turn it fast enough for the speed I want. At the moment the shaft turns once in about 20 seconds.

Edit.... Looking at the code again I dont think I can use the port command I will try the old code.
Edited 2023-07-28 13:11 by palcal
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
circuit
Senior Member

Joined: 10/01/2016
Location: United Kingdom
Posts: 245
Posted: 09:18am 28 Jul 2023
Copy link to clipboard 
Print this post

  stanleyella said  I was assuming not real stepper motor. Real ones need a big psu and driver. a 3d printer is a good example, mine's using a 328p to do it all...and a driver.


Your assumption is not quite correct; stepper motors come in an enormous range of sizes.  "Real" stepper motors that are tiny are to be found in cameras where they operate the aperture diaphragm, in camera lenses where they achieve focus and so forth.  VERY tiny stepper motors are common in wristwatches. The stepper motor inside the 28BYJ-48 IS a proper stepper motor, just one that is designed to drive a miniature high-ratio gearbox.  The large scale of manufacturing in China keeps the price low, but yes, the quality somewhat variable.
 
Revlac

Guru

Joined: 31/12/2016
Location: Australia
Posts: 1026
Posted: 09:30am 28 Jul 2023
Copy link to clipboard 
Print this post

@Hans,
  Quote  I use this type of stepper on my N scale train turntable. I have supplied code for it, but it is not optimized and not the final code that I will use as I was simply using it to test the turntable.

That turntable looks Good , mostly 3D printed, I run G Scale, a large turn table could be done much the same way I would think, having to pick up a large Loco or wagon by hand to turn it around the other way is not ideal or fun.
Would like to see some of your build and ideas some time if you would like, I expect it would need another thread.
Cheers Aaron
Off The Grid
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4247
Posted: 10:19am 28 Jul 2023
Copy link to clipboard 
Print this post

pascal,

when changing direction on the stepper motor, you should continue from the place you stopped.

forward
STP=0
STP=1
SPT=2
stop (wait 0.1 sec)
reverse
STP=1 (backward from where you sttopped at step 2)
STP=0
STP=3
STP=2

I think you stepper motor is a 5V device. You can (at cost of heat) speed it up (so it may be able to do the 5ms pause) when you connect it to a higher voltage.
But to prevent the windings burn out, you have to limit the current the the maximum the motor can handle. This is often performed by connecting the motor via a resistor.



The resistor must have the right value for maximum speed gain, and minimum heat in the motor.

Volhout

P.S. some motor drivers use PWM to emulate the resistor in a loss-less configuration.
P.P.S. if you vary the PAUSE time you may be able to achieve higher speeds. Start slow (PAUSE=20, then 18,, then 16, then 14 etc...) and at every step (STP value) make the PAUSE shorter until the motor stops advancing. You may find a value that is better than 10 for maximum speed. Each time you reverse, or start rotation, follow that sequence.
Edited 2023-07-28 20:25 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4247
Posted: 10:43am 28 Jul 2023
Copy link to clipboard 
Print this post

Pascal,

This should work for you (note I used different IO pins. Change these back to your setup...)

'interface definition
SetPin 4,DOUT
SetPin 5,DOUT
SetPin 6,DOUT
SetPin 7,DOUT
Dim FWD%(3)=(&b0110,&b0101,&b1001,&b1010)

'motor parameters, change these for your motor
curve = 0.95                    'this is acceleration parameter
maxspeed = 5
minspeed = 20

'initial state
STP=0

'the movement
Do
  'move forward
  speed=minspeed
  For x = 1 To 250              ' half a revolution FWD
    STP=(STP+1) Mod 4           ' CW rotation
    Port(4,4)=FWD%(STP)
    speed = Max(speed*curve, maxspeed)
    Pause speed                 ' dynamic PAUSE value controls rotation.
  Next x
  Pause 100
  'move reverse
  speed=minspeed
  For x = 1 To 250              ' half a revolution REV
    STP=(STP+3) Mod 4           ' CCW rotation (SPT+3 is equal to STP-1)
    Port(4,4)=FWD%(STP)
    speed = Max(speed*curve, maxspeed)
    Pause speed                 ' dynamic PAUSE value controls rotation.
  Next x
  Pause 100
Loop


P.S. the trick with STP+3 equals STP-1 is that it does the same, but never gets negative.
P.P.S. you should adapt the motor specific parameters to get the best out of your motor.
Edited 2023-07-28 21:09 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Hans

Senior Member

Joined: 18/10/2022
Location: Canada
Posts: 116
Posted: 06:46pm 28 Jul 2023
Copy link to clipboard 
Print this post

  Revlac said  @Hans
That turntable looks Good , mostly 3D printed, I run G Scale, a large turn table could be done much the same way I would think, having to pick up a large Loco or wagon by hand to turn it around the other way is not ideal or fun.
Would like to see some of your build and ideas some time if you would like, I expect it would need another thread.


Hi Aaron;

Yes, a new thread would be better. It probably wasn’t a good idea to post on someone else’s thread, sorry guys, but it was related to the same stepper that palcal was using.

This turntable is all 3-D printed on an FDM printer Creality 3. I also have an Elegoo Mars Pro resin printer.

The contact me page doesn’t seem to be working as I was going to contact the forum manager to ask if there was a way to create a model train Electronics specific forum. That might have some interest to a number of people I know.

Hans …
 
DaveJacko
Regular Member

Joined: 25/07/2019
Location: United Kingdom
Posts: 76
Posted: 09:27pm 28 Jul 2023
Copy link to clipboard 
Print this post

Hans wanted to know about this stepper board...
have a look for this on ebay, to get you started.

"CNC Shield V3 - A4988 Stepper Motor Driver Expansion Board for RepRap 3D Printer"

quite a nice litle board that carries up to 4 stepper drives
regs
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 09:41pm 28 Jul 2023
Copy link to clipboard 
Print this post

@Volhout
        That code does not run the motor at all, I can feel it trying and I also feel it when it tries to reverse but no movement. With my code I can get it to run CW but not CCW.
Edited 2023-07-29 07:42 by palcal
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2137
Posted: 11:00pm 28 Jul 2023
Copy link to clipboard 
Print this post

  Hans said   I was going to contact the forum manager to ask if there was a way to create a model train Electronics specific forum.
"Other Stuff" page sometimes has model railway threads.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 01:07am 29 Jul 2023
Copy link to clipboard 
Print this post

@ Volhout
         I have managed to get the motor to run with your code by commenting out the line  
speed = Max(speed*curve, maxspeed)

and setting the speed to 10. But it only travels clockwise it does not reverse.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 06:04am 29 Jul 2023
Copy link to clipboard 
Print this post

@ Volhout
         I have it working finally using a different step sequence. There was no information with the motor so I went by a magazine article that appeared to use the same motor. There is a lot of information for Arduino but Arduino code and Chinese are very similar to me. So after a lot of searching I found this Full Step sequence
&b1000,&b0100,&b0010,&b0001

It works, It just needs some work on the speed.
There is another sequence I will try tomorrow
&b1001,&b1100,&b0110,&b0011

"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4247
Posted: 06:52am 29 Jul 2023
Copy link to clipboard 
Print this post

Pascal,

I know where it went wrong. The patterns is closely tied to how the coils are connected to the io pins.
Good that you found a working pattern

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 08:36am 29 Jul 2023
Copy link to clipboard 
Print this post

The annoying thing is, I had one of these running some time ago and I've been looking for the code. I can't find it, but I know it's on a SD card somewhere....
IIRC I modified the recommended code for the Arduino "experimenter" kit. They aren't too horrible as long as you don't want accurate positioning or a decent speed. :) Good for experimenting with as the supplied driver board has LEDs and the motor shaft isn't running too fast so you can see what's happening.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 08:36am 29 Jul 2023
Copy link to clipboard 
Print this post

@ Volhout, Thanks for your help
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024