stepper motor unipolare in full step

Nandino

Active member
Salve a tutti, ecco il mio programmino con il 08m2 per far funzionare un stepper motor in configurazione full step

Code:
start0: basso 4
avanti0: se pin3 = 1 allora gosub indietro0
alto 0
pausa 1
basso 0
pausa 1
basso 0
pausa 1
alto 0
pausa 1
goto avanti0

indietro0: basso 0
dietro0: se pin3 = 0 allora gosub start0
alto 4
pausa 1
basso 4
pausa 1
basso 4
pausa 1
alto 4
pausa 1
goto dietro0


start1: basso 2
avanti1: se pin3 = 1 allora gosub indietro1
alto 1
pausa 1
alto 1
pausa 1
basso 1
pausa 1
basso 1
pausa 1
goto avanti1

indietro1: basso 1
dietro1: se pin3 = 0 allora gosub start1
alto 2
pausa 1
alto 2
pausa 1
basso 2
pausa 1
basso 2
pausa 1
goto dietro1





start2: basso 1
avanti2: se pin3 = 1 allora gosub indietro2
basso 2
pausa 1
alto 2
pausa 1
alto 2
pausa 1
basso 2
pausa 1
goto avanti2

indietro2: basso 2
dietro2: se pin3 = 0 allora gosub start2
basso 1
pausa 1
alto 1
pausa 1
alto 1
pausa 1
basso 1
pausa 1
goto dietro2



start3: basso 0
avanti3: se pin3 = 1 allora gosub indietro3
basso 4
pausa 1
basso 4
pausa 1
alto 4
pausa 1
alto 4
pausa 1
goto avanti3

indietro3: basso 4
dietro3: se pin3 = 0 allora gosub start3
basso 0
pausa 1
basso 0
pausa 1
alto 0
pausa 1
alto 0
pausa 1
goto dietro3
programma lunghissimo che per funzionare funziona ma volevo sapere se c'è qualche altra alternativa meno macchinosa,
perche penso che anche se non si vede nel funzionamento del motore forse con il multitasking il silicio provoca dei ritardi .....
grazie per la cortesia un saluto a tutto siete fantastici
 

inglewoodpete

Senior Member
To assist forum members who do not understand Italian, I have translated your post into English, which may bring you more help.
Per assistere i membri del forum che non capiscono l'italiano, ho tradotto il tuo post in inglese, il che potrebbe darti ulteriore aiuto.

I see that you are using the gosub command but the (sub)routines that you call do not end with a return statement. This will cause problems for your PICAXE.
Vedo che stai usando il comando gosub ma le (sotto) routine che chiami non terminano con un'istruzione return. Ciò causerà problemi al tuo PICAXE.



Hello everyone, here is my little program with 08m2 to operate a stepper motor in full step configuration

Rich (BB code):
start0: Low 4
Forward0: If pin3 = 1 Then gosub Back0
High 0
Pause 1
Low 0
Pause 1
Low 0
Pause 1
High 0
Pause 1
goto Forward0

Back0: Low 0
Reverse0: If pin3 = 0 Then gosub start0
High 4
Pause 1
Low 4
Pause 1
Low 4
Pause 1
High 4
Pause 1
goto Reverse0

start1: Low 2
Forward1: If pin3 = 1 Then gosub Back1
High 1
Pause 1
High 1
Pause 1
Low 1
Pause 1
Low 1
Pause 1
goto Forward1

Back1: Low 1
Reverse1: If pin3 = 0 Then gosub start1
High 2
Pause 1
High 2
Pause 1
Low 2
Pause 1
Low 2
Pause 1
goto Reverse1

start2: Low 1
Forward2: If pin3 = 1 Then gosub Back2
Low 2
Pause 1
High 2
Pause 1
High 2
Pause 1
Low 2
Pause 1
goto Forward2

Back2: Low 2
Reverse2: If pin3 = 0 Then gosub start2
Low 1
Pause 1
High 1
Pause 1
High 1
Pause 1
Low 1
Pause 1
goto Reverse2

start3: Low 0
Forward3: If pin3 = 1 Then gosub Back3
Low 4
Pause 1
Low 4
Pause 1
High 4
Pause 1
High 4
Pause 1
goto Forward3

Back3: Low 4
Reverse3: If pin3 = 0 Then gosub start3
Low 0
Pause 1
Low 0
Pause 1
High 0
Pause 1
High 0
Pause 1
goto Reverse3
very long program that works to work but I wanted to know if there is any other less cumbersome alternative,
because I think that even if you can't see it in the functioning of the engine, perhaps with multitasking the silicon causes delays .....
thanks for the kindness a greeting to all you are fantastic
 

