jenswilly.dk

Microcontrollers and embedded electronics

PCB layout done

19. November 2011 22:29 by Jens Willy Johannsen
Categories: PCB, Projects | Tags:

First version of the PCB for the RGB Tumbler is ready. Although usually I do through a couple of revisions before I send it off and get it made.

The PCB ended up somewhat larger that I had originally planned. It is currently 3.6 x 3.6 mm.

Here are pictures of the PCB printed in 1:1 scale and populated with components to verify that everything fits (click for larger images):

Top side (click for large version)

Bottom side (click for large version)

I need to move the slide switch a bit up to make room for the 10 µF capacitor. And I will also move the battery holder up a little bit. The NCP1402 voltage booster almost touches it. Apart from that, everything looks pretty good.

Another problem is that I ended up placing several vias directly under thethe battery. This may not be the best thing. Especially since the vias on ITead's PCBs (ITead Studio is where I get my PCBs made) are not always completely covered (even though the Gerber files say they should be covered). I guess I'll just have to cover the vias myself with some tape or something).

No comments No comments »

RGB Tumbler prototype

15. November 2011 23:40 by Jens Willy Johannsen
Categories: Projects | Tags:

Here's the prototype of the RGB Tumbler in all its glory – click to see hi-res image:

Click for large version

No comments No comments »

Prototype ready

15. November 2011 23:02 by Jens Willy Johannsen
Categories: Projects | Tags:

The prototype has been assembled and the first version of the firmware (including the no-button, Gauss-Newton calibration) is done. The calibration routine has been converted from Rolfe Schmidt's Arduino sketch to raw AVR Libc.

Here's a video of the prototype being put into calibration mode, calibrated and then turned on in normal mode.
The camera doesn't do the RGB LED credit and the colors aren't reproduced very well – probably because of the high intensity of the LED.

And I have changed the colors a bit since the last few posts. So now a white light on power-on means "if you switch off now the device will go into calibration mode on next power-up". And the blue flashing LED means "switch to next orientation and hold the sensor still". After a reading it will flash twice either green (meaning "reading ok") or red (meaning "bad reading – hold it still, man")  and lastly it will keep flashing green meaning "calibration done – cycle power".

