Tuesday, 6 August 2013

Design and Test, Part Two

Testing Day Two

As mentioned before, I'd tested and debugged my hardware to the point where it's time to start integrating the systems.  Or in other words get the micro talking to the rest of the board.
Notice Something Strange?

Method In The Madness

I've used PIC's in a lot of my designs, as I had accumulated the tools for these over the course of my working career.  However, I've been following the growth in Arduino with interest, and as it's the intention of myself and Nick who's collaborating with me, to open source this design (once the bugs are out of the hardware) the decision was to base this build on an Arduino.

We chose the Leonardo, although the Uno probably has enough under the hood, for the sole reason that we both like having a serial debug port option.  As we need a serial port to talk to the SIM900, the built in USB interface of the ATMEGA32U4 gives us this debug port.

And before you ask, we decided to not pursue the use of a software UART, because they suck.  No, you're wrong.  Don't use them. (Seriously software UARTs are fine if that's your only option but puts a lot of overhead on the code.  Using a hardware UART makes code that much easier).


After loading the programming header, disappointment immediately followed.  Just as bad as getting 0V from your power supply, we couldn't talk to the ATMEGA32U4.  
Time to do the basic checks - 5V present?  Yep.  Ground connected?  Yep?  Programming header wired the right way?  Of course not.....

I'd managed to mix up the MOSI and MIS0 pins on the programming header.  And rather than hack the board, I figured it would be neater to knock out a little adaptor board.  After all, once the bootloader was in, future programming would be via the Arduino studio.

Like This!
Fit-It Board Schematic

Fix-It PCB.  I don't do 3D for everything!

I swapped the programming header with a socket on the prototype, and installed the Fix-it board. (Must. Resist. Temptation. To. Call. It. Felix.)

Glamour Shot.

Other Glamour Shot.
With the Fix-it board in place, we could discover the micro, and upload the bootloader.  IMHO this is a nicer fix than hacking away at the PCB but I'm annoyed that I made this mistake.  The Leonardo is an open source design and and the Eagle files are there for review.  

So I could have installed Eagle and checked my work.  To rub salt into the wounds I've since found there are scripts that you can run in Eagle to convert the PCB to an Altium compatible file and that makes review easy.  Dammit. 

It Lives!

Anyway, once my little adaptor board was ready, it was time to try shooting the bootlaoder into it.

Hooked Up

AVRISP detected the target micro and I was in business.


For a clone Leonardo, the firmware you need is the 'Caterina-Leonardo.hex' in the Arduino studio.  If you're a windows user it can be found under this path:


If you're using Linux...  look it up yourself.

Once the boatloader was in, the Blink.ino sketch was uplaoded and .. our chosen led blinked waaaaay too slow.  The problem lay in the fuse settings - we were still running the defaults.

Following the instructions to be found here, we were able to configure the fuses and we had a led happily blinking away at 2Hz.  Huzzah!

Up until now we were using the AVRISP programmer, and uploading via the 'Upload Using Programmer' command in the Arduino IDE.


Arduino IDE
Time to try bootlaoding over the USB!


Yeah, As if it were that easy...

If you take a look at the shot below you might notice two things.

Spot the Mistakes

The first is the little wire link between R22 and R28 (Altium shot for reference).

I should have mentioned this last post, but when testing my comparator the LED I used for a voltage reference failed to illuminate.  The reason was I'd not connected the 5V net correctly and the wire link is a simple fix.  But what went wrong?
Comparator Pull Up

You can see my schematic for the Comparator pull up resistor is tied to the 5V net.  This works.

5V is there, right?

And here's the 5V net on my LED resistor.  Looks fine, I didn't miss it, but the net didn't get to the PCB.  Huh?

What happened was that i'd not correctly placed the net at the end of the resistor, I'd overlapped the 'wire' part of both and this doesn't register as a connection.

This isn't Altium's fault.  If I'd run the Design Rule Check before committing to a PCB, this would have resulted in a error (unconnected net on R22) but I didn't and now I have a link.  It's hard checking your own work.....

The other issue?  I stuffed up the USB connection.....

Stress Testing

Once we'd got the bootloader running, it was time to hook up the USB.  I soldered in the micro-usb connector, plugged it into the PC, and it didn't work.  Sigh.

Then the micro USB cable got hot.  uh-oh.

If you take a look at the part I used, the datasheet isn't obvious at pointing out how the pins are numbered.

Not at all clear

So I took a look at wiki and compared it with my connector:
Wiki Says..

My Board
So by comparing the wiki pinout for the Micro-B connector with my PCB model, and accounting for rotating (as mine is 'upside down' compared to the wiki shot) I came up 1 -5 being right to left, as shown in my PCB screenshot below.
My USB Pinout.
After killing the micro-usb cable I was immediately suspicious that I'd got ground and 5V mixed up.  Perhaps I'd got the pin order reversed?
After converting the Leonardo board to Altium and taking a look:
It's obvious I'd stuffed it.  

The next question was how was I going to work around this?   I could cut traces and solder links, but that would take some time and as I've got enough errors to warrant a new PCB design I took another path.


The micro-usb cable that I'd tortured actually melted at the micro-a end, so that was cut off and the cabling soldered directly to the board.  This time, it connected, and  was in action!  We have boatloader!

A bit miffed, I was having a whinge to my mate Nick about how crap it was that the datasheet didn't even label the pins correctly.  You know, blame anyone but yourself for your problems :)  Nick took one look at the datasheet and then pointed out the obvious....

Live and learn...

You can follow the series here:

Cutting Out the Middle Man
Design and Test Part 1
Design and Test Part 2
Design and Test Part 3
Implemented.  Whoo Hoo!

No comments:

Post a Comment