Nandino

Active member
Code:
start0: Low 4
Forward0: If pin3 = 1 Then gosub Back0
High 0
Pause 1
Low 0
Pause 1
Low 0
Pause 1
High 0
Pause 1
Return

Back0: Low 0
Reverse0: If pin3 = 0 Then gosub start0
High 4
Pause 1
Low 4
Pause 1
Low 4
Pause 1
High 4
Pause 1
Return
Ecc......
What careless, this ok? thanks for the fix, so this is the only way to run the motor in full stepper? Isn't there a combination using the "toggle" or something?
Thanks for your kindness
 

Eng460

Well-known member
Hi Nandino, section 3 of the manuals interfacing, example 6 is a unipolar stepper motor, and uses a program similar to yours but using the “toggle“ command. That might help, especially if you have a copy of the manual in your language.

Also worth looking at the “toggle” command in section 2.

What project will you use the stepper motor for?

Eng460
 

Nandino

Active member
The toggle command is not good for the unipolar command in full step mode, because it has a single sequence to power a single motor winding, in full step two opposite windings must be powered at the same time, all to have more torque!
I have no projects in progress but it could help me in the future
 

Eng460

Well-known member
Hi Nandino, I believe that is covered in the example by the circuit shown which uses a ULN2003 Darlington driver chip to provide the necessary two complimentary outputs. The code provided just provides single steps spaced by delays, but I assume by shortening the delay the behaviour could be tuned to your requirements.

Extra components I know. I wonder if as an alternative, the “let pinsA=... “ Which allows changing all pins in a port with one instruction could be used to avoid the Darlington driver providing you have enough available outputs on your Picaxe to do the job directly.

I have not tried it, just thinking....

Eng460
 

AllyCat

Senior Member
Hi,

Why make it so complex with multitasking (many Start:s) and/or Subroutines (slow). Also, the pulses will not be spaced uniformly because of the extra delay in the IF...GOSUB construction. Adapted from my suggestions in #3 of a recent thread , for example :
Code:
#picaxe 08m2
symbol A1 = c.0     ; Select as required
symbol A2 = c.1
symbol cB1 = c.2
symbol cB2 = c.4
symbol direction = pinc.3
symbol gapwid = 8          ; Adjust for speed
symbol gapwid1 = gapwid - 1
setfreq  m16                    ; Or as required
forwards:
  pause gapwid1  :  High A1 : Low A2     ; Enable coil A
  pause gapwid  :  High cB1 : Low cB2     ; Enable coil B
  pause gapwid  :  Low A1 : High A2     ; Reverse coil A
  pause gapwid  :  Low cB1 : High cB2     ; Reverse coil B
  if direction = 0 then forwards             ; Or fall into backwards
backwards:
  pause gapwid1  :  High A1 : Low A2     ; Enable coil A
  pause gapwid  :  Low cB1 : High cB2     ; Reverse coil B
  pause gapwid  :  Low A1 : High A2     ; Reverse coil A
  pause gapwid  :  High cB1 : Low cB2     ; Enable coil B
  if direction = 1 then backwards
  goto forwards
Or more compact versions are possible by using Variables (e.g. b0 - b3) to define the pins and/or TOGGLE commands and/or OUTPINS and XOR commands, etc. :

Cheers, Alan.
 

Nandino

Active member
ciao allycat, ho provato a simulare il tuo programma ma le sequenze di accensioni non sono complementari, anzi se hai tempo prova a simulare il mio primo programma e così vedi anche tu cosa intendo, scusa se ti rompo con questa richiesta



ciao eng460: il circuito dell'esempio 6 ha un difetto che sono le resistenze di ritorno, quelle da 1k ... bruciano !!!!! anche se devo dire che il motore gira a pieno regime e sarebbe fantastico, il mio primo programma fa girare il motore a pieno regime ed è ok, ma come dice allycat è troppo complesso!
 

AllyCat

Senior Member
Hi,

I presume your program is written for an Italian version of the Program Editor, but it is too complex for me to bother to translate it. However, I now see that you require code for a UNIPOLAR not BIPOLAR stepper. You don't appear to have identified the "A" and "B" coil connections, so I have changed the Symbols and if the drive outputs are "Active High" then I believe the equivalent version would be:
Code:
#picaxe 08m2
symbol A1 = c.0     ; Select as required
symbol A2 = c.2     ; *swapped
symbol cB1 = c.1   ; *swapped
symbol cB2 = c.4
symbol direction = pinc.3
symbol gapwid = 8          ; Adjust for speed
symbol gapwid1 = gapwid - 1
setfreq  m16                    ; Or as required
forwards:
  pause gapwid1  :  Low A2 : High A1      ; Enable coil A+
  pause gapwid  :   Low cB2 : High cB1     ; Enable coil B+
  pause gapwid  :  Low A1 : High A2     ; Enable coil A-
  pause gapwid  :  Low cB1 : High cB2     ; Enable coil B-
  if direction = 0 then forwards             ; Or fall into backwards