When in normal mode, the G readings on each axis are clamped to 0-1 (I'm using the absolute value, so -1 G is the same as +1 G). This is then converted to a PWM duty cycle between 0% and 100%.
Red is the X-axis, green is Y and blue is Z. That's why it lights a solid blue when lying flat on the table: the only acceleration is 1 G on the Z-axis.

Kommentarer 1 comment »

No-button calibration

15. November 2011 11:12 by Jens Willy Johannsen
Categories: Projects | Tags:

As I explained in my last post I need to include an accelerometer calibration routine in the RGB Tumbler. But I don't want to add one or two buttons – it would take up way too much space on the PCB.
So I thought about how I could choose between "normal mode" and "calibration mode" without a keeping a button pressed on power-up and I came up with this:

On power-up, the MCU checks an EEPROM variable to see if it should go into calibration mode. If this variable is not set, the MCU sets the variable, waits one second and then clears the variable again. This means that if the user quickly (within one second) turns the device on and then immediately off, the EEPROM variable is set (because the MCU never gets to clear it before being turned off) and the next power-up will put the device into calibration mode.

For the calibration itself I will rely on delays instead of pushing a button on indicate that the device is in a new position (we need six positions for calibration). So I will flash the LED for a couple of seconds (four) and then take a reading and then repeat the process five more times. So when the LED flashes rapidly the user must change the device orientation and hold it still.
After all six readings have been taken the black magic-based calculations will be done (Gauss-Newton-based, actually but for me it amounts to the same thing) and the resulting calibration values will be stored in the EEPROM.

If this didn't make sense, then read the rest of the post to see flow charts attempting to explain the same thing.
Read the entire post »

Kommentarer 1 comment »

Accelerometer calibration

15. November 2011 10:55 by Jens Willy Johannsen
Categories: Projects | Tags:

I received a bunch of stuff yesterday – including the ADXL335 breakout board and immediately wired it up to see what kind of output I got. Everything worked nicely except the voltage on the X-axis was nearly 300 mV different from the Y-axis (!) when the accelerometer was lying flat on the table (and thus being subjected to 0 G on both X and Y). The Y- and Z-axes looked ok. Weird. And frustrating. Everything I've read about the ADXL335 (including the datasheet) led me to believe that at 0 G, the voltages on all three axes should be pretty much the same.

Anyway, after lots of Googling and scratching my head, I finally stumbled upon Rolfe Schmidt's blog where he has a lot of information about ADXL335 calibration. I don't pretend to understand the math behind Gauss-Newton algorithms but it worked perfectly!

The calibration values I got did indeed suggest that the X and Y axes were horribly miscalibrated. Maybe this particular unit is damaged – who knows. But I'll be sure to include a calibration routine in the MCU software.

No comments No comments »

Watchdog timer and idle mode

14. November 2011 11:44 by Jens Willy Johannsen
Categories: ATmega, Projects | Tags:

Since the RGB Tumbler will be running off a single coin cell I will need to make sure the ATmega microprocessor doesn't use a single microamp more than necessary. And there are several ways of doing that.

Firstly, let's switch off all peripherals that we won't be using. The "Power Reduction Register", or PRR, is the place for that (refer to section 9.11.3 of the datasheet). And also ACSR for disabling the analog comperator:
Read the entire post »

Kommentarer 1 comment »

LED Driver power dissipation

12. November 2011 13:43 by Jens Willy Johannsen
Categories: Projects | Tags:

Whenever we're dealing with more than a few miliamps we need to consider power dissipation. And for the LED Driver for the RGB Tumbler project I'm using three 50 mA LEDs connected to a SOIC-16 LED driver. That's at least 150 mA through a fairly small IC so let's look at the numbers.

The problem is always the temperature at the "junction" inside the IC. If this is too high, the IC will stop working. If it is much too high it will melt, burn or explode. And in most cases that is less than desirable.
Read the entire post »

No comments No comments »

RGB Tumbler parts

6. November 2011 22:54 by Jens Willy Johannsen
Categories: Projects | Tags: ,

This is what my parts search has yielded so far:

Power

The MCU, LED driver and accelerometer will be powered directly from a 3V coin cell. But for the blue and green LEDs, 3 volts is just not enough since the LEDs require 3.2V forward voltage and the LED driver requires a further 0.4V for the current regulator. So about 4V would be perfect. I've used the NCP1400 DC-DC converter before but it provides only 100 mA and since each LED draws 50 mA I will need more than that. The NCP1402, however, provides up to 200 mA. And even though it exists in a 4.0V version I've been unable to find that in stock anywhere so I'll probably go with a 5V version instead.
Note that with 5V I can't run multiple LEDs in series so I'll either have to make do with a single LED or use parallel LEDs.

LED

This one looks nice: Optek OVSTRGBB1CR8. It's an RGB LED with 50 mA per LED in a PLCC6 package. PLCC are pretty easy to hand-solder even though the leads are bent in under the device. Flux and a tinned tip will do the trick. And it has a generous 2.1 mm pitch.

MCU

I use AVR MCUs because that's what I'm familiar with. I will need three PWM channels and three A/D channels. This AVR Quick Reference gives a good overview of the features of the various ATtiny, mega and Xmega devices.

The ATtiny's have either not enough PWM or A/D channels or not enough pins to utilize both PWM and A/D at the same time or they only come in SOIC-14 packages (too big) or QFN-20 (don't wanna). The ATmega168 and -328 however have enough PWM and A/D channels and plenty pins to use both at the same time and come in a TQFP-32 package. And I already have a couple of TQFP '328s laying around so an ATmega 328P-AU it is.

LED Driver

This one was tricky. First off: do I even need an LED driver? Driving the LEDs directly from the MCU ports is not possible because the MCU cannot supply enough current for three 50 mA LEDs (and the MCU is running at too low a voltage in this case). I could have the MCU drive MOSFETs and use current-limiting resistors. But that would waste too much power in the resistors and the whole thing would eat up quite a bit of PCB real estate. So yes: I need a driver.

I spent several hours looking at and dismissing LED drivers because they were BGA or LGA package only or they were for low-current LEDs only (10 or 25 mA) or they had no current regulation at all. This one looked promising: ON Semi NCP5623. It's an I2C controlled three channel 175 mA controller in a TSSOP package. I don't even need to use PWM from the MCU. However, I only found it at Digi-Key where it was "non-stocked" with a minimum quantity of 2500 pcs. I don't think so.

I finally settled on this one: On Semi CAT4109. It doesn't inlcude PWM controller so the MCU will have to do the PWM'ing. Also it needs three resistors instead of only one for setting the current and it exists only in a SOIC-16 package which is kinda bulky. But it will have to do.

Accelerometer

For the last critical part I settled on an Analog Devices ADXL335. It is +/- 3G with three analog outputs. The only problem is that it is in a LFCSP-16 package which is intended for reflow soldering only. It may have visible connections on the side of the package. I hope it does because then it should be possible to hand-solder it. I will make sure the pads extend 0.5 to 1 mm beyond the case itself so I can flux-and-tinned-tip solder it. I'll keep my fingers crossed and we'll see. Note that the chip has a pad on the bottom (which is impossible to hand-solder) but according to the datasheet, the "exposed pad is not internally connected but should be soldered for mechanical integrity". Which means that I should be able to get away with not soldering it.

 

