running a stepper using high/low, problem

captnemo

New Member
Maybe someone can shed some light on this. I'm running two stepper motors using an 20M2 via two ULN2003 boards. You know the ones with the LED's' and connectors.
I'm controlling the steppers by doing in a typical "high b.0: low b.1: high b.2: high b3 then a pause. This is done for every step. I slowed the program down with long pauses between steps, so I could see what what causing the stepper not to run smoothly. It appears one or two of the LED's on the board are lighting up very dim and only for a brief time when they shouldn't be. I think this is causing the stepper to run rough. What could cause this, or is this inherent when using the high/low to run a steppers?
I'm not running the steppers at the same time, so only four outputs are being used. The problem exists no matter what ULN2003 board I use or stepper. The steppers are the common, geared ones (28YBJ-48) that are usually sold with the ULN2003 boards.

Also, I was going to originally use binary to control the output's which is fine, if you are going to run two steppers the exact same distance at the same time, since it appears you can't separate the B.0 thu B.7 into two groups of four. You have to control all eight bits at the same time, which means if you write 00001111, to control one stepper the stepper connected to the 0000 outputs will not move, so it's all eight bits in the command or nothing. That's why I used the high/low system.
However, since I'll only be running one stepper at a time. I guess I could use the binary control system. Who cares if the other steppers control lines are zero's (off) when it's not being run anyways.
It does appear you could run two steppers at the same time with two different steps and pauses by using a 28X or a 28X1. However, you run into the same problem having to use eight outputs for each stepper. The 28X and X1 simply gives you more outputs.