backwards:
  pause gapwid1 :  Low A2 : High A1     ; Enable coil A+
  pause gapwid   :  Low cB1 : High cB2     ; Enable coil B-
  pause gapwid  :  Low A1 : High A2     ; Enable coil A-
  pause gapwid   :   Low cB2 : High cB1     ; Enable coil B+
  if direction = 1 then backwards
  goto forwards
Or you can reduce the power consumption by introducing another "Pause" between each pair of "Low" and "High" commands and reducing the first Pause correspondingly.

Cheers, Alan.
 

Nandino

Active member
hello eng460: I apologize if I have not always translated my words now I will rewrite you translated, the circuit of example 6 has a defect which are the return resistors, the 1k ones ... they burn !!!!! although i have to say the engine runs at full throttle and that would be great, my first program runs the engine at full throttle and it's ok but as allycat says it's too complex!
 

Eng460

Well-known member
Hi Nandino, thank you for translating. Google translate on an iPad is beyond my computing skills. No need for apologies. It is my loss that I only have one language. It adds to the richness of the forum to have people participating from all around the world with a common interest.

Interesting that those return resistors are burning, or even warm. There is obviously something about the circuit that I don’t understand as I thought they should be at signal level. Interesting!

I wonder if others can give more explanation.

Eng460
 

AllyCat

Senior Member
Hi,

No, the 1k resistors should not get hot or "burn". With 5 volts the power is v2 / R = 25 / 1000 = 25 mW. Even quite small resistors are rated at 250 mW so should not get noticibly warm. However, a problem with the hardware (inverter) method (in example 6) is that always one "A" coil and one "B" coil must be active; the motor can NOT be switched OFF, so it might get quite (or very) hot. In fact, due to the inductance of the coils, the power can be higher when the stepper is NOT moving than when it rotates !

Thus it is better to have one output pin for each coil (so that all the coils can be switched OFF) but there is also a potential problem with the TOGGLE command: To switch the coils needs for example TOGGLE A1 : TOGGLE A2 , which would be equivalent to alternatively HIGH A1 : LOW A2 and then LOW A1 : HIGH A2 . Even using PICaxe's Multi-Tasking (many Starts) there is a time delay at each separate instruction, so there must be a time when BOTH A coils are active at the same time (which will use double the current, but the magnetic fields cancel to zero). This is not a problem with direct HIGH and LOW commands (because we can always arrange to switch OFF one coil before switching the other ON), and with a BiPolar stepper, switching both ends of the coil to the same voltage level switches it OFF.

All these problems can be solved by using the PINS command, but everything needs to be configured correctly. The basic core of the program could be (untested), but the code in post #11 should be easier to understand and work correctly:
Code:
DIRS = %10111   ; Coil pins = B2 , 0 , A2 , B1 , A1
PINS = %00011   ; Start Forwards  .. or :
;  PINS = %00110   ; Start Backwards
FOR b0 = 0 TO 9
  PAUSE 7
  OUTPINS = OUTPINS XOR %00101
  PAUSE 8
  OUTPINS = OUTPINS XOR %10010
NEXT
OUTPINS = 0     ; Stop
Cheers, Alan.
 

Nandino

Active member
You are very kind to say the least I hope to be able to try all your advice one of these evenings, especially the latest example of Alan and in any case thanks for the support, see you soon Luca
 

Nandino

Active member
Alan .... Fantastic, I tried to simulate your two programs .... perfect, but now I have to put them on the picaxe and let's see the engine how it behaves and how much it warms up, during the week I try and let you know .... Thanks thank you thank you
 

Nandino

Active member
Code:
#picaxe 08m2
DIRS = %10111                                          ; Coil pins = B2 , 0 , A2 , B1 , A1
symbol direction = pinc.3
PINS = %00011                                          ; Start Forwards
                 
forwards:
  PAUSE 7
  OUTPINS = OUTPINS XOR %00101
  PAUSE 8
  OUTPINS = OUTPINS XOR %10010
  if direction = 0 then forwards
  PINS = %00110                                        ; Start Backwards         