No comments No comments »

RGB Tumbler

5. November 2011 19:40 by Jens Willy Johannsen
Categories: Projects | Tags: , ,

For a new project I thought I'd like to do some RGB LED stuff. And I got the idea of making a small circuit (small enough to be put inside a ping-pong ball) that controlled one (or more) RGB LEDs from its physical orientation. Simply put, acceleration on the X, Y and Z axes would translate to intensity of the red, green and blue LED. And since there is always an acceleration of 1G towards the center of the Earth (also known as "gravity"), the color of the RGB LED would depend on its orientation.

So the system will comprise the following "blocks":

  1. Power
  2. MCU
  3. 3 axis accelerometer
  4. LED driver. Or maybe the LEDs can be controlled directly from the MCU.
  5. RGB LED. One or two.

When looking for parts there's a few things to keep in mind:

  1. Size matters. It must be as small as possible. I only recently started working with SMD components but already I can't imagine having to deal with those clunky, Soviet tractor-like through-hole components. But I still haven't gone all the way into reflow soldering. So I'm looking for primarily SOIC, TSSOP and TQFP packages. QFN packages are actually possible to hand-solder but it's not fun at all and LGA and BGA are pretty much impossible. For many-pin devices, SOIC is actually kinda big with their huge 1.27 mm pitch and 0.5 mm pitch TSSOP would be preferable.
  2. Power. As little as possible. I plan on running everything off a single 3V coin cell so voltage should be 2.7 to 3 volts and amps should be as few as at all possible.
  3. Availability. I much prefer to be able to get everything from one, local provider.

So off to the intertubes for some Googling…

Comments 2 comments »

Airsoft Rounds Counter follow-up

1. November 2011 22:07 by Jens Willy Johannsen
Categories: Projects | Tags:
So here is the looong overdue follow-up of my Airsoft Rounds Counter project. Sorry for the incredible long wait…

Ok. Everything has been assembled and mounted. I mounted the control unit inside the stock. Power comes from the gun battery. The wires from the photo interrupter to the control unit run inside the handguard and upper receiver. I have drilled through the aluminium endblocks of the handguard and I'm using three pin RC servo type plugs and sockets to connect the silencer with the IR photo transistor and LED to the gun (I need to unplug it in order to unscrew it) and also inside the stock so I can easily disassemble the gun.

And it works pretty darn good, actually!

Comments 2 comments »

High-power LED driver

10. June 2011 10:09 by Jens Willy Johannsen
Categories: PCB

For the airsoft flag device project I have been working with normal or semi-high-powered LEDs. And they just weren't bright enough so I had to step it up to proper 1W or 3W LEDs.

However, that required me to change the circuits since it's not a good idea to drive a 1W LED with a series resistor since way too much power will get wasted in the resistor. The correct way of driving high-power LEDs is with a dedicated constant current circuit.

So I decided to make a small board with just the driver circuit and external leads for power, GND and LED control as well as leads for the LED itself.

Of all the many ways of making a constant current regulator, I decided to go with the ZXLD1350 IC for reasons I can't remember.

Here are links to the datasheets:
ZXLD1350
ELL5PS SMD inductor
ZLLS1000 SMD Schottky diode

Schematic:
Board:
EAGLE files: Eagle files

Terms of use: Yeah sure, go ahead. No guarantees, obviously.

Comments 3 comments »

Board assembled

6. January 2011 13:38 by Jens Willy Johannsen
Categories: PCB, Projects | Tags: ,

I have received the PCBs and assembled the first one. Everything expect connections to external components, that is.

Here's a picture. It looks pretty much like the rendering. And I know: some of the soldering joints could have been made better but bear in mind that this is my first SMD soldering attempt so I'm actually pretty pleased with the result.

PCB with all SMD components (click for larger version)

Comments 6 comments »

Eagle3D layout

20. December 2010 21:38 by Jens Willy Johannsen
Categories: PCB, Projects | Tags: ,

Here is a 3D model of the board created with Eagle3D (here's a tutorial and here's some information about getting it to work on Mac OS X):

Eagle3D model of the Airsoft Rounds Counter PCB (click for larger version)

Comments 3 comments »

Firmware complete

16. December 2010 12:47 by Jens Willy Johannsen
Categories: Projects | Tags: , , ,

Pretty much at least. I've added an EEPROM variable for storing the magazine capacity and I've added support for programming the magazine capacity and for resetting the rounds remaining counter without turning off the entire device.

