Eagle and Gerber Files (easier!)

Monday, February 6th, 2006

I’ve been doing a little more experimentation with EAGLE and the included .cam files. I found that these should be more than sufficient for my needs (two-layer PCB, top and bottom soldermask, top and bottom solder stop and top silkscreen.) I just processed the ger274x.cam and the excellon.cam job files, uploaded my design to FreeDFM and they recognized all of the file contents. FreeDFM will analyze your design and correct or suggest fixes before you submit it for production.

To run these .cam job files:

  1. open up your .brd file, then
  2. from the menu: File -> CAM Proecessor (a new window will popup)
  3. from the menu: Select File -> Open -> Job…
  4. EAGLE should already be showing the contents of the ./cam directory under the main directory where EAGLE is installed, if not, navigate to it. Choose the gerb274x.cam file
  5. (Click through the tabs and make sure “mirrored” is not checked! I made the mistake of submitting the files with the top layers as normal and the bottom layers as “mirrored” and the boards came back wrong.
  6. Click on the Process Job button
  7. from the menu: Select File -> Open -> Job…
  8. Choose the excellon.cam file (make sure “mirrored” is not checked)
  9. Click on the Process Job button

List of files created from the two jobs:

  • combined3.plc – top silkscreen
  • combined3.cmp – component side copper (top side)
  • combined3.sol – solder side traces (bottom side)
  • combined3.stc – top soldermask
  • combined3.sts – bottom soldermask
  • combined3.gpi – Photoplotter info file
  • combined3.drd – NC drill file
  • combined3.dri – Drill station info file

You should download GC Prevue from www.graphicode.com. This is for Windows only. After you install, run the program and from the menu “import” all of the files that you generated above. You should see all the layers and the drill holes in the right place. (One way to make sure that your top and bottom layers are correct is to write text on the top and bottom traces layer…this way you know your GERBER files are right when you see the top layer text as normal, but the bottom layer text as reversed)

Here’s an article about the history of the Gerber PCB making process and the file format.

Eagle and Gerber Files

Tuesday, January 31st, 2006

Addendum:
We submitted the files to pcbexpress and they said that the .drl file was not the NC drill file. I had to run the excellon.cam job file to generate the .drd file.

Recently I had to use Eagle to adjust a colleague’s PCB layout. To install it on a Mac, first download and install X11. Next download Eagle from cadsoft and uncompress the file. You should now see a directory. Inside, there’s a readme.txt file that tells you to run a bunch of commands in the terminal so that you can use the ‘install’ script that’s in the directory…but immediately following these commands it says:

NOTE: the installation procedure described here is not mandatory.
You can just extract the TGZ archive to any location of your choice
and use it there directly. All the ‘install’ script does is to copy
the program and man-page to the default location and set up a
symbolic link to the executable in /usr/bin/eagle.

So, just copy the directory to your /Applications directory and you should be set.

Now (drumroll), in order to run Eagle you first have to start the X11 server. After X11 is up and running, double-click on the ‘eagle’ file in the ./bin directory in Eagle’s main directory. That’s it.

After creating your schematic and pcb layout, you need to generate the appropriate files to submit to a PCB manufacturer. Most of these places will require Gerber files. I’m submitting my designs to PCBexpress and I found these easy to follow directions on their site…to generate Gerber files from Eagle, download these .cam job files and follow these instructions.
These .cam files will generate the appropriate Gerber files for you to submit. For a two layer PCB (traces on top and bottom), you’ll use E1.cam or E2.cam. Here are the files that are commonly generated with the .cam files downloaded from pcbexpress:

.bot – bottom traces
.top – top traces
.bsk – bottom silkscreen
.slk – top silkscreen
.smb – bottom solder mask
.smt – top solder mask
.drl – drill tool file

Happy PCB designing! There’s something satisfying about laying out component and solving the puzzle of connecting them together without crossing wires. :)

DIY USB Charger

Friday, January 20th, 2006

Rachel wanted an external charger to charge up her iPod nano but Apple sells iPod one for $30! I wanted to see if I can cook something with the stuff in my miscellaneous electronics closet.

Disclaimer: This info is provided with no guarantees. If you don’t know what you’re doing, do not try to put this together.

