Well it’s not really software …

It’s been quite a while since my last post … this is largely due to two things …

1. My day job suddenly exploded (in a good way) … which means more of my spare time thinking about that rather than getting distracted.

2. I got distracted by FPGA’s 🙂

So in my quest for a more powerful embedded processor I stumbled upon the whole FPGA world, for anyone not familiar these are “Field Programmable Gate Arrays” … basically these are a big bucket of logic that you can program to perform specific functions in hardware, hence they can be very performant and do things you wouldn’t be able to acheive with low power embedded CPU’s.

I had looked at FPGA’s before, but they were expensive, difficult to use for the hobbyist (i.e. packages you couldn’t easily hand solder), and incredibly difficult to program.

Well it seems the world has changed…

There are now a range of FPGA’s that are pretty low cost (around £10 to £20) that have pretty good functionality, my SMD skills have improved so hand soldering is an option (although milling my own boards has gone out of the window … more on this later), and come with tools that make them reasonably straightforward to program. I show the Xilinx logo here since they seem to be the most prolific in the low cost and hobbyist space, however there are other offerings from people like Altera and Lattice that are definitely worth looking at also.

To make things even easier there are now a couple of Arduino-like boards around that you can use to experiment.

My favourite is the “Papilio One“, a very simple board consisting of the FPGA, some flash (for storing the “code”) and bits to interface via USB. It’s low cost, easy to use, and you can even run an Atmel CPU core inside it so that it simulates and Arduino, then you can build extra bits in “hardware” to do whizzy things.

My early experiments have centered around doing stuff with VGA, these devices are powerful enough to actually generate a VGA signal on the fly, you can then either create the image by pulling data from RAM (i.e. a bitmap or framebuffer) or you can create images using logic. I’ve built a small “wing” (expansion board for the Papilio One) to do 12-bit colour VGA, and I’ve designed another board to act as a 320×240 3.5″ LCD breakout board … just waiting for that to be deliverered, then I can start playing with LCD’s.

A great inspiration was the “Gameduino” which really shows what can be acheived.

Programming these things is interesting, especially if you’re used to working procedurally … absolutely everything happens in parallel, which is incredibly powerful, and sometimes quite challenging.

More to follow … I think this one will run … at least until I get distracted again 🙂



Linear Bipolar Stepper Controller … early thoughts

In my continued hunt for the holy grain of CNC Controller cards my thoughts have moved away from current chopping IC’s and towards linear control.

This has driven a number of interesting experiments and distractions all over the place, but it’s getting to the point where I’m close to building the first one, so making it worthy of a blog and hopefully some feedback.

Big Caveat:  I am not an electronics expert, all opinions expressed here are gathered from the net, my experiments, and more usually mental extrapolation with very questionably foundations. So please feel free to point out the errors of my way.

First a little comment about PWM/Current Chopping vs. Linear controllers.

Stepper motors seem to be devices that usually like a very small voltage, the Nema17 ones I’m playing with seem to like 2.8V, and for speed control the typical approach is to use PWM and vary the duty cycle. Marry these two things together and you can get away with much higher (easier to control) voltages and use PWM and current limiting to ensure the total power is appropriate for the motor.

There are loads of devices out there that do this, I’ve researched (and prototyped) the TB6560 which is used in many lower cost CNC controller boards (including a chinese one that I’ve battled with), I’ve also used the Pololu A4983 boards which are based on the Allegro A4983 chip. Actually these devices to a pretty good job, they also allow micro-stepping to provide more steps that the motor physically accomodates (it does this by diffentially powering the different windings to hold the motor in a sub-step position.)

So far, all is good. I’m using a 16 stepping A4983 at the moment (see my Home Grown driver board) and it does a nice job.

However … the PWM approach uses a high frequency to turn the supply on and off and this can be heard in the motors as a whine or squeal depending on how good the driver is and how much current you are supplying. This chopping also leads to more heat generation in the motor (there a good Wiki article on why, but it’s really beyond my capabilities). Also, some of the existing driver IC’s have quite limiting requirements … the signal pulse width requirement on the TB6560 is something that I’m sure more people are running out of spec, especially on Mach3 which doesn’t do long pulses!

All that said, I was fairly content with the drivers until I discovered the Linistepper, this showed that there were relatively simply ways to use a linear driver. The Linistepper didn’t handle bipolar motors, but the principles look applicable.