The device can be in two modes: run and program. Run is the normal count-down-when-a-round-is-fired mode and the PRG/RST button will reset the counter (for when you put in a fresh magazine).
To enter program mode, press the PRG/RST switch while powering on the device. The display will show "PrG" for a second (as opposed to "run" in run mode) and then the counter will show 000. Pressing the PRG/RST button will increase the counter which is the magazine capacity. If the PRG/RST button is held down for a second, the counter will increase quickly. The capacity is saved in EEPROM every time is it increased so simply turn off and back on the device to use the new capacity.

Download the code here: firmware_rev2

Points of note:

  • Both the photo interrupter and the reset switch work as external interrupts (INT0 and INT1, respectively)
  • In programming mode, a 1 second timer compare match interrupt is used for hold-to-count-quickly
  • Magazine capacity is stored in EEPROM
No comments No comments »

Final layout?

12. December 2010 12:19 by Jens Willy Johannsen
Categories: ATtiny, PCB, Projects | Tags: ,

Schematic and layout revised again. I added the 10 µF capacitor (that really ought to be there) and a LED with accompanying resistor for debugging purposes.

Here a print-it-out-and-see-if-it-fits test. And it does fit. Note that all the resistors are the same value (doesn't matter of course since all 1206 resistors are the same size) and that I've placed a 1206 resistor instead of a 1206 LED. Also, the B sized 10 µF capacitor isn't placed on the printout but it shouldn't pose any problems.

Layout, revision 3 printed 1-to-1 with components (click for larger version)

No comments No comments »

Soldering SMT components

11. December 2010 15:59 by Jens Willy Johannsen
Categories: PCB | Tags:

Until now I have only made through-hole circuits.But the Airsoft Rounds Counter project's demand for a small PCB made me decide to use SMT. The components are a lot smaller so you can fit a lot more onto a small board but they are more difficult to solder by hand. (But easier and faster to assemble automatically. And cheaper.)

So I have to practise my SMT soldering. Fortunately there are a couple of great tutorials on the net. I used these:

And it's actually not that hard. I have – so far – had much success with flux-pen-and-solder-on-the-tip-of-the-iron method. A flux pen if your friend – trust me.

Here's an example of my handiwork (the ting at the top is a millimeter scale ruler):

One of the first attempts: a 1206 resistor

The resistor in the image above is a fairly large SMD component: a 1206 sized resistor. The smallest I will be using to begin with are 0805 sized capacitors and SO-20 and -24 ICs. You can see the various SMD sizes here:

Image from fpga4fun.com: SMD sizes (click for larger version)

(Note: SMD means "surface-mount devices" and SMT means "surface-mount technology". I use the terms pretty much interchangeably. Which is wrong. I know.)

No comments No comments »

Schematic Revised

10. December 2010 22:05 by Jens Willy Johannsen
Categories: Projects | Tags:

And a new and revised schematic for the Airsoft Rounds Counter. The only difference is that the photo interrupter's collector wire is now connected to the ATTiny's INT0 pin.

Schematic, revision 2 (click for larger version)

Update: obviously I mean "to digit cathodes" and "to segment anodes" – not the other way around.

No comments No comments »

PCB Layout Revised

10. December 2010 21:55 by Jens Willy Johannsen
Categories: PCB, Projects | Tags: ,

Oops. The photo interrupter's collector wire wasn't connected to INT0 on the ATTiny. That has been fixed now. Also, the board is now 1 mm wider so there is enough clearing from the segment A wirepad to the edge of the board.

And the VCC and GND traces are now 24 mils and all other traces are 12 mils wide. Refer to the first layout if you can't remember what the various wirepads are for.

SMD layout, revision 2 (click for larger version)

No comments No comments »

Breadboard Prototype

10. December 2010 21:46 by Jens Willy Johannsen
Categories: Projects | Tags: ,

Here are a couple of pictures of the breadboard setup:

The first picture is of the breadboard itself. The components are marked and the green dots are where the wires from the photointerrupter go.

Breadboard (click for larger, more legible version)

The second pictures includes the photo interrupter mounted to the barrel using duct tape (what else). Note that this was before the Max7219 and display was mounted:

Breadboard and business end of airsoft gun (click for larger version)

Comments 2 comments »

SMD layout

10. December 2010 0:53 by Jens Willy Johannsen
Categories: PCB, Projects | Tags: ,

Here's the first draft of an SMD PCB layout for the Airsoft Rounds Counter project.

The wire pads are as follows:

  • VIN
    9V power input
  • AN, CA
    Anode and cathode the the photo interrupter LED
  • CO, EM
    Collector and emitter for the photo interrupter transistor
  • A-G, DP
    Segment anodes on the display
  • 1-4
    Digit cathodes on the display
  • RST/PRG SW
    Reset and program tact switch

Actual size is 49.53 x 20.32 mm.

SMD layout

SMD layout (click for larger version)

Kommentarer 1 comment »

Firmware for Airsoft Rounds Counter

9. December 2010 12:05 by Jens Willy Johannsen
Categories: Projects | Tags:

Here is version 1 of the firmware for the Airsoft Rounds Counter project. The code uses avr-gcc but should be real easy to port if you use a different compiler.
This firmware is by no means the final version. Rather, it is the firmware for the breadboarded version (the schematic is here).

The ZIP archive contains three files:

  1. main.c
    Contains all the code. Please note that the code assumes that a LED is connected to PB4 which is not shown in the schematic. This is purely for debugging purposes and you can add the LED or not. The code doesn't care. And neither do I.
  2. Max7219.h
    Header file with definitions for the various Max7219 commands.
  3. Makefile
    Standard makefile. Do a 'make all' to compile, 'make fuse' to set fuses (they are set to internal 8 MHz RC oscillator with slow startup, no BOD, SPI enabled), 'make flash' to flash the ATTiny and 'make clean' to delete the binaries.

Download the ZIP archive here: firmware.zip

Comments 4 comments »

Prototype

8. December 2010 11:06 by Jens Willy Johannsen
Categories: ATtiny, Projects | Tags:

I have the first prototype of the Airsoft Rounds Counter up and running on a breadboard.
Here is the schematic. A couple of notes:

  • A 10 µF capacitor or so near the power supply certainly wouldn't hurt. Neither would a diode on the input side of the 7805.
  • The "program and reset" switch doesn't do anything with the current code and can be omitted for this version.
  • On the breadboard I also have a tact switch from the ATTiny's RESET pin to ground so I can reset the counter.
  • I'm using a 9V battery for power.

Schematic – click to view large version

Comments 3 comments »

SPI and USI

6. December 2010 13:36 by Jens Willy Johannsen
Categories: ATtiny | Tags: , ,

The Max 7219 chip communicates using SPI. The last time I used it I had apparently written my own bit-banging SPI routine in the Arduino IDE. Which works just fine (the SPI protocol being so simple) but it seems clunky. And since the ATTiny2313 has a built-in USI (Universal Serial Interface) capable of doing SPI I thought I might as well use that.

After a bit of Googling and reading of the datasheet, this is what I came up with:

#define PIN_LOAD PB4

// Utitlity method to shift 8 bits out the USI pins in 3-wire (SPI) mode
static unsigned char spiByte(unsigned char val) 
{ 
    USIDR = val;            // Set data byte to send
    USISR = (1<<USIOIF);    // Clear Counter Overflow Interrupt Flag (by writing 1 to the USIOIF bit)
    do
    { 
        USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);    // 3-wire mode; shift reg. clock source: external pos. edge; 4-bit counter source: USITC; Toggle USICK pin 0->1 or 1->0 (shift register will only clock on 0->1)
    } while ((USISR & (1<<USIOIF)) == 0);                        // Check for OIF set which will happen after 16 cycles. I.e. 8 bits since the clock toggles twice per bit.
    return USIDR;            // Return data value
}