I found a 5V (1A) power supply that I purchased to use for microcontroller projects. I bought it from allelectronics (part number: PS-513) and it was only $4.50.
usb_charger3

I didn’t have a female USB plug, so I bought a USB extension cable from Target for $8.
usb_charger5

You’ll also need a multimeter, a soldering iron and some heat shrink, 1/4″ diameter. (You can use electrical tape, too.)

  1. Cut the male phone connector off of the power supply. Remove an inch or so of the the outer insulation and you should see four wires. Red/Black => +5 and Yellow/White => GND. Strip the Red and White wires. I plugged in the power supply and the voltage measure 5.2V. The USB specs indicate that USB hubs will supply voltages in the range of 4.4V to 5.25V (more specifically 4.7V to 5.25 V for High power devices and 4.4V to 5.25V for Low power devices.)
    usb_charger0
  2. Cut the USB extension cable. I just cut my 6′ cable in half. One should haver the male connector and the other should have the female connector. We’re going to use the half that has the female connector. Remove some of the insulation, the metal foil, and shield, from the cut end and you’ll see four wires. Red is +5 and Black is GND.
  3. Now, connect (just twist together for now):
    • Red (power supply) to Red (USB cable)
    • White (power supply) to Black (USB cable)

    usb_charger6

  4. You can do a little test before plugging in a real device. Take the other section of the cut USB cable (the one with the male connector) remove the insulation, and strip the red and black wires. Plug the male USB connector into the female USB connector. Plug the power supply into the wall. Take a voltage reading from the red and black wires you just stripped. If you see +5V then you’re set! If you see -5V then you’ve misconnected the wires between the power supply and the USB cable(w/ female connector)

Now you’re ready to plug in your USB device. I have a “broken” mobiblu MP3 player. It doesn’t play music anymore, but it still responds to charging. I plugged my power supply into the wall. I plugged my mobiblu into the female connector of my homemade charger…and voila the mobiblu shows that it’s charging from a charger! If you don’t have a device that you can test on, make sure that you check all the voltages before plugging in something expensive…like your iPod. If you have a USB light or something try that first.
usb_charger7

So now all you have to do is tidy up your work by soldering the connections you made and heat shrink (or tape up) the section of exposed cable and you’re project is complete.
solder and heatshrink

You can do this with any regulated 5V power supply. There are lots of places you can get them. Jameco has them.

Some more info on USB specs
(including pinouts and voltage specs).

Good Luck!

PIC Timer Interrupts

Friday, October 14th, 2005

Here’s a very basic program to use TMR0 and an interrupt for TMR0 to do something every second.
I’m using a 4Mhz clock.

We are setting up the PIC so that everytime TMR0 reaches it’s max value(this is configurable), a Timer Interrupt occurs.

----------------------------------------------------------------------------------------

'Works w/ 18Fxx2 - James Tu 06/01/2004

'This program sets up a TMR0 interrupt
'The interrupt happens every 1 sec!
'I timed it...it's pretty precise

'It changes the state of an LED every second.

led var PORTB.4
ledstate VAR BIT

ledstate = 1

INTCON2.7 = 0 'Enable PORTB pullups...18Fxx2

'setup TIMER0
'set the high and low bytes of TMR0...
'we'll be using it in 16-bit mode
'This is equal to 65535 - 62500 = 3035...
'Calculated to give us 1 sec interrupts with 1:16 prescalar
TMR0H = $0B
TMR0L = $DB

'Enables TMR0, set to 16-bit
'Enable Pre-scalar
'Set prescalar value 1:16
T0CON = %10000011

On Interrupt Goto myint ' Define interrupt handler
'Enable Timer0 Interrupt
'Turn on INTCON.7(GIE) and INTCON.5 (TMR0IE)
INTCON = %10100000

TRISB.4 = 0

loop:

led = ledstate

Goto loop ' Do it forever

' Interrupt Service Routine
Disable ' No interrupts past this point
myint:
if ledstate == 1 THEN
ledstate = 0
ELSE
ledstate = 1
ENDIF
INTCON.2 = 0 ' Clear TMR0 interrupt flag
TMR0H = $0B ' put 3035 in TMR0 for 1 sec interrupts
TMR0L = $DB
Resume ' Return to main program
Enable