Basically the linear approach is all about driving the motor at the correct voltage and then varying the voltage (and hence current) to acheive the desired positioning. It’s linear because the voltage is constantly applied, there’s no chopping, no PWM … so there should be no whining, the motor should be cooler (although you’ll get the heat in the driver) and you have infinite ability to vary the microstepping by controlling the voltage.

So … thoughts forming … rather than using a fairly limited resistor stack to select current levels, we could use a microcontroller (I love microcontrollers) … then we could either use a PWM source with a low-pass filter to create a control voltage or a DAC.

For actual motor control, a traditional H-Bridge, but with Darlingtons, one pair will be used as simple switches (could probably use FET’s here, may be cooler, need to experiment) and the other pair will be used to control the current (and hence voltage) … using the TIP122/127 combination, we have a gain of 1000 … therefore for a 2A capable system we only need to drive the base 2mA, should be doable.

So, all conceptually looking good … the Atmel ATTiny261A has a high speed timer that we could use at the PWM source, with two compare registers and a bit of switching logic and an op-amp or two we could drive everything we need. But … I know nothing about filters, so Spice (circuit emulation) allows a bit of experimentation.

So after playing with both passive and active filters for a while, I get a bit concerned about the responsiveness … you are basically filtering out the high frequency PWM signal and should be left with a DC voltage proportional to the duty cycle. To get the best smoothing you need a bigger RC network, but this slows down the overall ramp up/down speed. You get better performance if you speed up the PWM, but this then limits your granularity.

Grrr … there’s always compromises! Anyway, bottom line is that PWM looks viable, and I’ll probably do some experimenting with it, however I am concerned about speed and smoothness … both are probably fine, but if you’re going to do it, lets to it well!

So, DAC’s are the other option … because of the way you need to drive the motors you need four DAC’s (or some switching) to control the two phases of the motor. So I started looking at how to interface DAC’s to the Atmel … again a bit tough, parallel uses loads of pins, anything serial has speed implications, not to mention an overall cost impact.

How about microcontrollers with DAC’s built in? Bizarely there aren’t many of these, some of the newest Atmel devices (the XMega’s) have two DAC’s in, but they seem quite limited and noise prone … and these devices are very fine pitch 100 pin SMT packages and will be a nightmare to prototype.

So here comes the next distraction … PSoC (Programmable System on Chip), from Cypres … Microcontrollers with loads of features and an element of customisability.

A number of the the PSoC1 devices have the capability to run 4 x 9Bit DAC’s at pretty high speed and they have enough analogue control to inject an offset (to get near to the 1.4v base threshold on the TIP’s) and enough power to drive them with no extra components (other than a resistor to control base current.)

As an aside, the PSoC3 and 5 devices are really really nice, you can build a load of stuff actually in the programmable logic area, and I think the next project will be building a much more capable device with those, with virtually no software. More on that later.

So, current status…

I have a breadboard H-Bridge with TIP122/127 transistors capable of driving a single phase of the stepper.

I have a PSoC1 device programmed up to create the Sine Wave’s for the two control lines and two signal lines for the single phase … adding the second phase is very trivial.

I have a schematic and board designed.

So, some testing on the breadboard, and then hopefully onto first prototype board. I put a single axis controller (capable of anything down to 128 microsteps, depends on your ability to drive it), capable of 2A per winding, driving a max of 3.6v … around £10. So a fully functional 3-Axis board (obviously including my customary spindle PWM controller) at around £40.

I’d love some feedback on this.


One distraction after another…

Hello, and welcome to Random Thinker.

There is a long story about how this blog/site came into being and I thought that was probably worthy of my first blog posting. The story is fundamentally a tale of starting something, getting distracted by an aspect of it, digging deeper, getting distracted by an aspect of that, digging deeper etc.

The problem is that I’ve never finished the first thing, but the good thing is that I’ve learnt a whole heap of things along the way.

So it all started with a power cut (which is a fairly regular thing) and my two DSL modems didn’t come back online properly, they’re stuck up in a fairly inaccessible attic space so it’s a pain to get up there and manually power cycle them. I did a bit of research into network power strips with the idea of being able to turn sockets on and off from my iPhone or other device on the network, but they were very expensive.

So, next idea, build one!  One of the things you’ll hopefully notice about the Random Thinker is that if we can’t something we build it!

Anyway, with a smattering of electronics experience in the dim and distant past, and some experiments with customising old wireless routers using OpenWRT a plan was born … however even simple things like the sockets themselves and the enclosure looked to be very expensive. Then I discovered the ‘energenie’ radio controlled power strip. Four sockets controlled by a small radio based remote.