void sendToMax7219( char reg, char value )
{
    PORTB &= ~(1 << PIN_LOAD);    // LOAD low
    spiByte( reg );
    spiByte( value );
    PORTB |= (1<<PIN_LOAD;    // LOAD high
}
No comments No comments »

Photo interrupters

6. December 2010 11:22 by Jens Willy Johannsen
Categories: General | Tags: ,

For the Airsoft Round Counter project I need some way of detecting when a round is fired and (like most people suggest) a photo interrupter is ideal for the purpose.

Basically, a photo interrupter consists of an LED (usually an IR one) and a photo transistor. A photo transistor works like a normal transistor but instead of a current at the base, it requires light to turn on the collector-emitter current flow. In a photo interrupter the LED and the photo transistor are mounted in small posts and when nothing interrupts the beam, the transistor turns on, passing a current from the collector to the emitter. When the beam is interrupted, the transistor turns off.

A photo interrupter has four leads or connectors: anode and cathode for the LED and collector and emitter for the photo transistor.

To use it in as a digital input for a microprocessor, you can create a circuit like this:

Photo interrupter circuit for digital logic

R1 limits the current to the LED (using the normal LED calculations having obtained information about the LED forward voltage and desired current from the datasheet – typically something like 2.0V and 20 mA).
When the photo interrupter is not interrupted, the input reads 0. When an object blocks the beam, the input reads 1.

This document from Lite-On has some excellent information about using photo interrupters (after the list of their products).

No comments No comments »

Airsoft Rounds Counter

6. December 2010 10:02 by Jens Willy Johannsen
Categories: ATtiny, Projects | Tags:

Browsing around on AVRfreaks' forum I stumbled upon this thread about an Airsoft Round Counter to display the number of remaining rounds when playing airsoft. This is obviously a cool idea and the thread inspired me to want to make one myself.

In the thread people discussed using everything from a simple switch attached to the trigger over photo interrupters and photo reflectors to accelerometers for detecting when a shot is fired. There is also a link to this page on the Design Decisions Wiki where a group of people have designed an "Airsoft Electronic Ammunition Counter" with detailed design considerations and requirement analysis and timing calculations. Excellent work and a great source of inspiration for this project.

My initial considerations for this project:

  1. Enclosure. Everything should be mounted to an airsoft gun and it shouldn't be the size of a shoe box!
  2. Component count. This ties in with number 1 above: if this is to be small enough to be portable I have to keep the component count down so the final PCB is of a manageable size. (Yeah yeah, "use SMD". Right, I'll do that in phase 2.)
  3. Ease of use. This will be used in skirmishes so it should be real easy to use. No re-flashing of the processor to change settings, easy to attach to a weapon and so on.

So far I have settled on the following basic components:

  1. ATTiny 2313-20PU. I could probably get by with a smaller ATTiny but since I already had a couple of these lying around I went with those...
  2. Four-digit 7 segment display
  3. Maxim 7219 CNG display driver.
  4. Wide-gap photo interrupter

Off to EAGLE for some schematic drawing and thence to the breadboard for figuring out how photo interrupters actually work...

No comments No comments »

Learning from your mistakes

15. September 2010 11:43 by Jens Willy Johannsen
Categories: PCB

In electronics as in everyting else, the more you mess up the more you learn (hopefully). With that in mind I figured, "what the hell, let's give it a go" and I sent an order to Micron 20 .

It is a pretty simple PCB for an ATmega168 (or -328) with voltage regulator, pull-up resistor for the reset pin, a crystal with associated load caps and a 3mm led with resistor.

The order specifications are as follows:

  • Single-sided
  • 6.9 x 2.8mm (2700 x 1100 mils)
  • Solder mask (blue) on both sides
  • Silkscreen (yellow) on top

Minimum PCB size is 0.7 dm2 (square decimeters?! Why would anyone ever use square decimeters as a unit?) so I will received 4 boards.
I chose to have the boards done in 7 work days (you can choose between 24 hours to 15 days) and airmail delivery and the grand total was €66.

Now, we'll see what kind of mistakes I have made :)

It looks like this:

(click to see larger image)

No comments No comments »

Learning PCB layout

15. September 2010 0:17 by Jens Willy Johannsen
Categories: PCB

So far I've only been concerned with designing circuit schematics. That is, an illustration of how the various components are connected to each other but which not necessarily have any correspondance with how the actual, physical components are placed on a board. I have been using the free version of CadSoft's EAGLE which is very capable and has all the features I will need for the forseeable future. And it runs on Mac OS X (as well as Windows and Linux). It does have kind of a weird user interface but you get used to that.

EAGLE has both a schematic editor and a PCB layout editor and until recently I had never spent more than five minutes looking at the PCB layout editor so I had some learning to do. This tutorial from SparkFun and this PDF helped a lot. As did this list of layers from PCB-Pool.

Three more things I learned:

  1. Choose the right components when making the schematic - or later.
    It quickly turned out that I had to go back and spend some more time in the schematic editor. Because up until now I just chose components without much regard for the "footprint" – i.e. size and shape. I didn't care exactly what resistor I was using as long as it had the right symbol and I could specify name and value.
    But for PCB layout you really need to know whether there are 0.1 or 0.2 inches between the capacitor leads, for example.
    So choose the right components when you make the schematic OR just drop in some components and then go back and change them when you starting working on the PCB layout.
    Yes, I know that most engineer types out there will yell stuff about always choosing the correct component to begin with. But honestly, when I make the schematic I have no idea whether a given resistor will be 10 mm or 8 mm long. And I don't want to spend time thinking about at that time. So there!
  2. Make your own or adjust the packages
    For some components I needed to change some details on the footprint. For the polarized capacitor I would like a square pad for the positive lead and for the 7805 volt reg I wanted to remove a lot of unnecessary silk screen print. This tutorial from SparkFun is helpful (http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=110).
    As is knowing how to copy everything from an existing package. Here's how:
    1) to identify the package and the library it's part of, choose the info tool and click on the part
    2) open the library and edit the existing package
    3) click the layers tool and show all layers
    4) choose the group tool and select everything
    5) click the cut tool (the scissor) – yes: cut. It will actually copy and not cut.
    6) open or create the new package
    7) click the paste tool (next to the cut tool)
    And then you can add or remove stuff and save the package. Then edit the part, add a new package and connect pins and pads and then replace the old part with the new variant in the schematic editor (And choose Library -> Update all).
  3. Print and check
    Print out a copy of the board in actual size by choosing File -> Print… and setting the scale factor to 1.
    Then place all the components on the paper (push the pins through if possible) and make sure everything fits and the footprints are correct. I caught several mistakes by doing this...