backwards:
  PAUSE 7
  OUTPINS = OUTPINS XOR %00101
  PAUSE 8
  OUTPINS = OUTPINS XOR %10010
  if direction = 1 then backwards
  PINS = %00011                                       ; Start Forwards
  goto forwards
hi Alan here I am again, I made a mix of your two programs that you gave me, what do you say ... could there be some problem if I do this?. in simulation everything is ok, and then I wanted to ask you if you explain this to me ....
OUTPINS = OUTPINS XOR% 00101
what is XOR?
and because the first pause put 7 and the next one put 8
why not all two equal?
and if I wanted to put the engine at a standstill for 3 seconds between one change of direction and the other, what should I do?
thank you very much for your time that you dedicate to me thanks
Luca
 

premelec

Senior Member
Exclusive or XOR, is a logical operator which results true when either of the operands are true (one is true and the other one is false) but both are not true and both are not false.
 

AllyCat

Senior Member
Hi,

The XOR effectively TOGGLES all bits in the first variable which are set in the second. So var XOR %00101 toggles bits 0 and 2 (A1 and A2), reversing the current. Note that {OUT}PINS is a short-cut, you might normally write b0 = b0 XOR %00101 : PINSC = b0 .

The Test and Jump (IF .. THEN GOTO) itself takes some time, approximately 1.2 ms (@ 4 MHz), so I subtracted 1 ms from the normal delay. I also showed a standstill (Stop) in my code (OUTPINS = 0) , just follow that with a PAUSE 3000 before setting the new direction.

Cheers, Alan.

ADDED: Yes, you can "mix" the instructions in the program in many ways, but personally I refer the program in #11 because it has a better structure. Also, you can then add delays to turn one of the coils (at a time) OFF, and I am considering more complex arrangements where one might use TRI-STATE, DAC or PWM outputs to save some pins and/or power and to "hold" a position, or perhaps "microstep", etc..
 
Last edited:

Eng460

Well-known member
Hi Premelec, that is the definition that I learned so many years ago, but that seems only to yield a simple true/false or 1/0 answer. But there must be more to it. In section 2 on variable mathematics, the operation is described as a “bit wise XOR”. I have to guess that means when performed on two binary numbers, the operation requires performing the XOR on the all the corresponding bits of the two numbers and so results in a new binary number, not a simple true (1) or false (0) outcome. Is that correct? I have always wondered if that was the meaning, but had no idea what it would be used for, so this is indeed a very interesting thread.

So the next question becomes where did that mystery number Alan used (with the original pins to get the required result) come from? We actually know the initial output number and the final number. Can we use these to find the mystery number?

I thought nothing ventured, nothing gained and took a wild guess. I wrote down the first and final numbers and performed the bitwise XOR on them and like magic, the mystery number appears.

So my question changes again! What is the logic behind choosing XOR? Why not one of the seven other logical operations listed in section 2 under the title of variable mathematics? And the obviously what would the others be used for?

It’s a bit obtuse when written out with words, so here is the first program step

%00011 ;pins
%00101 ;mystery number
————-
%00110, the result of bitwise XOR

Now the reverse -
%00011 ;pins
%00110 ;required result
————-
%00101, the result of bitwise XOR, the mystery number.

So I feel I have learned something. Just puzzling over when those other bitwise logical operations might come in handy.

I see Alan has replied while I have been doing all that and answered some of my questions by explaining the timing of the pauses and detailing the shortcut. That is very helpful, thank you. So now only my question about why XOR was appropriate in this case and when would the other bitwise logical operations be used still applies.


Eng460
 

premelec

Senior Member
Thanks for bringing that up.... bitwise it is... which is clearer when writ in binary rather than hex or decimal... as to all those other clever section 2 functions hippy and Alan have a mastery and understanding I never will though I occasionally use one or two. I guess it is just a lot of practice... you are on the right track there!
 

AllyCat

Senior Member
Hi,

Yes "bitwise" means working in parallel on all the bits in the byte at the same time, or actually you can do all 16 bits in a Word. You can (also) change each bit in the byte using the bitx variables in bytes b0 - b3, or work with the "weight" of the bit(s) in any byte or word. For example: %01000000 OR 17 is the same as %01000000 OR %00010001 and becomes %01010001 .

The main reason for using XOR is "because it works". Most of the logical operators work with two binary values so there are 4 possibilities (i.e. 00 , 01 , 10 . 11) and 4 possible "outcomes" (i.e. 0 or 1). Here, we want a selective TOGGLE, i.e. to INVERT (only) the bits in the first word that are selected by "1" bits in the second. Note actually the first and second bytes can be swapped and still produce the same result. For inversion, of the 4 possible input combinations, two of the outcomes should be "0" and two should be "1", but the majority of Logic operations produce a "1" (or a "0") for 1 or 3 of the combinations.

