I can’t machine for toffee

24 February, 2009

I had a go at doing some mechanical work at the weekend. I tried to machine the acrylic I bought and create some kind of joint using a stepper motor. I have to say that I failed rather miserably!

I tried scoring and snapping the stuff only to find that a cut length of anything longer than about 10cm was impossible! A hacksaw proved much better but I really don’t have the benches, vice, etc to make a decent job of it. I’m now thinking about getting something made up. The problem with that is that I’m finding it difficult to start designing when faced with a blank screen on a CAD package. It is holding the robot arm project up though.

21022009130

In other news…

I purchased some bits off ebay. Firstly I bought some Picaxe compatible kits to help me prototype. Some of these are Picaxe-08 kits so I shall be making some compact stepper motor controls shortly. They were from rkeducation (they also have a web site).

Secondly, inspired by a kite aerial photography (and some RC) videos I decided to buy some radio gear. I now have a 6 channel transmitter and receiver which work well with the servos I have. I see a few more projects coming up…

Advertisements

Bipolar stepper motor control with Picaxe and L293D chips

28 January, 2009

I’ve now got a schematic and program for running a bipolar stepper motor via a serial interface (just as for the unipolar case). This is important for the robot arm cause because two of the three steppers will be of the bipolar kind.
Where driving the unipolar stepper required only current ‘pushing’ (ie all in the same direction through a common ground), a bipolar motor requires current to flow in both directions. The following image shows the difference.

steppers

In theory the control of this is very easy with two half H-bridges (essentially four transistors) controlled by several Picaxe output lines). The basic concept is shown below.

image

(Source: http://commons.wikimedia.org/wiki/File:Bipolar_Stepper_Motor_H-bridge.png)

The L293D chip has the requisite transistors and a nice interface (with lots of extra features that my DIY skills couldn’t match). I’ve also used it in the mobile robot experiment to control the direction of 2 motors.

As with anything like this though, one needs to think through the sequence and outline a table of output values corresponding to the steps, as below.

Direction Coil 1 Coil 2
N + 0
NE + +
E 0 +
SE +
S 0
SW
W 0
NW +

At first I was using 6 output lines (!) – 4 for each of the transistor inputs and 2 for enabling or disabling the L293D’s 2 ‘half h-bridges’. In this configuration it could be reduced to 4 by using an external NOT gate (because 2 of the controls are always the opposite of another 2). Such a scheme would look like this:

Direction EN1-2 1A 2A EN3-4 3A 4A
N 1 1 0 0 0 0
NE 1 1 0 1 1 0
E 0 0 0 1 1 0
SE 1 0 1 1 1 0
S 1 0 1 0 0 0
SW 1 0 1 1 0 1
W 0 0 0 1 0 1
NW 1 1 0 1 0 1

But while trouble shooting this (I had swapped LSBs with MSBs so it probably did work after all!) I came across a site tying the enable lines Hi and using 4 control lines. At the poles one of the loops must have zero current flowing through it. In the above scheme this is done by setting the enable line Low and ignoring the A values. In the 4 line scheme this can be achieved by sending the same control output to both ends of the loop (ie the potential difference across the coil is 0). Then the table looks like this (including half stepping):

Direction 1A 2A 3A 4A
N 1 0 0 0
NE 1 0 1 0
E 0 0 1 0
SE 0 1 1 0
S 0 1 0 0
SW 0 1 0 1
W 0 0 0 1
NW 1 0 0 1

That makes the schematic as follows:

bipolar_schematic

…and the program as follows. Note that this program is designed to wait until it detects a serial input on input 0 (pin 17) in the form of three bytes: The first is a qualifier – 85 uniquely identifies this stepper motor – the second is the number of steps – 0-255, and the third is the speed – 0-127 is backwards, 128-255 is forwards.

'Serial driven stepper motor by DMT195

symbol posrotor=b0
symbol numturns=b2
symbol speeddir=b7
symbol direc=b8
symbol pulsegap=b3
symbol counter=b4
symbol modrotor=b1
symbol outbyte=b5

posrotor = 1 'set starting position

start:    'main sequence - wait for command then move the motor
 numturns=0   'sets a default number of turns
 high 7    'reset ready flag
 serin 0,T2400,(85),numturns,speeddir 'get serial data
 gosub getspeed   'get the direction and speed
 gosub move       'perform number of steps
goto start

getspeed:
 if speeddir>128 then  'find direction and store in direc (1 is +ve, 0 is -ve)
  direc=1
 else
  direc=0
 endif
 speeddir=speeddir//128
 'gets the speed 0-127 negative, 128-255 positive (higher =faster)
 pulsegap=264-2*speeddir
return

move:
 for counter=1 to numturns
  pause pulsegap      'wait before moving again (set by speed)
 if direc=1 then
  posrotor=posrotor+1 'increase/decrease the step by one
 else
  posrotor=posrotor-1
 endif
   gosub moverotor  'set the rotor position for this step
 next counter
return

moverotor:
 modrotor=posrotor//8    'find out where the rotor arm should be (1 of 8 positions)
 lookup modrotor, (0x08,0x0A,0x02,0x06,0x04,0x05,0x01,0x09), outbuyte
 '(%00001000,%00001010,%00000010,%00000110,%00000100,%00000101,%00000001,%00001001) is (0x08,0x0A,0x02,0x06,0x04,0x05,0x01,0x09) in hex
 'looks up the step from the sequence and applies it to the output pins
 pins=outbyte
return

Please leave comments if you’ve found this useful or if you think I’ve made a mistake.

I have something to say about accessing all these devices through a single serial port too but that will have to wait for one or two more tests…

Update: Of course this can be done with a PICAXE 08(M)  with the 4 outputs and 1 serial input to spare. The pinouts would have to change as would the respective program. If there’s enough demand for me to document this I will. Let me know in the comments. Consider using this little board from Technobots.

Update 2: I’ve reduced the code length by using a lookup table instead of the select/case structure. I’ve also use hex to reduce the size of that line (but included the binary values in a comment below for those that are interested).


My First geeky YouTube video

9 April, 2008

It’ll be video podcasts next ;-)