No comments No comments »

The next step

10. September 2010 15:46 by Jens Willy Johannsen
Categories: PCB

Having made a couple of prototype-like projects I thought it would be nice to put the projects on proper made-for-the-purpose circuit boards. So far I've been using these boards and they have worked very well: the size is perfect for an ATmega168 with support components (like a 7805 volt reg and a couple of capacitors) and they are laid out like a breadboard.

However, I'm running out of space for components on those boards and using single-pad proto boards seems kind of kludgy.

So I began looking into making my own PCBs. But all that stuff with printing and ironing and splashing around with acids and whatnot just looks like too much hassle.

So if I don't want to make my own, I guess I'll have to buy them. It might be a bit more expensive but they will look soo much cooler with solder mask and silkscreen and stuff.

After a couple of hours of Googling I ended up confused on higher level. It turns out that there are lots and lots of companies making PCBs to order but specifications, requirements, prices, minimum quantities etc. vary wildly. My requirements are:

  • Simple boards: typically only one copper layer and (for the time being) no small SMD components so layout isn't too complex.
  • Small quantities: like one or two or six boards at a time.
  • No hurry: I can wait a couple of weeks.
  • Price: I don't want to spend too much money on something that is just for fun (actually, that's probably too late but still...)
  • No hassle: by which I mainly mean import tax and VAT.
  • Solder mask: I'd like a solder mask (http://en.wikipedia.org/wiki/Solder_mask) to help protect from shorts and to avoid having to tin all copper traces to prevent corrosion of the copper (not strictly necessary). Also, it look cool.
  • Silkscreen: Not strictly a requirement but it would be nice to have outlines and labels silkscreened unto the board. And again: it looks cool.