Most of this is described in Manual 2, "Mathematics - Variables", but there are actually more than 7 Logical operators; I think PICaxe supports: AND , NAND , ANDNOT (which is not the same), OR , NOR , ORNOT , XOR , XNOR and XORNOT , and NOT with a single variable. You could make a full "Truth Table" but I'll just start you off:
Code:
A   B     AND  NAND  ANDNOT  XOR
0   0      0    1      0      0
0   1      0    1      1      1
1   0      0    1      0      1
1   1      1    0      0      0
          ---  ---    ---    ---
Total  =   1    3      1      2    bits set
Interestingly, NAND and similar use more program bytes than ANDNOT, etc. There are also the dedicated characters for many of those (e.g. & , | , ^ , / and &/ etc.) but personally I prefer the "plain text" version to hieroglyphics. ;)

EDIT: I didn't fully read Eng460's questions before this post, so to add a little more detail: The bitwise operations are particularly useful for "masking" operations, for example testing for a condition on one or a group of bits within a byte or port. For example you can force any byte (not just the bit-addressable b0 - b3) ODD by using var = var OR %00000001 or EVEN with var = var AND %11111110 . The XOR is particularly useful for testing or creating a change in a group of bits, for example to swap an ASCII character between Upper Case (Capitals) and Lower Case you can use char = char XOR %00100000 (noting the weight of that "1" is 32 and "a" - "A" = 97 - 65 = 32).

Finally, it's interesting that any ("combinatorial") logic function can be created from only NAND gates (Latches may be more complex). A NOT is created just by linking the two (or all) inputs, and two (or more) NANDs feeding into the inputs of another NAND give an AND - OR function (e.g. inputs (A AND B) OR (C AND D) ). Thus an EXCLUSIVE - OR can be created from 5 x NAND gates, for example (A AND (NOT B) ) OR (B AND (NOT A) ) . But of course brackets are not available in PICaxe Basic !


Note that I have also added a paragraph to my post #19, but now perhaps we should give Nandino his thread back. :)

Cheers, Alan.
 
Last edited:

Nandino

Active member
it was a fantastic lesson to say the least, to tell the truth I miss the steps, the example programs to understand the functions and nand etc .... but in my case the XOR came right to my brain .....
now I put this threed in suspension for a few days because I have to physically put everything into practice and then we will hear from you and I will post my progress,
I greet you all and thank you all for your help
Luca
 

Eng460

Well-known member
Thanks so much Alan, you have gone a long way to filling in the vast gaps in my understanding of how those logic functions can be used. I am sure that I am not the only one who will be reading your explanation many times before I feel I really have it, but I can now see the possibilities of those function.

Instead of just a few lines of code that solve the specific problem, you have explained how they work, so the knowledge is so much more useful. (And I suggest right on topic.)

I found the seven plus XOR operations in section 2, but NOT is only described on the pages for X1 and X2 parts. Does it apply on the M2 parts as well? And I where would we find the XORNOT description?

Thanks Premelec, you can see why I needed a little more than the definition. But so many doors now open.

Now back to Nandino. Though I must keep an eye out for one of those stepper motors in my box of salvaged parts.

Eng460
 

Nandino

Active member
good evening friends masters, I tried to develop your teachings for pure study, so using the 08m2
the intent should be clear, that is, to give back and forth and stop using only pin 3
do you think I have complicated my life?
I don't know how else to do .... if you have suggestions, other ways .... thank you very much

Code:
sect:
dirs =% 10111                                                          ; Coil pins = B2, 0, A2, B1, A1
main:
count 3, 5000, b0                                                     ; count pulses in 5secs (at 4MHz)
debug                                                                      ; display value
   
if b0 = 2 then gosub forwards0                              ; if you feel 2 pulses in 5 sec go to forwards0
if b0 = 4 then gosub backwards0                           ; if you feel 4 pulses in 5 sec go to backwards0
if b0 = 6 then gosub stop                                       ; if you feel 6 pulses in 5 sec go to stop
goto main                                                                ;  back to main

forwards0:
PINS =% 00011                                                        ; setting for Start Forwards
forwards:
  PAUSE 1
  OUTPINS = OUTPINS XOR% 00101                       ; change the output comparing it with the previous one
  PAUSE 2
  OUTPINS = OUTPINS XOR% 10010                       ; change the output comparing it with the previous one
  if pin3 = 0 then forwards                                       ; continue the loop until pin3 goes to 1
  outpins = 0                                                            ; set all outs to 0 so everything stops
  let b0 = 0                                                               ; resets b0
