Help with project

techElder

Well-known member
confused with 12v going in 2 directions.
You need a better basic understanding of electricity. Voltage doesn’t “go” anywhere; current “goes”. Current will flow from the lower voltage (GND) to the higher voltage (12V) through the switch (ULN2803.)
 

hippy

Technical Support
Staff member
9 for inputs
13 for outputs

so i might have to use the 40x2
Depending on what your switches actually do you may be able to minimise the number of input signals, read multiple switches on a single ADC line.

For example you won't want, and possible wouldn't ever get, a 'go left' at the same time as 'go right' so both can be used on the same signal.

If it's joystick controlled you could use analogue joysticks which need just two analogue signals rather than four switch lines.

An alternative is to use another PICAXE to read the switches and buttons and pass them to the motor controlling PICAXE. That could even simplify the software design.

You could probably get by with two 20M2 chips.
 

depeet

New Member
Included, a possible architecture.
You better use a ULN2803 instead of ULN2804. The 03 is made for 5V input, the 04 is made for 6 to 15V. I had some trouble in an earlier project by using ULN2804. Switched to ULN2803 and everything worked fine
 

hippy

Technical Support
Staff member
Included, a possible architecture.
Your 61, 31 and 10 threw me at first until I twigged that was 6 ins, 3 ins, 1 out :)

I would do similar but, instead of multiple signals linking the two, I would carry the data across using a single line serial, HSerIn on the stepper driver PICAXE. I would connect the limit switches and electromagnet control to that. Opposite end limit switches can be paired-up to save on number of inputs.

That way one can check the button handler is working by viewing what is sent using the Terminal, and the motors can be tested the same way. When they both work separately, they should both work together.
 

techElder

Well-known member
In my industrial life "before", I always used/found "limit" switches on machinery. However, they weren't an obvious part of the programming of a machine. They were usually an emergency out-of-limits switch. Most of the time there was some sort of indicator of motion in the carriage/axle/spindle/current that let the software know proper movement was being made.

I guess its a matter of semantics, but perhaps the "limit" switches are really "position" switches? It matters because a "limit" switch would most likely just disable or cut the power to the motor/driver. No programming involved.
 

oracacle

Senior Member
Dedicated stepper controller chips & modules exist for a reason and are dirt cheap. For instance:

which are great for bipolar steppers and not so great for unipolar
 

hippy

Technical Support
Staff member
I guess its a matter of semantics, but perhaps the "limit" switches are really "position" switches? It matters because a "limit" switch would most likely just disable or cut the power to the motor/driver. No programming involved.
For industrial systems where there are limit switches they would normally be safety critical cut-offs; when activated they will bring the system to a fail-safe stop. One would normally then have separate home position detectors.

When something isn't safety critical they can be used to indicates that motors and the like should stop turning and can serve the dual use purpose of home indicators.

The challenge, as always, is in determining when a system is safety critical or not. Anything which fails with no damage done likely isn't, but anything which could stall, overheat, then catch fire, probably is, unless it was only ever operated in circumstances where that could never happen.
 

Technoman

Senior Member
@depeet :
The 03 is made for 5V input, the 04 is made for 6 to 15V.
Correct, although I have seen it given compatible with TTL (UTC manufacturer) and personally did not encounter any problem for 5V input. Thank you for the warning.

@hippy : sorry, I should have written 6 inputs, 1 output, ...

The use of 2 serial input latch drivers like UCN5841-5842 or MIC58P42 could take from 13 to 6 the pincount to drive the steppers and the electromagnet (CLK1/SIN1/Strobe1 - CLK2/SIN2/Strobe2). Only one 20M2 would be necessary, leaving 12 inputs available.
 

Hemi345

Senior Member
You could reduce the pin count by putting multiple buttons/switches on one PICAXE analog pin using a resistor ladder:

Then you'd just READADC that pin to determine which button was pressed.
 
Included, a possible architecture.
Sorry for the late comment to this been busy with other stuff,