Two providers I'm currently looking at are:

Micron20 / PCB Boards in Bulgaria which is very cheap and
PCB Pool in Germany which is a bit more expensive but looks more professional.

Both are in the EU so there's no import tax and VAT, both accept designs in EAGLE .BRD files (EAGLE is the schematic and layout program I use), and both are able to deliver single and double-sided boards with solder mask and silkscreen in small quantities for a reasonable price.

(original image by Henry Herndon)

No comments No comments »

Choosing the correct MOSFET

10. September 2010 14:54 by Jens Willy Johannsen
Categories: Projects | Tags: ,

I just found out I forgot to post this article about choosing the right MOSFET for the autogun project. Here it is:

When switching on the gun, we're passing a significant amount of current through the MOSFET.
As shown on the power test tables in this posting, we should expect a peak of 50 Amps and a sustained current of about 20 Amps.
So the MOSFET should be able to handle at least 15V and 60A. And since we are turning on the MOSFET from the MCU control circuitry at 5V the gate threshold should be low enough for the MOSFET to turn fully on at 5V. In practice this means a logic-level MOSFET.

The datasheets of MOSFETs will list a whole bucketful of specifications. Some of the important ones are:

VDSS maximum drain-source voltage. In my case, it should be at least 15V
ID maximum drain current. In my case, it should be at least 60A to be safe. (Although the *sustained* current will only be 20A.)
Be careful with this one. Often it will be specified as one value "silicon-limited" and another - lower one - as "package-limited". This means the chip itself can handle a high current but the casing might melt or burst into flames. Which is bad. So use the lower one.
Also, it might be specified as one value "@ 25 °C" and another - again, lower - "@ 110 °C". Again, use the lower one since it is highly unlikely that the MOSFET will be at 25 °C when we are pulling 20A through it.
PD maximum power dissipated in the MOSFET. This is calculated as RDS(on) * I^2.
VGS(th) gate threshold voltage. This is a measure of how much voltage on the gate is required to turn the MOSFET on. As mentioned, since we're dealing with logic-level voltages, it should be no more than 2.5V
RDS(on) drain-source resistance when fully on. This will determine how much power is dissipated in the MOSFET's junction.
Since all the power dissipated in the MOSFET junction is converted into heat we need to check how fast we can get rid of that heat. Otherwise, the MOSFET will heat up and eventually break. And possibly (albeit not likely) melt and/or burst spectacularly into flames. Therefore, we will also take a good, long look at the following:
RΘJ-A thermal resistance between junction and ambient. This is a measure of how much power can be dissipated as heat from the junction to the surrounding air without any help.
RΘJ-C thermal resistance between junction and case. We might need this if we need a heatsink. In that case we need to add this with the thermal resistance of the heatsink (RΘHS) and check if we are below the max allowable thermal resistance.
TJ maximum operating temperature for the junction. We need this to check if enough heat is dissipated.