[YouTube=http://www.youtube.com/watch?v=HRzqh8Hb4xk]
YouTube – Unipolar stepper motor controller PCB with serial input


Committed to a PCB

6 April, 2008

So here is the unipolar stepper motor controller committed to a PCB. It’s my first PCB that I’ve made and populated from scratch. I used the toner-transfer method and then drilled out the holes with a small drill. I’ve got a programmer on there so I can upgrade the firmware if needed. The connector for power and a serial command is a bit of a hassle at the moment but will fit in with my grand scheme! Note: this need regulated power, which I’m assuming will come from a master board (the supplier of the serial). This makes sense as I’ll have multiple (modular) controller boards.Unipolar stepper motor controller PCB


PICAXE unipolar stepper motor controller

8 March, 2008

Here’s my stepper motor controller, based on an 18 pin PICAXE microcontroller. The idea is that this chip takes away the processing overhead associated controlling a stepper. A master CPU (of some kind, potentially a PC) can send a serial command to the PICAXE telling it how much to move and at what speed (and direction). A Darlington driver array controls the power and a 7-segment display shows the current coil powering. Here’s the schematic (PICAXE programming connector not shown):

schematic

The way I’ve programmed this is different to other approaches I’ve seen. These tend to complete a full rotation every time. I’m sure others have done controllers that manage sub-rotation control like this but maybe not the way I’ve done it. I basically have a single value which defines how far the motor has rotated. I then increase this number step wise and use modulo division (//) to find out what position the rotor should have.

Program and video of operation after the break…

Read the rest of this entry »


More than a PIC – the PICAXE

5 March, 2008

I got so far with my Microchip PIC development until I realised that the learning curve was steepening! The open source compiler I was using wasn’t really up to the job and the ‘real’ compilers were very expensive (for casual use). So I started looking around again…
I came back to looking at the PICAXE chips. For some reason I’d overlooked them but quickly realised they were just what I needed. All the elements are there:

  • Cheap chips (few quid each)
  • Free compiler
  • Cheap cables and no special programmers
  • Great documentation (I bought a cheap book too although much of the info is online!)

Again these use basic. It was so quick to learn that I’d caught up and surpassed my PIC development in a single session. I’m currently controlling a stepper motor from a serial interface. I think I’m doing it differently to other approaches so I will upload some data soon. Until then, go out and buy some PICAXE chips and get programming!!

Update: See the results here!