goto main                                                                ; returns
 
backwards0:
  PINS =% 00110                                                      ; setting for Start Backwards
backwards:
  PAUSE 1
  OUTPINS = OUTPINS XOR% 00101                       ; change the output comparing it with the previous one
  PAUSE 2
  OUTPINS = OUTPINS XOR% 10010                       ; change the output comparing it with the previous one
  if pin3 = 0 then backwards                                    ; continue the loop until pin3 goes to 1
  outpins = 0                                                            ; set all outs to 0 so everything stops
  let b0 = 0                                                               ; resets b0
goto main                                                                ; returns

stop:                                                                        ; stop everything
  outpins = 0                                                           ; set all outs to 0 so everything stops
  if pin3 = 0 then stop                                             ; continue the loop until pin3 goes to 1
  let b0 = 0                                                              ; resets b0
goto main
 
Last edited by a moderator:

AllyCat

Senior Member
Hi,

Yes, there are better ways, particularly as COUNT is a "blocking" command which stops the PICaxe doing anything else for the 5 seconds.

Firstly, there are 2 "free" digital inputs, c.3 and c.5 (Legs 4 and 2) which gives 4 possible states, e.g. OFF , FORWARDS , BACKWARDS and "something else". To use c.5 (the Programming input) you can use the DISCONNECT command, but the pin must still be held Low when the battery is first connected to the PICaxe (i.e. at "bootup"). Also, make sure that you understand the "Hard Reset" Procedure which you must use to re-program the PICaxe. Or better, use a RECONNECT command after you have read the input pin and found it Low, and/or can allow the PICaxe to Reset/Reboot.

Therefore, a better solution may be to use the PULLUP %1000 command which connects an internal resistor of about 30k between the pin and the supply rail. Now, you can connect the pin via a low resistance (e.g. 1k) to either the supply rail (Vdd), the Earth (Vss) or do not connect it (e.g. use a "Centre Off" toggle switch). Also connect a resistor of => 47k, permanently between the c.3 pin and Earth. After a PULLUP OFF, read the input pin. If it is "1" then you know that the 1k is connected to the supply rail. If the pin is "0" then use the PULLUP %1000 command and read the pin again. If the input is still "0" then you know the 1k is connected to Earth, but if the input has changed to "1" then you know that only the 47k pulldown resistor is there (and the internal 30k resistor is "stronger").

It is also possible to do the same on c.5 to give up to 3 x 3 = 9 input possibilities, but the Programming method is more complex and you must use different commands. Alternatively, you could put a high value variable resistance (minimum > 47k) and a capacitor (to Earth) on the pin and make a simple ADC by using PULLUP %1000 : PAUSE 1000 : PULLUP OFF and measure the time (using a simple "counting" program loop) for the input to fall from "1" back to "0".

Cheers, Alan.

@Eng460: Apologies, I didn't answer your questions. Most of the Logic operators are described in the "Variables - Mathematics" section of Manual 2, but a few are missing (and NOT appears to be described in the wrong section). For situations like this, the best "Reference" is the Program Editor itself, and perhaps the Simulator (or in the last resort, a real PICaxe chip). Usually, the PE Syntax Check will tell you what you can (or can't) use (i.e. what the Editor "understands") for the particular chip that you have selected.
 

AllyCat

Senior Member
Hi,

Of course if you want to use a single push-button on c.3 (or even on c.5) then the simple solution is the "Short-Push / Long Push" method. Use an "Active Low" input (connect the switch across the input pin down to Earth) and you can use the PULLUP resistor command as described above to keep the pin normally High ("1").

In principle you might just use PULSIN c.3 , 0, w1 and its "Timeout" facility with: IF w0 = 0 THEN longpulse : GOTO shortpulse ; < 655 ms @ 4 MHz. Then Shortpulse: runs the motor Forwards for (say) 10 seconds and Longpulse: Backwards for 10 seconds (or whatever delay before you planned to read the COUNT again).

But there is also the BUTTON command which will "Debounce" the input and should do all you need, and probably more using the "Autorepeat" facility.

Cheers, Alan
 

Eng460

Well-known member
Hi Alan, thanks for the answer on those mathematical operators.

It seems that at the end of the day, if you want to use an operator of the same type as those described in section 2, then try using it, even if it is not documented, and see how in goes in PE and the simulator.

Must be very confusing for the students who I understand are the primary target audience for Picaxe.