Browsing through dozens of MOSFETs, this one looked promising: IRL1404PbF. It is listed as a "N-LogL 40V 160A 200W 0,004R TO220AB" MOSFET.
(Which means "N-channel, logic-level, VDSS=40V, ID=160A, PD=200W, RDS(on)=0,004Ω in a TO-220 package".)
It looks good because:

  1. it is logic-level activated
  2. it can handle 15V
  3. it can handle 60A
  4. it has a low RDS(on) which means that the PD will be low (PD = RDS(on) * I^2 = 0,004Ω * 20A^2 = 1,6W) which means that we just might be able to get by without a heatsink

To check if we can dissipate the heat fast enough, we need to calculate how hot the junction becomes under load by using the following formula (Tamb is the max operating ambient temperature. in Denmark the temperature is never above 35 so that should be a safe value):

Tj  = PD * RΘJ-A + Tamb
    = RDS(on) * I^2 * RΘJ-A + Tamb
    = 0,004Ω * 20A^2 * RΘJ-A + Tamb
    = 1.6W * 62 °C/W + 35 °C
    = 99,2 °C + 35 °C
    = 134,2 °C

Perform this calculation with your own values with this Instacalc calculator.

The result is below the specified 175 °C.
(If, however, we were to run 25A continous current through, we would end up with a junction temp of 190 °C (do the math yourself) which is too high.)

As you can see the current rating for a MOSFET should be taken with a grain of sand. The IRL1404 MOSFET is rated to 160A. But without a heatsink it can't even handle 25A continously.

Bonus reading: choosing a heatsink

If we ended up with a too high temperature, we would need to mount a heatsink to the MOSFET in order to lower the thermal resistance.
In that case, instead of using RΘJ-A for thermal resistance, which is junction-to-ambient air resistance, we would use the combined thermal resistance by adding the following:

J-C junction-to-casing (0,75 °C/W for the IRL1404)
C-S casing-to-heatsink (0,5 °C/W for a "flat, greased surface" and typically between 0,5 and 1,5 depending on whether you use thermal grease, mica or bolt it directly on)
HS heatsink-to-ambient (depending on the heatsink)

We can calculate the maximum thermal resistance that will dissipate the heat from the junction fast enough by using the above formula (transposed a bit):

maxRΘJ-A = (Tj-Tamb)/PD
          = (175-35)/PD
          = 140°C / RDS(on)*ID^2
          = 140°C / 0,004Ω * 20 A ^2
          = 140°C / 0,004Ω * 400 A^2
          = 140°C / 1.6W
          = 87.5 °C/W

In this case the max thermal resistance of the junction-ambient without heatsink is lower than that (per the datasheet it is 62 °C/W) so we don't need a heatsink, but if we calculated it for a 25A sustained current we would end up with a max thermal resistance of 56 °C/W and since the j-c plus c-s is about 2 °C/W (if we don't use thermal grease) we would need a heatsink with a maximum RΘ of 54 °C/W. Like this little one here which has a thermal resistance at normal airflow (as opposed to "forced", i.e. fan ventilated) of 16,2 °C/W.

*whew*

Links:
A lot about thermal resistance and heatsinks: http://www.jaycar.com.au/images_uploaded/heatsink.pdf
About choosing a MOSFET and explanation of the MOSFET's parameters: http://robots.freehostia.com/SpeedControl/MosfetBody.html

Comments 2 comments »

Success!

16. July 2010 13:36 by Jens Willy Johannsen
Categories: Arduino, Telit GE865 | Tags:

I connected everything – that is: battery, SIM card, push button, LED and transistor and level shifting for 2.8V <-> 5V logic. And considering how much trouble people seem to have had I was surprised how quickly it worked!

The only two things I ran into was:

  1. The first SIM card I used didn't want to talk to the GE865. Probably because it is for a 3G modem and not a phone. Anyway, the second (normal) SIM card worked perfectly.
  2. Using the Arduino IDE's serial monitor as terminal interface didn't really work. But using "screen /dev/tty.usbserial-A9007ND2 9600" from the Terminal prompt worked flawlessly.

I had zero problems with the power supply. Even though I'm not using the recommended low ESR capacitor. Maybe because I'm in a densly cell-phone-covered area. Or maybe because the battery is capable of delivering up to 2A by itself.

And everything worked: sending and receiving SMS'es, retrieving a web page using GPRS. Nice! Now I just need to connect it to a DTMF decoder and a Speakjet :-)

Here's a picture of the breadboard setup:

(click to view large version)

No comments No comments »