----------------------------------------------------------------------------------------

Instead of changing the state of the LED, you can increment a variable…If have you have a variable called
SECONDS, you can add 1 to SECONDS when this timer interrupt occurs. This will allow you to keep time…for time event driven processing.

TMR0 can hold a 16-bit value or an 8-bit value
TMR0 has a pre-scalar that can be set to either 2,4,8,16,32,64,128, or 256.
(What the pre-scalar do is that it slows down the counting of TMR0. If the pre-scalar is set to 32, TMR0 increments by 1 every 32 PIC clock “ticks”)

Here’s the math…

  • 4Mhz crystal means an internal clock of 1Mhz
  • 1Mhz means there’s an internal clock “tick” every .000001 sec.
  • TMR0 can hold either a 16-bit(65536) or an 8-bit(256) value…I chose 16 (therefore TMR0 can count from 0 to 65535)
  • If we just left it like this, TMR0 counts from 0 to 65535 and the TMR0 Interrupt will happen every 0.065536 sec (65536 * 0.000001) .
  • We want TMR0 to interrupt every 1 sec.
  • If we set the pre-scalar to 16, TMR0 will interrupt every…0.065536 * 16 = 1.048576 sec…pretty close to 1 sec.
    • If you want you can leave it at this. If you want really precise timing, you have to do the following…you have to fill TMR0 with a starting value.(TMR0 is just a register so you can set it to any value.)
    • We want the solution to the equation:
      • value * 0.000001 * pre-scalar = 1.0 sec
      • value = 1.0/(0.000001 * 16) = 62500
    • So we want TMR0 to count 62500 not 65536. What we can do is to set TMR0 to 65535-62500 = 3035. So it actually counts from 3035 to 65535 which is 62500! We do this at the beginning of the program and every time an interrupt happens.
    • TMR0 is a 16-bit register in my example, so we have to write two bytes…one is written to TMR0H (high byte) and TMR0L (low byte).

That’s it!

The table below shows the interrupt intervals you can expect from a 4Mhz clock, and a 16-bit TMR0.

prescalar 2 4 8 16 32 64 128 256
TMR0 INT happens every (sec) 0.131 0.262 0.524 1.05 2.09 4.19 8.38 16.77

“Open-collector”, “Open-drain” demystified

Friday, October 14th, 2005

You’ll come across the terms “open-collector” and “open-drain.” These are used sometimes to describe how a particular IC’s pins are implemented internally.

This and also this are good explanations of what those terms actually mean and why an IC’s pin would be designed as open-collector or open-drain.

Max232A RS-232 Driver/Receiver

Friday, October 14th, 2005

Maxim’s RS-232 level converters are sometimes necessary if a chip or a control board needs to communicate with the PC, especially if the specs for the chip/board indicates that it can only accept TTL/CMOS logic levels. The uControllers, the PIC and the BX-24, that we’ve been using are more tolerant of these voltage levels, so that’s why we can connect the TX/RX of the PC directly to these uControllers.

For situations where you need to shift the voltage levels so you can communicate with a PC(on the PC the voltage swings from +12 to -12 V), you’ll need the Max232A. This bumps up the voltage for serial communication TO the PC(because most chips/boards work on 0 to 5 volts) and lowers the voltage for serial communciations FROM the PC to a safer level for the chips/boards.)

If you are using the MAX232A, you’ll need five 0.1 uF capacitors. The datasheet has a connection diagram that shows 5 polarized capacitors. You can use non-polarized caps. I verified this with MAXIM technical support.

PIC IR remote

Friday, October 14th, 2005

Here’s the info on how to control a SONY TV. (caveat you may need to do some debugging.)

You need a 555 timer to generate the 40 Khz for you.
Your pic just turns on or off the 555 to transmit the appropriate data.

Circuit link.

SIRC codes explained.

SIRC code data format

My PICBasicPro code to implement this protocol.

Update:

Found a simpler solution. Use this IC from rentron. It will generate either a 40 or 38KHz carrier frequency for you. Use the PIC program above and connect the PIC pin to DATA IN of this IC. You need a 4Mhz clock, some pullup/down resistors, and the circuit to drive your IR LED…that’s it!