Creating a Custom PCB for the Atmel AVR...

15
1 Creating a Custom PCB for the Atmel AVR Microcontroller Adrian Herrera Introduction This tutorial provides information on how to design and prototype a circuit featuring an AVR microcontroller, and what needs to be given to the SECTE workshop for the construction of the final Printed Circuit Board (PCB). This is important for project-based subjects such as ECTE250, ECTE350, ECTE451, and ECTE458. A simple design is used as a reference project throughout this tutorial. This tutorial requires the following: A STK500 development board and appropriate Atmel AVR microcontroller, A solder-less breadboard (available for loan from the SECTE store) and any required electronic components, EAGLE software package by CadSoft. Initial Design and Testing using the STK500 Board For instruction on how to install and use Atmel’s AVR Studio for either Assembler or C programming, please consult the relevant tutorials located on SECTE’s AVR website. For this tutorial, a simple circuit featuring an Atmel ATMega8515 AVR microcontroller, an LED Bar Graph, and a DIP switch was designed and prototyped. When a switch was placed into the ON position, its corresponding LED in the LED Bar Graph was also switched on. Resisters were used between the microcontroller’s pins and the LED Bar Graph to limit the current to the LEDs. Assembly code is given in Appendix A, while C code is given in Appendix B to perform the required operations in the microcontroller. This code can be tested via AVR Studio’s in-built simulator, as outlined in the relevant tutorials located on SECTE’s AVR website. Once the code has been properly compiled, the HEX file can be downloaded to the microcontroller and tested on the STK500. Appropriate functionality that can be tested on the STK500 include serial communications (via the onboard RS-232 transceiver), and basic digital I/O (via the switches and LEDs). Note that it can sometimes be difficult to test external electronic components when using the STK500; however these can be tested using a breadboard prototype. For the reference project, digital I/O is the only functionality utilised, which allowed full testing on the STK500. PORTB was used for input, so it was connected to the switches, while PORTA was used for output, so it was connected to the LEDs. This is shown in Figure 1.

Transcript of Creating a Custom PCB for the Atmel AVR...

Page 1: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

1

Creating a Custom PCB for the Atmel AVR Microcontroller Adrian Herrera

Introduction This tutorial provides information on how to design and prototype a circuit featuring an AVR microcontroller, and what needs to be given to the SECTE workshop for the construction of the final Printed Circuit Board (PCB). This is important for project-based subjects such as ECTE250, ECTE350, ECTE451, and ECTE458. A simple design is used as a reference project throughout this tutorial. This tutorial requires the following:

• A STK500 development board and appropriate Atmel AVR microcontroller, • A solder-less breadboard (available for loan from the SECTE store) and any required electronic

components, • EAGLE software package by CadSoft.

Initial Design and Testing using the STK500 Board For instruction on how to install and use Atmel’s AVR Studio for either Assembler or C programming, please consult the relevant tutorials located on SECTE’s AVR website. For this tutorial, a simple circuit featuring an Atmel ATMega8515 AVR microcontroller, an LED Bar Graph, and a DIP switch was designed and prototyped. When a switch was placed into the ON position, its corresponding LED in the LED Bar Graph was also switched on. Resisters were used between the microcontroller’s pins and the LED Bar Graph to limit the current to the LEDs. Assembly code is given in Appendix A, while C code is given in Appendix B to perform the required operations in the microcontroller. This code can be tested via AVR Studio’s in-built simulator, as outlined in the relevant tutorials located on SECTE’s AVR website. Once the code has been properly compiled, the HEX file can be downloaded to the microcontroller and tested on the STK500. Appropriate functionality that can be tested on the STK500 include serial communications (via the onboard RS-232 transceiver), and basic digital I/O (via the switches and LEDs). Note that it can sometimes be difficult to test external electronic components when using the STK500; however these can be tested using a breadboard prototype. For the reference project, digital I/O is the only functionality utilised, which allowed full testing on the STK500. PORTB was used for input, so it was connected to the switches, while PORTA was used for output, so it was connected to the LEDs. This is shown in Figure 1.

Page 2: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

2

Figure 1 - Testing digital I/O on the STK500

Tips:

• The STK500 uses active-low switches and LEDS, resulting in inverted logic which may cause confusion if an active-high design is used in the breadboard prototype and final PCB.

• When using the serial port, ensure the RXD and TXD pins are connected to the appropriate PORT of the microcontroller being used, and that the RS232 SPARE connection is connected to a PC (not the RS232 CTRL connection).