all the motors have arrived now so I can start doing the CAD model

in regards to the architecture, I don't fully understand how you would program this as its not a strength of mine.
I understand the master control 20m2 as it will allow for control of the switches and magnet causing the magnet to activate on a timer after the claw as moved on the z by so much.

my confusion is on the DIR/STEP and stepper address. I don't fully get how you would be able to communicate with forms of motion.
I kinda get that the stepper address as it would work as a logic gate to understand what motor to move. but for the direction would that relate to the 2 pins.

so for forward in the x-direction, the DIR forward pin would be on and 01 would be on.
would this not cause the inability for diagonal movement and would need for a 3rd input for the stepper address to keep the z-axis separate.

out of curiosity, you included and the interface is this like an LCD screen or OLED screen sort of thing.

sorry if this comment comes across strange as I was more typing it out to understand my thinking of how to program the chips as it's going to have to be two sets of code and two programming ports. I think I get it but it's just how to do it now in the picaxe editor.
 
Last edited:
You could reduce the pin count
I found this joystick you can buy that I think works how you're describing. I did consider this approch however due to the accuracy that type creates it isnt nessay for the project and instead im going for more an arcade joystick design where it uses gates to control it.

this will require for maybe more inputs from the master to the control as it's going to require a more specialized set of inputs as id prefer to go for an 8 gate style (8 directions) over 4 to give a user more ability in the movement of the claw. for this ill most likely use 4 microswitches (same for the safety, home switches) to enable for the diganol directions to be hit


 
Last edited:

Technoman

Senior Member
This proposed architecture was aimed at driving unipolar steppers about the same way an A4988 or alike would drive a bipolar one.
  • Within a loop, the program (master) would read the buttons of the joystick and else, set stepper address and DIR then send pulses on STEP for each axis, etc.
  • The loop would take a short time. A pause is anyway necessary between each state change on the steppers windings. It's not a matter of speed.
  • The rate of the pulses could be variable : slow at the beginning then increase.
  • ... to have to be two sets of code and two programming ports.
    Yes. One is entirely dedicated to steppers. The program is polling the inputs then drive each stepper.
  • For the programming of the stepper driver, have a look at : https://phanderson.com/picaxe/step_1.html
  • There is no screen on the diagram.
I'll try to draw the architecture proposed by hippy in #46 where the microcontrollers are communicating on a single data line, using UART.
 
using UART
I don't fully know how this is supposed to work but time to learn :D

ive read this and it sorta does explain it

from what i can see its a way for the inputs of one chip to be read on the second.
if im wrong do correct me so if people use this to learn.



also I forgot the on-off switch making 10 inputs. 4 for joystick 3 for buttons 3 for end switches
 

hippy

Technical Support
Staff member
from what i can see its a way for the inputs of one chip to be read on the second.
Yes; it's as simple as that. One PICAXE or thing can read its inputs and send out an 8-bit byte ( or multiple bytes ) to tell something else what to do. The second PICAXE or thing receives those bytes, determines what they mean, and then does what is commanded of it.

"Serial", usually meaning UART/RS232 serial, is easiest to use because it only requires a single signal line plus 0V.

"SPI", is also a serial protocol but uses at least two signal lines, data and clock plus 0V, and may need more signal lines.

Single wire "serial" is a good choice for a PICAXE-to-PICAXE link because it's less wiring and the PICAXE has good support for that, notably SEROUT and SERIN commands, with receive timeouts and data packet qualifier support.

There is also a HSERIN variant, "Hardware serial" which allows data to be received even when a PICAXE is not explicitly waiting for data. The X2 chips are more capable than the M2 in that respect but both have HSERIN functionality.

So, during testing you could have a test program in your button handler which doesn't handle buttons but just tells a motor to go forward for one second, stop, go backwards, stop, and repeat that -
Code:
Do
  SerOut B.7, N2400, ("F") : Pause 1000 ; Forward for 1 second 
  SerOut B.7, N2400, ("S") : Pause 1000 ; Stop for 1 second 
  SerOut B.7, N2400, ("B") : Pause 1000 ; Backwards for 1 second 
  SerOut B.7, N2400, ("S") : Pause 1000 ; Stop for 1 second 