Attached is the program. I'll be connecting switches to control; auto/man, jog, direction, stepper selection, full/half step mode. I will also attempt to use C.1 and C.0
connected to a pot. to set the distance; where C.1 (adc input x 200 = W6), this should give me up to 51,000 steps max. since 255 x 200= 51,000.
The speed (pause between steps) would be C.0 (adc input x (say 50 or whatever) = W8 (don't want the pauses to be too long).
I haven't written the jog portion yet, and haven't checked all the sequence's because I ran into the above problem.

This is not a big deal, as I'm only doing this in order to put some schematics and some programs to operate steppers, on the Forum, for learning purposes. As you can see I
can use some learning myself.
 

Attachments

WhiteSpace

Well-known member
Hi @captnemo - I've been battling with steppers over the last few weeks too, rotating a laser range sensor to create a scanner. It combines the step angle with the range from the laser to calculate x,y coordinates: https://picaxeforum.co.uk/threads/scanning-tof10120-with-output-to-oled.32283/ . I have attached two versions of the code there, which may help a little. I have used the binary codes to pins approach, on the B pins of a 28x2. To drive one stepper, I masked off the pins above B.3. If you want to drive two steppers independently, can you use B.0 to B.3 and A.0 to A.3? I'm not familiar with the 28X or 28X1 so I 'm not sure if they have the same pin setup. A quick glance at the manual suggests that there are other blocks of 4 output pins on those Picaxes which you could use. Or is it possible to add (is bitwise AND the right term?) two sets of binary instructions doing different things for the two motors, to produce two separate results on the two "halves" of the B.0 to B.7 block of pins? One part of the code would work out the motor 1 code, another the motor 2 code, then combine them and send them to the B pins. I think both motors might need to be stepping at the same speed, unless you can control the step speed by just not advancing the step code, and holding the step in order to slow it down.

I hope that helps. Happy to discuss further if you would like to explore any of these ideas further - although I'm sure someone else will have better answers than these!
 

AllyCat

Senior Member
Hi,
It appears one or two of the LED's on the board are lighting up very dim and only for a brief time when they shouldn't be. I think this is causing the stepper to run rough. What could cause this, or is this inherent when using the high/low to run a steppers?
Possibly it's the delay between the execution of the first and last commands in lines such as high B.0:low B.1:low B.2:high B.3. Each instruction executes in about 400us (for High / Low with a 20M2 at 4 MHz) so there will be about a 1.2 ms delay between B.0 and B.3 being updated. You may be able to optimise the sequence of B.0 ... B.3 in each list, but there are other solutions......

it appears you can't separate the B.0 thu B.7 into two groups of four. You have to control all eight bits at the same time,
Yes, you have to write to the whole port, but it's not difficult to "build" an appropriate byte to send to the port. For example, suppose you have the four bits for each motor in the low 4 bits of variable Symbols "StepperA" and "StepperB" (e.g. B2 and B3). Then you can simply write PINSB = StepperB * 16 OR StepperA. If you're not comfortable with the OR bitwise logical operator, in this case you can simply use a "+" instead.
Also, if you need to change a few bits on a port which has already been written, then you can read the values back with e.g. b1 = OUTPINSB , modify the required pins (i.e. bits in b1) and then write the value back with {OUT}PINSB = b1
________

The program could be written much more efficiently, which may also help the speed. For example, the bit-sequences can use a "lookup table", such as LOOKUP SequenceNumber , (%0001 , %0010 , %0100 , %1000) , StepperA .
Or even directly from a table, e.g.:
DATA baseaddress , (%0001 , %0010 , %0100 , %1000)
offset = SequenceNumber + baseaddress
READ offset , StepperA
.

Also by using individual bits to build up your SCENARIOs, you can use a SELECT .. CASE structure, or even more efficiently a BRANCH... or ON .. GOTO ... command. Not directly derived from (or compatible with) your code, but the "bare bones" might be:
Code:
Symbol  flags = b0
Symbol FullStep = bit0  
Symbol StepperA = bit1
Symbol Auto = bit2
   FullStep    = pinc.4       '1 is full steps.
   StepperA = pinc.5         '1 is stepper 1 is selected.
   Auto     = pinc.2            '1 is auto mode

ON flags GOTO  SCENARIO1 , SCENARIO2 , SCENARIO3    ; etc.       ; First label is flags = %000 , next %001 , etc.
Cheers, Alan.
 

WhiteSpace

Well-known member
Alan has (as usual) explained rather more authoritatively what I was thinking above, when I suggested using two separate sets of 4 bits to drive the two motors, combining them into a single byte for the 8 B pins. In case it helps, I attach the latest version of my stepper code, which has moved on further from the version last posted in my LIDAR thread. If you ignore the sections that calculate and send the positioning data from the LIDAR and the sections that ensure that the stepper arm accurately traces the required 120 degrees, there are some sections of code that deal with forward and reverse stepping, single step and half step (currently REM'd out) and manual stepping, using the lookup method that Alan describes above, which may save you some time if you decide to go down that route. My code takes blocks of 7 steps, simply because that corresponds to the angle of advance that I want for the scanner, but it does so with a FOR...NEXT loop so you should be able to to split out a single step if that's what you want. I should also have added that I am using a driver chip (TC 4469) between the Picaxe and the stepper. I don't know how that compares with your ULN2003, but the principles should be exactly the same. The 4 outputs from the Picaxe to the TC4469 correspond to the 4 outputs from TC 4469 to stepper.
 

Attachments

captnemo

New Member
Thanks for all the suggestions. Since I'm running the steppers, one at a time, I'll try the binary method and fool around with that. But before I do that, I'll speed the processor up to 32Mhz just to see if that gets rid of the pulsing, LED's, just out of curiosity.
I would have been nice, if who ever did the picaxe operating system broke the outputs down into groups of four. This would have been nice to work with steppers and LED displays that have built in decoder/drivers.
Also, an "if then" statement like "if pinc.1=1 then W=15." Instead having to go to a subroutine or label to get a value changed. I know an IF statement can't do these things but it would have been nice. There are no laws that say you can't add to basic programming commands.
 

AllyCat

Senior Member
Hi,
nice, if ..... broke the outputs down into groups of four.
In what way? A set of ports in a 40X2 called A, B, C, D, E, F, G and H or (as I think you'd soon find that 8-bit ports are generally much more useful) a new set of 4-bit ports called: S, T, U, V, W, X, Y and Z ? And why 4-bits; an "octet" of 8 x 7-segment displays could be selected by 3 bits. IMHO it's not difficult to write, for example, w1 AND 15 (or AND $0F , or AND %1111, etc.) which can of course also work with 3 bits (w1 AND 7) , etc... Brackets would be nice, and they were "promised" a long time ago, but obviously proved to be more difficult to implement than expected.
.... .an "if then" statement like "if pinc.1=1 then W=15." Instead having to go to a subroutine or label to get a value changed.
You (almost) can do that already; the correct syntax is: IF pinc.1 =1 THEN : W1 = 15 : ENDIF but if you have an aversion to colons there are alternatives using "LET"s or "White Space". The ENDIF is essential because you might want to setup, for example, "THEN W1 = 15 and W2 = 25" , that would do something completely different in most computer languages. PICaxe Basic will also accept: IF pinc.1 = 1 AND pinc.2 = 0 THEN : W1 = 15 : ENDIF which is quite "unusual".

Cheers, Alan.
 

captnemo

New Member
Been doing yard work.
I stumbled across the fact that you can, IF pinc.1=1 then :W1=15.
I'm trying to use the Editor to monitor the values in a running 20M2 picaxe. I've done this before, but can't remember how I did it.
I got the stepper program running, I'm using the pot to set the number of steps, but don't know what the picaxe is reading, so I don't know how many steps the stepper is suppose to do.
Thanks.
 

WhiteSpace

Well-known member
@captnemo do you just mean the serial terminal?

Page 219 of Manual 2 https://picaxe.com/docs/picaxe_manual2.pdf gives the instructions. I rely on it heavily to see what is going on. I have used it in my various stepper programs to see how many steps the motor has done at a particular point etc.

The code is:

SerTXD ("The value that I want to check is :" #SomeByteOrOther, CR, LF)

If you post what you are trying to monitor, I'll see if I can help.
 

captnemo

New Member
I'm trying to read a 10k pot connected to +5v and common, with it's wiper going into C.7.
The program is as follows:

readadc C.7,W12
W6=W12*200
sertxd (#W6,CR,LF)

I entered this and monitored the "code explorer" W6 just registered zeroes. I tried with the "debug" selected and not selected.
Is there some sort of setup or enable I have to do on pin C.7?
 

AllyCat

Senior Member
Hi,

The Code Explorer window is for the Simulator (so you need to "set" its input appropriately), but aren't you using "real" hardware? The SERTXD should be displaying in the "Terminal Emulator" (window), which may be set up to open automatically (after a program is downloaded), or by pressing f8, or I usually put a #TERMINAL 4800 at the top of my programs (after a #PICAXE 20M2 to confirm what is being used). Note that the 4800 (baud rate) needs to be changed proportionally if you use a SETFREQ other than M4.

Alternatively you can put a DEBUG into the program, but beware that each time it reports (e.g. inside a loop) takes around 150 ms which may upset the running of a fast program (e.g. a stepper driver) considerably.

Cheers, Alan.
 

captnemo

New Member
I'm using real hardware.

The editor wasn't set up to open automatically and I couldn't find any reference about monitoring, on the Editor screen.
I put "#terminal 4800" in the main program, like you suggested, sure enough it came up.
I had to change the setting to ASCII and can now finally read the pot.

I think the last time I was able to monitor the values "real time," I was using the Edition 5 software, and that was several years ago and I don't recall any emulator popping up. It was more like a chart off to one side of the screen.

Thanks for the help again.
 

AllyCat

Senior Member
Hi,

Yes, to be honest, I still prefer PE5 for some applications; the Download process is clearer (and faster) and the Simulation and Terminal windows pop-up more reliably. In particular, the PE6 Terminal window seems to get "hidden" behind other panes and unlike PE5 it doesn't appear to have an Options > Editor > "Open after Download" facility (but then it doesn't need to be closed before a Download). However, the PE6 Terminal does have many more features, so I sometimes use the PE5 Editor/Download combined with the PE6 Terminal. :)

The PE5 Editor is still available for Download from the "Obsolete" section, and both both programs can be installed and even Run at the same time (with obviously some conflicts of the Com Ports). But it does have a few unfixed Bugs, so PE6 should also be tried before reporting a "problem". ;)

Cheers, Alan.
 

captnemo

New Member
I'm using a Windows XP laptop and had to get some files from Microsoft and download them to the laptop before I could install the Editor 6.
I had version 5 already on the laptop, but I think the new M2 models are not on that version, that's why I had to use 6.

I've got the all the stepper programs running and I'm going to place a PDF drawing for wiring a 21-02458-03 0611 stepper, controlled directly by an 08M and a 28YBJ-48 (geared steppe) controlled by a 08M via a ULN2003, and also two stepper motors controlled by a 20M2 via two ULN2003's.
It might save someone some time, looking up stepper connections. I'll also post the program with the schematic under the "finished projects"
 
Top