Now here’s problem number 1 … this would actually have been the perfect solution to my problem, but no, RT needed a network based solution. Why? Because it’s more techy!

So the good thing is that this device has four sockets, an enclosure and what looked to be a fair amount of space to house a custom board, but that board had to be small.

So now I feel I’m dragging this out a bit, perhaps I’ll make this the subject of another blog … the long and the short of it, I did some prototyping, bought a tiny 5v switched mode PSU board, a tiny Bifferboard to provide control and network, and then started looking at how to manufacture my PCB.

In my distant past I’d done a small amount of PCB work, mostly using Ferric Chloride to etch, and old fashioned tape to lay out the board. The UV approach is now much more straightforward, and easily done at home … I came very close to buying a UV exposure unit.

Problem 2 … I only want to manufacture the one board, you can send away to have prototype boards made for you, they are great … perfect quality, multi-layer, through hole plating, solder resist, screen printing … works out about £30ish. Why don’t I just do that? Because making boards yourself is far more fun!

So then I discovered the best way to make PCB’s at home … the Zen 7×7 CNC Milling Machine kit! This is a home-build kit of a fully functional CNC milling machine that you can use to do all sorts of things, but it does a really nice job of milling PCB’s using a method called isolation routing.

A bit extreme, you may think, for one PCB … but hopefully you’re learning that that’s not the point!  You can buy the kit in a variety of different flavours, with the basic one including all the basic materials and the stepper motors, all you need in addition is a controller card and the relevant software.

Now given that RT is based in the UK, and Zen are based in the US, and those nasty customs people like to add duty/VAT payments I wanted to keep the import amout as small as possible so I just ordered the basic kit, I could get the controller card from eBay where there were loads advertised.

The kit arrived, absolutely brilliant … you only need a screwdriver, an allen key, and a vice to build it … very easy, great fun (other than pushing the bearings in), and a couple of hours later I had a fully built CNC machine … unfortunately since my controller was coming from China/Hong Kong I had to wait a couple of weeks longer until I could get going.

In the meantime I start doing some research and discovered that all of these controller cards are run through the parallel port, and because of the nature of the control mechanism, the timing is critical and certain hardware and things on the OS can cause major problems.

Problem 3 … I should have just accepted this, but NO, not RT. This can’t be sensible, not in 2011! What we need is a separate controller, USB or Network that takes that pain away. There are some available, but, guess what … very expensive.

So, recognising that this isn’t a simple task, more detailed research into the technologies was required. This meant I became quite an expert (on paper at least) on the TB6560 controller chip used in most of these controller cards … I even built a horrific test board just to prove I could get it to work. Don’t laugh, it was functional and proved a couple of points which would be very useful later.

So then, thankfully, my card arrived from China. All up and running and things were great … I spent a fair amount of time working through tooling, speeds, feeds etc for milling PCB’s but was getting some reasonable results. Then I decided that the Zen Spindle I was using wasn’t accurate enough for the seriously fine SMT boards that I needed to create, so I ordered a Wolfgang Engineering TB-650 (not shown on his web site). This spindle needed a new mount, which I could make myself using the CNC machine … this highlighted a problem with missing steps and then led me on a very long and detailed diagnosis of the Chinese TB6560 card … this resulted in me finding numerous problems … this will be the subject of another blog post.

So, not content with the Chinese card, I decided to build my own … so I used some small controller modules and built a card (with separate PWM controller for the spindle) around them. This worked really well and is still the controller card I’m using today.

But that is not the end of the story … all of these controllers use a “chopping” method to control the motors, this means turning the supply on and off really quickly and picking the point to turn it off based on the current needed at any given point in time. This all works ok, but it’s not ideal … and there seems to be a view that “linear” controllers are better, but more expensive. Then I found Linistepper and realised that this was something I could build.

I’m a great fan of the Atmel Microcontrollers (there’s one on the board above), and so they seemed like an obvious choice, but in working out how to handle getting a controllable analogue signal I discovered the Cypress PSoC devices and so will experiment with those.

So it all started with a power cut, and I’ve been through power controllers, CNC machines, controllers cards, controllers chips, stepper motor control, microcontrollers, and now the PSoC devices. The good thing is that I have built a nice controller card, and use that every day for milling PCB’s, and I have great plans for the next “linear” version. My plan is to blog about some of the key aspects of this individually and also publish the outputs on my project pages.

I still don’t have the power controller 🙂

Happy distractions. RT.