Loop                                    ; Repeat forever
In the receiver one simply has to grab those bytes sent, determine which they are and what to do -
Code:
Do
  SerIn C.0, N2400, b0
  Select Case b0
    Case "S" : Gosub StopMotors
    Case "F" : Gosub GoForward
    Case "B" : Gosub GoBackwards
  End Select
Loop
It's a bit more complicated than that for stepper motors because you need to keep stepping and moving while waiting for the next command to arrive but that's the gist of it.

A HSERIN version would be something like -
Code:
HSerSetup B2400_4, %000
Do
  b1 = 1
  HSerIn w0 ; b1:b0
  If b1 = 0 Then
    Select Case b0
      Case "S" : Gosub SetStop
      Case "F" : Gosub SetForward
      Case "B" : Gosub SetBackwards
    End Select
  End If
  Gosub KeepMovingMotor
Loop
 
@hippy thanks mate I'm not fully at the programming stage as I'm just ordering all the electronics now. ill post the circuit once I have it done to do a final check then move to the programming. but it really helps with my understanding as I'm going to have to document all this development in the coursework.
23167
23168
going off your comments ill most likely go for the 20x2 as @Technoman claims that 2 are enough for the system
 
Last edited:

hippy

Technical Support
Staff member
@hippy thanks mate I'm not fully at the programming stage as I'm just ordering all the electronics now. ill post the circuit once I have it done to do a final check then move to the programming.
What you will often find is that there is 'a synergy' between the hardware, circuit and program. That there's an optimal solution, which doesn't always come from designing the hardware or circuit without also thinking about the program, and vice-versa.

This can particularly bite when a program wants to use some hardware feature but that's precluded because its pin has been allocated for something else.

In this case, on the receiver, the motor and electromagnet driver; you need to avoid using the HSERIN pin other than for serial in.

One thing I would always recommend is not placing orders for PCB's if having any made until both circuit and program have been worked out because that can be expensively annoying if you have to rework the board because the software won't work otherwise.

Post your circuits or programs and people here will be delighted to give them the once-over to see if there may be any issues.

going off your comments ill most likely go for the 20x2 as @Technoman claims that 2 are enough for the system
Two M2's might be good enough for the job though it might depend on how quickly the motors have to be stepped. If you don't have any PICAXE chips to test with, two X2's will be the safest bet, especially 20X2 as they are the fastest PICAXE which has an internal oscillator.

If your budget stretches to it maybe consider buying 2 x 20X2 plus 1 x 20M2. You'll either have a spare M2 ready for your next project or a spare X2 if at least one can be swapped for the M2. I suspect at least the joystick handler could be a 20M2.
 

hippy

Technical Support
Staff member
I would probably wire the motor driver as below, which should work for either 20X2 or 20M2 -
Code:
             .--------_--------.
             | V+           0V |
             | SI           SO |
  Limit Z -->| C.7         B.0 |------------> Motor X A
  Limit Y -->| C.6 In      B.1 |------------> Motor X B
  Limit X -->| C.5         B.2 |------------> Motor X C
Motor Z D <--| C.4         B.3 |------------> Motor X D
Motor Z C <--| C.3         B.4 |---------.
Motor Z B <--| C.2         B.5 |------.  `--> Motor Y A
Motor Z A <--| C.1  HSERIN B.6 |<--.  `-----> Motor Y B
          .--| C.0         B.7 |---|--------> Motor Y C 
          |  `-----------------'   |  .-----> Motor Y D
          `------------------------|--'
                                   |
Serial In -------------------------'
The PICAXE can fairly easily sort out that the pins may not be logically or entirely sequentially ordered, in fact any pin can be used for pretty much anything; whatever makes it easiest to wire-up.

The only restriction is B.6 must be Serial In, and C.6 is input only so must be one of the Limit switches.