Breadboard Prototyping Once initial testing using the STK500 board has been completed, a prototype circuit can be constructed using a solder-less breadboard to test features/components that may not have been possible to test using the STK500 board. Breadboard’s are either available to borrow from the SECTE store, or to purchase from electronics retailers such as Jaycar and Dick Smith Electronics. A typical breadboard layout is given in Figure 2. The green lines denote a continuous strip of copper (terminal strip) underneath the plastic top, which create an electrical connection between points on the breadboard.

Page 3: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

3

Figure 2 - Typical Breadboard Layout (adapted from Wikipedia)

The vertical red and blue terminal strips that run down the left and right sides of the breadboard are typically used to provide power to the electronic components (note the break halfway down the board), while the horizontal terminal strips in the centre of the board are used to hold the electronic components. Power to the breadboard can be provided by either one of two ways. One method is via the VTG and GND pins on the STK500 board as shown in Figure 3. Note the STK500 board can only source a limited amount of current, so only use this method to power simple circuits with relatively low current requirements.

Page 4: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

4

Figure 3 – Powering the breadboard via the STK500

Alternatively, an external supply may be connected to the binding posts at the top of a breadboard (shown in Figure 2), and then connected to the vertical terminal strips via jumper wires. If using this method be wary of the power supply’s output voltage; the AVR microcontroller only requires a 5V DC supply, much more than this can potentially damage or destroy any electronics on the breadboard. For the reference project, the breadboard prototype is shown in Figure 4 and Figure 5.

Page 5: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

5

Figure 4 - Reference project Breadboard prototype

Figure 5 - Reference project Breadboard prototype

Page 6: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

6

Tips: • Useful tools for breadboard prototyping include a small pair of wire cutters and/or wire strippers,

and (perhaps most importantly) a multimeter (to check voltages and resistances). • Try to keep the layout of your breadboard neat and tidy, making it easier to fault-find if something

isn’t working right. This includes keeping jumper wires to a suitable length, which may also help in reducing stray capacitance.

• If possible, try and use a colour-coding system for your jumper wires, e.g. red for positive voltages, black for grounds, etc. This again helps keep the prototype neat and tidy, aiding in fault-finding.

Veroboard Prototype In addition to the breadboard prototype, a prototype may be constructed using Veroboard. Veroboard is similar to a breadboard, in that copper tracks run throughout the board. However, unlike a breadboard, it requires components be soldered onto the board. Veroboard is available from Jaycar and Dick Smith Electronics in various sizes, with differing styles of copper tracks. Examples are given in Figure 6 and Figure 7.

Figure 6 - Veroboard with continuous copper tracks

Figure 7 - Veroboard with copper rings

Page 7: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

7

For the style of Veroboard shown in Figure 6, careful thought must be used when deciding on how to layout components to make best use of the copper tracks and minimise the use of wire jumpers. If using the style in Figure 7, wire jumpers are required to join components together as there are no continuous copper tracks. For the reference project, Veroboard with continuous copper tracks was used. The resistors were soldered on first, with cuts made in the copper tracks to ensure they were not shorted out. Following this, the IC socket for the microcontroller was soldered on, with cuts again made in the copper to ensure the microcontroller pins did not short out. The prototype at this stage is shown in Figure 8.

Figure 8 - Veroboard prototype with resistors and IC socket attached

Next, the LEDs and DIP switch was soldered on. Once again these were placed so electrical connectivity was achieved via the copper tracks (with appropriate cuts made so no components were shorted out) and no wire jumpers were required.

Figure 9 - Veroboard prototype in construction

Finally, the power supply connector was attached. For this, additional wire jumpers were required to route power to the microcontroller. Note that this prototype does not feature any voltage regulation, so it is assumed that 5V will be provided to the power supply connector (although this is not always a safe assumption!).

Page 8: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

8

The final Veroboard prototype is show in Figure 10.

Figure 10 - Final Veroboard prototype

Tips:

• When using Veroboard with continuous copper tracks, a knife can be used to cut the tracks to form breaks as desired.

• When using the soldering iron, ensure adequate heat has been reached and the tip is clean before you begin soldering components to the board.

• When soldering components to the Veroboard, start with the smaller lower-laying components first (e.g. resistors) before moving onto the high-rising components (e.g. power supply connection). If done the other way round, it can be difficult to solder on the lower-laying components neatly.

• When soldering on jumper wires, ensure you do not leave the soldering iron on the wires for too long, as the plastic coating will melt under sustained high temperatures.

