CNC Controller

Circuit Design&CNC Controller&Electronics&Hardware&PCB Layout&Projects04 Feb 2012 10:58 am

Armed with a blinking LED program, I set to work attempting to flesh out the rest of the software for the CNC board. I built and tested a nested vectored interrupt handler, and started trying to port my USB stack from another chip that has very similar USB hardware. As time went on though, the outlook became a bit bleak; A number of things did not appear to be working as intended on this chip, and the manufacturer’s example code included bizzare comments and workarounds for some pretty impactful bugs that weren’t otherwise documented. Not confident that I would be able to make this chip work the way that I wanted, and being less than thrilled with the ease of assembly and some of the design of the CNC Rev1 board, I decided to make a new CNC board.

My design goals would be:

  • Ensure the design will work, by using chips I’m familiar with & already have code working on.
  • Reduce complexity by only having one motor driving voltage, but still allow that voltage to be changed.
  • Reduce the part count per motor, by consolidating components into fewer packages and taking a different design path driving the motors.


CNC Controller&Electronics&Hardware&Projects31 Jan 2012 12:31 am

As I mentioned earlier, JTAG is a pretty simple protocol. For the ucHelper I’ve designed a command-oriented serial protocol that allows me to perform various JTAG and UART operations. After some initial trouble with physical connections on the CNC board, it was possible to enumerate the JTAG chain! In order to be sure JTAG was really working as intended, I took a short detour and wrote an SVF player, and was able to program some existing Xilinx FPGA boards from SVF files (like serialeth).

The ARM Chip I was using on the CNC board (NXP LPC2927) has two JTAG chains – one of them is a boundary scan / flash (and who knows what else) chain, and the other is for the ARM9 standard debug interface. I only really wanted to program the flash, so I started out with the flash chain – There was some documentation for the JTAG flash interface of a previous chip in the series so I was hopeful this one would be similar.

Unfortunately it was not meant to be. The enable bits / initial handshake sequence for the flash controller on this chip seems to be entirely different than the earlier one, sometime I may go back and find the right bits to make that work, but I shifted my focus to using the ARM debug interface. The first thing I noticed, is that it didn’t work :) As it turns out (after connecting the layers of deep indirection in the documentation), you must have a crystal in a specific range of frequencies for it to work; After fixing that though, I began to make progress on that front. the ARM debug interface for this chip is relatively well documented in the ARM9 documentation on ARM’s site. Documentation always seems to leave something to be desired, but this was at least relatively unambiguous – and worked!

Effectively, the ARM9 chips (also most other ARM chips), for a debug interface, simply intercept the processor’s instruction and data busses, and allow you to single step the processor. So you can perform operations by injecting the instruction you wish to execute, and single stepping. You can write a register to an arbitrary memory location, which causes it to be intercepted on the data bus (afterwards you can read the data bus) – Similarly you can read from memory and it will end up reading the value you insert onto the data bus into a register. It’s a rather minimal and effective debugging interface, it doesn’t consume much in the way of hardware resources, though the software to do anything useful with it has to be a bit complicated as a result.

Since the single step operations capture the data bus, it’s not possible to directly modify or read system memory through them, but there is another special provision for doing this, for executing individual instructions synchronized with the normal CPU clock that can interact with memory. So, I wrote a handful of wrappers that would allow me to manipulate the CPU’s registers and read from / write to memory, and around that built a small program that wrote the flash using the system’s internal flash controller.

With that literal pile of work behind me, I set off building software for the ARM chip itself. A short amount of time later, I had a blinking LED (Because this is naturally the most important thing to do with /any/ piece of hardware)


(Not visible: LEDs blinking)

(Continuity note: Note that the above board is not the same one as the board shown in part 1! At some point in messing with the JTAG chains I became sufficiently frustrated with the quality of connections on the first board, which had been reworked a few too many times perhaps, that I built a second board and took special care in making sure the JTAG chains and other important connections were in good shape. It’s a bit less than fully populated because… placing some 400-500 components is HARD!)