Eng460
 

Wrigley

Active member
Hi Nandino
I'm a bit late for this thread but thought I'd add this anyway.
I have a 28BYJ-48 uni-polar stepper to rotate my model crane project. I've put my crane post in the Robotics section, and attached my program file here also.
I had delays so I added the suspend and resume commands so that when I move the joystick on the r.c. transmitter to rotate the crane it stops the arm of the crane extending/retracting.
I'm driving it with 7 volts via a ULM2003.

My picaxe is an 18M2 so I have this command first - let dirsb = %11111111 otherwise the outputs don't work.
You may need to also add let dir = %xxxxx at the start of your program for your 08M chip. 1 is output pin and 0 is input pin, not sure please check.

I used pause 10 to give me a slow and steady speed. The command let outpinsb = %00000000 turns off the ULN2003 so that the stepper isn't drawing current when the crane is not rotating. This can be quite high over 400mA.
Hope all this makes sense.
Regards Wrigley
 

Attachments

Nandino

Active member
You were really very kind all of you, now I'm trying with the count command but I will also try the recommended ones, tests, tests and tests .... 😜
 

Wrigley

Active member
Also Nandino watch out faulty steppers. I recently bought ten micro steppers and five of them had no wire on one coil and some had coil resistance of 40 ohm (40R) not 20R, so I may have to increase the uln2003 driver voltage.
 

Nandino

Active member
hello everyone, I'm back with the news .... starting from the assumption that curiosity and desire to learn push me, I successfully abandon the unipolar stepper because with your advice I have seen that everything works
now I would like to try bipolar,
I bought a pg16l0064 and then L293d, I followed the manual, section 3 page 18 and I would have bet nothing works.
i.e the stepper makes ticks ticks but does not turn, I rotated the pins between pic and l293, I rotated the motor pins, but nothing,
coils a and b are about 30ohm the same, I first tried out1 out 2 for A then for B and vice versa
help, any other tests I can do?
 

AllyCat

Senior Member
Hi,

You don't have to open another thread, but Bi-Polar motors are quite different to Uni-Polar. I've never used a L293 so I can't help much ; It appears that your motor needs about 12 volts and almost 1 Amp per coil from the power supply.

There are plenty of H-bridge output driver ICs available, but probably it would be better to get a dedicated Stepper Driver IC, which should give lots of "extra" facilities automatically. I've never used one but I had the DRV8825 recommended to me in Post #2 of this thread. There are a few other references on this forum, but they are quite old and most of the (ebay) links are dead. Maybe the topic for the new thread? ;)

Cheers, Alan
 
Last edited:

Nandino

Active member
Thanks for your speed, yet, the manual and like so many other circuits use the l293d precisely because it has two h bridges! But perhaps as you say the engine has too much absorption and maybe the advancement stops ....
 

Wrigley

Active member
[QUOTE = "Nandino, post: 335461, member: 74058"]
hello everyone, I'm back with the news .... starting from the assumption that curiosity and desire to learn push me, I successfully abandon the unipolar stepper because with your advice I have seen that everything works
now I would like to try bipolar,
I bought a pg16l0064 and then L293d, I followed the manual, section 3 page 18 and I would have bet nothing works.
ie the stepper makes ticks ticks but does not turn, I rotated the pins between pic and l293, I rotated the motor pins, but nothing,
coils a and b are about 30ohm the same, I first tried out1 out 2 for A then for B and vice versa
help, any other tests I can do?
[/ QUOTE]
Hi Nandino. I'll get back to you with info later.
 

AllyCat

Senior Member
Hi,

Sorry, I didn't look in detail at Manual 3 (or the L293 data) and made a "mistake" in my initial reply, which I quickly "edited" before going to bed. ;) In principle it shouldn't matter if either (or both) of the coils is connected "backwards".

However, IMHO the code on page 18 of Manual 3 is rather "incomplete"; it doesn't say which PICaxe is being used, or why the "Pins" (or is it Legs? ) are numbered 4 , 5 , 6 and 7 (it's probably for Port B on an 18-pin PICaxe, Legs 6 - 9). It won't work with an 08{M2}, because Leg 4 (pin 3) is an "input only"; It might work with (08M2) Legs 3 , 5 , 6 and 7 and the lookup changed to lookup b1,(%1x010,%1x001,%01x01,%0x110),b2 where the x represents either a 0 or a 1 ("don't care").

For other PICaxes, I would wire the coils to port B , across pins 0 - 1 and 2 - 3 and first try a lookup of: lookup b1,(%1000,%1101,%0111,%0010),b2 which should use lower power (and put less load on the power supply). But the code in Manual 3 should work if the pin connections (and power supply) are correct.