Preparing Schematics Schematics are required by the workshop staff to produce the final PCB. The more detail/information included in your schematics, the easier it is for the workshop to produce the PCB. Not only this, but it is also an important step in documenting your work (important not only in project subjects, but in the “real world” as well). Numerous schematic editors are available, ranging from free (such as EAGLE by CadSoft) to expensive professional packages (such as Altium Designer, formerly Protel). A freeware version of CadSoft’s EAGLE software is available for download from http://www.cadsoft.de/download.htm. Versions for Windows, Mac, and Linux are available. Also available from the CadSoft webpage are additional parts libraries that contain hundreds of electronic components from many different manufacturers.

Page 9: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

9

Another useful library is that for parts available from Sparkfun Electronics (http://www.sparkfun.com), available from http://www.opencircuits.com/SFE_Footprint_Library_Eagle. To make a library available for use in EAGLE, copy the .lbr file into the Eagle\lbr directory. To create a new schematic, go to File → New → Schematic. You will be greeted with an empty schematic, as shown in Figure 11.

Figure 11 - Empty EAGLE Schematic

To place a component into the schematic, click the button in the left-hand pane. Find the appropriate parts library, and select the desired component (packaging is not so important if only designing a schematic) as shown in Figure 12.

Page 10: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

10

Figure 12 - Select component from the parts libraries

Parts can be rotated by clicking the button in the left-hand pane, and then clicking the component in question until the required orientation is achieved.

To turn off the rotation, click the button in the left-hand pane.

To rename components, click the button in the left-hand pane, and then click the component in question. The new name can then be entered into the text-box, as shown in Figure 13.

Page 11: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

11

Figure 13 - Rename a component in EAGLE

To change the value of a component (e.g. resistor, capacitor, etc), click the button in the left-hand pane, and then click the component in question. The new value can then be entered into the text-box, as shown in Figure 14.

Figure 14 – Change the value of a component in EAGLE

Page 12: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

12

To connect pins together via wires, click the button in the left-hand pane. To draw the wire, click a point in the schematic, and then click again where you want to place the other end of the wire. This wire can then be routed to another pin if required by clicking another point in the schematic. If not, press the ESC key. Finally, the .sch files created by EAGLE can be saved as standard image files by selecting File → Export → Image. Click “Browse” to select the location to save the schematic, and select the image type from the drop-down menu. The image resolution can also be set. A beginner’s tutorial to EAGLE can also be found at http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=108. The schematic drawing for the reference project is given in Appendix C. Tips:

• Ensure you always double-check the pin numbers in the parts libraries against the component’s datasheet, otherwise your final PCB may not work as intended!

• Ensure you show all power supply connections for active components (including ground!).

PCB Manufacture While various home-kits for PCB manufacture are available for purchase from Jaycar or Dick Smith Electronics, SECTE’s workshop can provide a manufacture service resulting in a professional-looking printed circuit board. Once the prototype has been thoroughly tested, and you are confident in your schematic diagram, take your schematics and all your components to the workshop staff. Other details such as housing for your circuit should also have been thought-out prior to seeing the workshop staff. This information (and your components; for size and packaging details) is required by the workshop staff for designing and drawing the PCB layout, which is then manufactured and your components soldered on to create the final PCB.

Page 13: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

13

Appendix A – Assembly Sample Code ; AVR-PCB.asm ; ; Simple assembler program for AVR PCB tutorial ; ; Author: Adrian Herrera ; Date: 3/02/2009 ; .include "m8515def.inc" .def temp = r16 RESET: ; Set PORTB as an input port with pull-up resistors active ; Set PORTA as an output port clr temp out DDRB, temp ser temp out PORTB, temp out DDRA, temp LOOP: ; Main loop ; Continually read in the DIP switch connected to PORTB, ; and based on this toggle the LEDs connected to PORTA in temp, PINB com temp out PORTA, temp rjmp LOOP ; End AVR-PCB.asm

Page 14: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

14

Appendix B – C Sample Code /* Avr-PCB_C.c * * Simple C program for AVR PCB tutorial * * Author: Adrian Herrera * Date: 22/12/2009 */ #include <avr/io.h> int main(void) { unsigned char temp; /* Set PORTB as an input port with pull-up resistors active * Set PORTA as an output port */ DDRB = 0x00; PORTB = 0xFF; DDRA = 0xFF; /* Main loop * Continually read in the DIP switch connected to PORTB, * and based on this toggle the LEDs connected to PORTA */ for(;;) { temp = PINB; temp = ~temp; PORTA = temp; } }

Page 15: Creating a Custom PCB for the Atmel AVR Microcontrollerphung/teach/ecte333/ECTE333-Lecture-13-PCB... · This tutorial provides information on how to design and prototype a circuit

15

Appendix C – Sample Schematic