(More to come in part 4…)

CNC Controller&Electronics&Hardware&Projects28 Jan 2012 03:33 pm

Around the middle of December I decided it was finally time to make this project actually work.

I took the one CNC board I had assembled, such a long time back, and subjected it to an initial smoke test (connecting the power, that is). There was smoke. Not discouraged by the loss of a chip or two, I took a further look. I found that the assembly of the first board had hit a number of major snags; The board was 2oz copper in order to be capable of routing large current loads to the motors – but the groundplane was exceptionally difficult to solder to, even though the pads have thermals. I found that one of the chips broke because a resistor intended to keep an “enable” signal low was not connected to the groundplane, and the other one, a FPGA, was installed backwards (these FPGAs have two circles on the top which could indicate pin 1; Unfortunately the wrong one was chosen and I didn’t check.)

Undeterred, I pressed forwards with getting this board to work. I replaced the FPGA and rotated the other one, doublechecked a lot of signals (there were still some components on the back side of the board that were not properly connected to ground). All the poor connections were on the back side of the board, the top side had been reflowed and the connections seemed uniformly good there.

After those fixes and some cleanup, ran the smoke test again – The board powered up without smoke! A first small victory down this path – But many more things remained.

So, let me tell you about JTAG. I made a post on jtag a long time ago, when I was first starting to mess with it; but for this project I decided to build my own JTAG tools to program the chips involved & for other nefarious purposes.

I have made a few starts  towards my own jtag stack over time, first was an AVR-based board intended to program all manner of things – This project ultimately stagnated as the jtag level shifting interfered with actually programming the AVR chip itself. Despite a fix, building out the stack was a big project and never was completed.

While I was designing the CNC board though, I had the idea for a more specific debugging helper tool geared for it, and not too long after designing the CNC board, I did build such a device based on a chip I had come to know and love (and built a USB stack for…) – this was the ucHelper, PCBs shown below.


ucHelper is really just a minimal JTAG and serial interface board – Being exactly what I needed for programming and debugging here though, I got started on writing the code for it.

(more in part 3)


CNC Controller&Electronics&Projects27 Jan 2012 02:29 am

It’s been just over a year since I decided to seriously pursue building my own 3D printer, and while it has been taking a back seat to a lot of other projects I’ve been doing, it’s looking like it will finally come together in the next few weeks!

The CNC Controller in the last two posts was my first big move towards realizing the idea; Being  a stubborn sort, I’ve wanted to build the entire thing entirely myself – Historically this has been both a good and a bad decision; I like owning the entire stack in a project, but it comes at a price – Actually building and completing the project takes a lot longer. The upside is I get a lot of experience from such projects, and learn a lot about a wide variety of things – this is ultimately the reason I do it so much.

I did finally concede to use an existing 3D Printer hardware design, and near the end of last year built a Prusa Mendel from a kit of printed parts & hardware (pic below)


However I am still quite determined to own the electronics. Around the very end of 2011 I finally decided to put the effort into making this project happen, and started to bring up the CNC board I had designed.

(More in part 2)

Circuit Design&CNC Controller&Electronics23 Jul 2011 04:54 pm

Ah, it’s been a while.

Since I opted to stop posting on a fixed schedule, that seems to have eliminated any hope of regular updates – oh well.

So, I have been largely tied up in a (Very big) project that’s still secret, I’m not saying much about it. But there have been a few bits of progress in other areas – Most notably, I finally got a CNC controller board populated!

Fully populated CNC board

Isn’t it lovely?  I certainly think so, after all the work that went into getting this far :)

Sadly, I won’t really get much further at the moment (need to get back to an all-consuming secret project), but this has marked a pretty big milestone in a few of my projects (the reflow controller also works pretty nicely!)

I’ll be sure to take some time and write up these when I make some more progress (or just get sick of working on the more important stuff again)