Cheers, Alan.
 

Wrigley

Active member
Hi Nandino
Your questions help me to learn as well.
Legs means the actual physical metal leg and pins refer to the what it does like serial in, readadc etc. But on threads written by beginners they may write the wrong thing so we have to be careful.

STEPPER
I looked on google for your stepper PG16L0064 and saw Moons' data PM-EN-2019.pdf. This shows 9volts dc and 7.6 ohms +/-10%. so if we take one lowest coil resistance we get 9/6.84 = 1.32amps (1320mA) this is over twice as big as the L263D output current. But you measure 30R which is 300mA well within the L293D.

TEST
Maybe you could connect a DMM set to current and connect this in series with a 9V supply and one coil for a short time and measure the current. Then divide 9 by this current.
If you are using a weakish pp3 9 volt battery maybe the stepper goes tick tick. If you have a bench power supply then this is not the problem.

L239
The ST L293 pdf shows that we have to connect a voltage to the ENABLE legs 1 & 9 (max 7v, 5v is good enough). Similarly a voltage to Vss leg 16.
If your stepper is 9 volts then connect 9v to leg 8 Vs.
I downloaded the TEXAS and ST datasheets so I could understand the 293 better.
If you look at one of the L293 chips (bottom right maybe) on my atlas crane cct you can follow the legs on each corner as to where the voltage comes from.

Wobbly or stepper going tick tick
I've attached a file that makes a bipolar stepper rotate anti-clock then clock wise at switch on. Let's call the coils a. and b.
I swapped coil a. wires round and it rotated first clockwise. Then coil b. swapped and it rotated anticlockwise first.. and so on.
Next I connected coil a. into b. outputs and coil b. into coil a. outputs and it worked as above.

Next I swapped one wire from a. with one wire from b. and the shaft just wobbled.
At 5 volts I can stop the shaft easy with finger but not so much at 8 volts.
Please check your set up with nothing connected to the shaft because too much physical load may make it just tick.
Would be good to know how you get on.
 

Attachments

PieM

Senior Member
Sorry but in french: 18M2 and LD293

Rich (BB code):
'===================================================
'Commande moteur PAP bipolaire 
'18M2 sur CHI035 Driver L293D
' connections moteur : sur A et B du L293D 
'===================================================
#picaxe 18M2
setfreq M32
'===================================================

symbol MOT = outpinsB   'MOT correspond au portB du 18M2
symbol period = W1      'temps entre pas en 1/100 de ms
symbol nbpas = W2       'Nombre de pas    
dirsB= %11110000        'affectation B.4 à B.7 en sortie vers le L293

'mémorisation de la sequence de commande pour le moteur en demi pas
eeprom 0,(%1010,%1000,%1001, %0001,%0101,%0100,%0110,%0010)

'prg principal ==============================
princ: 

do
      'mise hors tension du moteur pendant 3 sec.
      Mot = Mot & $0f | %00000000 
      pause 3000
      
      'actionne x demi-pas dans un sens avec une vitesse donnée
      period = 50 : nbpas = 200
      for w10 = 1 to nbpas
      inc b0
      gosub PAS
      next
      
      'actionne x demi-pas dans l'autre sens avec une autre vitesse
      period = 20 : nbpas = 200
      for w10 = 1 to nbpas 
      dec b0
      gosub PAS
      next
      
      pause 500
      
      'actionne x pas dans un sens avec une vitesse donnée
      period = 50  :nbpas = 200: b0 = 0 'va lire une séquence (paire) sur deux (mode 2 enroulements alimentés)
      for w10 = 1 to nbpas  
      b0 = b0+2
      gosub PAS
      next
      
      'actionne x pas dans l'autre sens avec une autre vitesse
      period = 28 :nbpas = 200: b0 = 1'va lire une séquence (impaire) sur deux (mode 1 enroulement alimenté)
      for w10 = 1 to nbpas  
      b0 = b0-2
      gosub PAS
      next
      
loop


PAS: ' Commande en demi pas ******************

      b0 = b0 & %00000111 'la valeur de b0 est limitée à 3 bits, soit 0 à 7 
      read b0, b1       ' va lire la séquence 0 à 7 dans l'eeprom.
      b1 = b1*16        'decale de de 4 bit pour être au niveau de b.4 à b.7
      Mot = Mot & $0f | b1    'envoi de cette séquence au moteur en masquant  les b.0 à b.3 
      pause period            'pause en ms
return
 
Top