The limit switches don't need to go to the joystick and button PICAXE, can come here, and it's arguably better if they do.

The top/bottom, left/right, forward/backward limits can be paired because both limits can't be reached at the same time. So that's only three limits.

It doesn't matter if the punter keeps trying to push past the limits - let them - the joystick handler doesn't have to worry about that, the motor driving PICAXE simply won't allow that to happen.

Oops : Just realised I've forgotten the electromagnet output. C.5 or C.7 can be used for that, with two of the limit switches being wired as an ADC input as Hemi345 suggested earlier.
 
Last edited:
placing orders for PCB's
The college im at has the ability to create its own PCBs so it makes that risk null and void as any mistake is just lost baseboard.
but you are correct as you don't want to have mistakes as in the past on projects I used a software called circuit wizard. because it doesnt have any linked company parts it caused for the connections of the parts I then ordered to be wrong.
 

depeet

New Member
@Tom_longden118 : with so many switches I started to think about the principle of a numeric keypad. Make an output high and look which pin (C.3, C.4, C.5 or C.6) becomes high. For example, if switch Joyleft is closed, an interrogation on line C.0 will result in a high signal on Picaxe input C.5

In this setup, I've put all the switches of the joytsick on 1 line (C.0), but you can make the matrix the way you want.

Anyway, in this matrix you can interrogate up to 12 switches with only 7 pins of the picaxe.

23170
 

hippy

Technical Support
Staff member
Anyway, in this matrix you can interrogate up to 12 switches with only 7 pins of the picaxe.
True, but the problem with putting the limit switches on the joystick and button handling PICAXE, rather than on the motor driving PICAXE, is that one cannot so easily test and debug the motor handling PICAXE separately.

If the motor handler is instructed from a PC, controlled via Terminal in PE6 say, rather than the button PICAXE to go forward; it will, with no self-contained means to tell it that it has hit the limit and should stop moving, it won't stop, it will keep moving.

An analogy is a driver and navigator in a car. If the driver does only what they are told it falls to the navigator to stop the driver driving into a wall, because the driver isn't going to stop until told to.

Rather than have a "do as you are told" scheme it is better to have "do as you are told except when you know that's not a good idea". That can only be achieved if the driver can determine for themselves when it's not a good idea to obey commands given.

Code:
            .---.        .---.
Joystick -->|   |---//---|   |---> Motor | Limit detect >--.
            `---'        `---'                             |
                           |                               |
                           `-------------------------------'
 

hippy

Technical Support
Staff member
Good engineering design of any kind is not actually supposed to be trial by error.
I would say that it invariable is, especially with software and hardware engineering; an iterative process of proposals and asking 'will this work?', followed by an analysis of how well it conforms with what is required and an assessment of what potential flaws there may be. Refinements continuing until one has a solid design.

So, the internal process can be seen as trial and error in many ways.

Like my earlier design which forgot an output; so back to the drawing board with that.
 

hippy

Technical Support
Staff member
To lower the pincount on the microcontroller side, taking it from 12 to 6, you could consider using the 2 wire-control as documented in http://www.tigoe.com/pcomp/code/circuits/motors/stepper-motors/.
Good idea. But does that allow three state control though; stopped, stepping forward and backwards ? It wasn't clear to me if it does.

And the main issue seems to be, in using the Darlington to do inversions to get down to two control signals it increases the number of Darlingtons required when there's more than one motor.

Not saying that's bad per se, but it does demonstrate how there are those numerous ways to skin a cat with it often hard to determine which would be best. We wouldn't even need to argue over signal count if a larger PICAXE were used. But reality is that 'easiest' isn't always preferable.
 
Thank you to everyone that helped me with this.

its short notice but I've fully finished the coursework and I am moving onto the next project.

@Technoman @hippy @depeet especialy thank you and the community.

I went with the 20x2 chips with 3 uln chips to control everything.

I won't be able to post what I did here sorry. but seriously thanks
 
Top