atmega 128 development board

Upload: fariha-naaz

Post on 06-Jul-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/17/2019 ATMEGA 128 Development Board

    1/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

     

    ATMEGA 128 DEVELOPMENT

    BOARD MANUAL

    JUNE 2012

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 1

  • 8/17/2019 ATMEGA 128 Development Board

    2/80

  • 8/17/2019 ATMEGA 128 Development Board

    3/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    INDEX

    1.0 Introduction..............................................................................................................................5

    1.1 Board Features...........................................................................................................................5

    1.2 Peripheral Interface....................................................................................................................81.3 Peripheral Overview..................................................................................................................8

    2.0 Programming ATMEGA128 Development Board...............................................................9

    2.1 Installing WIN AVR..................................................................................................................92.2 Installing AVR Studio.............................................................................................................132.3 Setting up Project in AVR Studio............................................................................................172.4 Writing your first code in AVR Studio....................................................................................222.5 Debugging the code in AVR studio.........................................................................................242.6 Loading your code on ATMEGA128 Development Board using AVR Boot loader from NEX

    Robotics......................................................................................................................................26

    2.6.1 Boot loader operating principle............................................................................................262.6.2 Boot Loading........................................................................................................................272.6.2.1 Boot loading via serial port................................................................................................272.6.2.2 Boot loading via USB port................................................................................................282.6.2.3 Installing FT232 USB to Serial converter drivers.............................................................292.6.2.4 Identifying and changing COM Port number of the Serial Port........................................322.6.3 Installing and using Bootloader GUI....................................................................................352.6.4 Using Boot loader.................................................................................................................372.7 Loading your code on the ATMEGA128 Development Board using AVR USB programmer  from NEX Robotics................................................................................................................... 402.7.1 Driver Installation.................................................................................................................40

    2.8 Loading your code on the ATMEGA128 Development Board using ATMEL’s AVRISP mkIIProgrammer................................................................................................................................52

    2.8.1 Fuse settings for ATMEGA128 microcontroller..................................................................54

    3.0 Hardware Description...........................................................................................................57

    3.1 Power and IO Port Configuration............................................................................................583.2 LED Interface..........................................................................................................................593.3 Switch Interface.......................................................................................................................603.4 RC Servo Motor Interface.......................................................................................................603.5 RS232 Serial Communication.................................................................................................623.6 USB Communication...............................................................................................................63

    3.7 XBEE Wireless Communication.............................................................................................643.8 SD/MMC Card Interface.........................................................................................................653.9 Motor Controller Driver IC L293D Interface..........................................................................673.10 High Current Driver ULN2003 Interface..............................................................................693.11 RTC Interface........................................................................................................................703.12 LCD Interface........................................................................................................................713.13 Buzzer Interface.....................................................................................................................733.14 ADC Interface........................................................................................................................74

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 3

  • 8/17/2019 ATMEGA 128 Development Board

    4/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    4.0 Sample Programs...................................................................................................................76

    4.1 IO interfacing...........................................................................................................................764.2 Buzzer test...............................................................................................................................764.3 LCD interfacing.......................................................................................................................764.4 ADC LCD................................................................................................................................76

    4.5 ULN2003 interface..................................................................................................................764.6 L293D demo code....................................................................................................................764.7 UART0 Serial..........................................................................................................................764.8 UART1 XBee..........................................................................................................................764.9 UART2 USB............................................................................................................................774.10 RTC demo..............................................................................................................................774.11 Servo control..........................................................................................................................774.12 SD card interface...................................................................................................................77

    5.0 Schematic.................................................................................................................................78

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 4

  • 8/17/2019 ATMEGA 128 Development Board

    5/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    1.0 Introduction

    1.1 Board Features

    ATMEGA128 Development Board is a powerful development platform based on ATMEGA128microcontroller which is one of the most rich feature AVR microcontroller from Atmel featuring128K Flash, 4K RAM, 53 I/O lines arranged in six 8 bit I/O ports, 8 ADCs, 2 UARTs, 4 timers,8 interrupts and much more. This board is ideal for developing embedded applications involvinghigh speed wireless communication, USB based data logging, real time data monitoring andcontrol, interactive control panels etc.

    The expansion ports are taken for all the pins of the microcontroller in neat PORT wiseconfiguration. Board has lots of peripherals such as LCD, SD /MMC card, ZigBee wirelessadaptor board, True USB to Serial converter, 8 servo motors connector, DS1307 based Real-Time Clock, ULN2003 7 channel driver, L293D dual DC motor driver, three Potentiometers, 8

    switches, 8 LEDs, boot switch and RS232 serial interface etc.

    The board is highly suitable for customization. The on-chip peripherals and the externalhardware on the development board are interconnected using pin headers and jumpers. The I/Opins on the microcontroller can be accessed from 10 pin FRC connectors. The board is madefrom double sided PTH PCB board to provide extra strength to the connector joints for increasedreliability. It supports the operating supply voltage between 7V to 14V and has built-in reversepolarity protection.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 5

  • 8/17/2019 ATMEGA 128 Development Board

    6/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Specifications• Microcontroller: ATMEGA128 with 14.7456 MHz crystal (Also supports ATMEGA640,

    ATMEGA1280, ATMEGA2560)

    • Double side high quality PTH PCB for added strength.

    • Power: 9 to 14V, AC or DC

    • Switches: Boot, Reset, Power• 10 pin FRC connectors for all IO ports

    • RS232,USB and Xbee serial interface along with the MCUs UART selection jumpers

    • SD card Interfacing

    • 8 channels for RC Servo motor control

    • RTC interface with 3V Li battery

    • Motor driving interface with L293D

    • On board ULN2003 chip interface

    • Eight number of onboard LEDs and Switches

    • A Buzzer interfacing

    •Compatible with General purpose prototyping board for stackable design

    • Application examples in AVR studio provided in the documentation CD

    Kit Contains• 1- ATMEGA128 Development Board

    • 1- USB Cable

    • 1- DB9 Serial Cable

    • 3- 10 pin FRC Cables

    • 10 - 1 to 1 jumper cables

    • 1- Documentation CD

    Documentation CD contain following Application examples• IO interfacing

    • Buzzer test

    • LCD interfacing

    • ADC sensor data display on the LCD

    • ULN2003 interface

    • L293D demo

    • UART2 Serial

    • UART1 XBee

    • UART0 USB

    • RTC demo• Servo control

    • SD card interface

    Warning:Input power supply should not exceed 15 V AC/DC.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 6

  • 8/17/2019 ATMEGA 128 Development Board

    7/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    1.2 ATMEGA 128 Features:• High Performance, Low Power AVR® 8-Bit Microcontroller

    • 32 x 8 General Purpose Working Registers

    • Up to 16 MIPS Throughput at 16 MHz

    • 128K Bytes of In-System Self-Programmable Flash

    • In-System Programming by On-chip Boot Program• 4K Bytes EEPROM

    • 4K Bytes Internal SRAM

    • Up to 64K Bytes Optional External Memory Space

    • Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode

    • Two 16-bit Timer/Counter with Separate Prescaler, Compare- and Capture Mode

    • Four 8-bit PWM Channels

    • Six PWM Channels with Programmable Resolution from 2 to 16 Bits

    • 8-channel, 10-bit ADC

    • Dual Programmable Serial USART

    •Master/Slave SPI Serial Interface

    • Byte Oriented 2-wire Serial Interface

    • Programmable Watchdog Timer with Separate On-chip Oscillator

    • On-chip Analog Comparator

    • Interrupt and Wake-up on Pin Change

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 7

  • 8/17/2019 ATMEGA 128 Development Board

    8/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    1.3 Peripheral Overview

    1. ATMEGA128 (Plug-in Module)

    2. Reset Switch

    3. ISP Connector

    4. PORTE Header

    5. PORTH Header6. PORTB Header

    7. PORTL Header

    8. PORTD Header

    9. PORTG Header

    10. PORTC Header

    11. PORTJ Header

    12. PORTA Header

    13. PORTK Header

    14. PORTF Header

    15. ADC Header

    16. LCD contrast POT

    17. LCD header

    18. LCD Backlight Jumper

    19. 16*2 LCD

    20. ULN2003 Header

    21. RTC Header

    22. L293D Header

    23. ADC POTs

    24. ULN2003 CON

    25. L293D CON

    26. XBee Header

    27. XBee Module

    28. SD/MMC Header29. SD/MMC Socket

    30. USB_serial Header

    31. USB connector

    32. Serial DB9 Connector

    33. Power Port

    34. Boot Load switch

    35. Boot Load Jumper

    36. AC/DC Socket

    37. Power Switch

    38.Power LED39. Terminal block connector

    40. Servo Header

    41. Servo connector

    42. LED Header

    43. LEDs

    44. Switch Header

    45. Switches

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 8

  • 8/17/2019 ATMEGA 128 Development Board

    9/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.0 Programming ATMEGA128 Development Board

    There are lots of IDEs (Integrated Development Environment) available for the AVRmicrocontrollers. There are free IDEs which are based on AVR GCC like AVR Studio fromATMEL and WIN AVR and proprietary IDEs like ICC AVR, Code vision AVR, IAR and KEIL

    etc. IDEs like ICC AVR and code vision AVR are very simple to use because of their GUI basedcode generator which gives you generated code. Almost all the proprietary IDEs works as fullversion for first 45 days and then there code size is restricted to some size. We have used freeIDE like AVR Studio from ATMEL and proprietary IDE like ICC AVR for the ATMEGA128Development Board. In this manual we are going to focus on the AVR studio from the ATMEL.It uses WIN AVR open source C compiler at the back end. It has many attractive features likebuilt-in In-Circuit Emulator and AVR instruction set simulator. After writing and compiling theprogram it gives “.hex” file. This “.hex” files needs to be loaded on the ATMEGA128Development Board using In System Programmer (ISP).

    IDE Installation

    Since AVR studio uses WIN AVR compiler at the back end we need to install WIN AVR first(Please note that WIN AVR must be installed before AVR Studio so that AVR Studio can easilydetect the AVRGCC plug-in).

    2.1 Installing WIN AVRInsert the ATMEGA128 Development Board documentation CD and from the “Software andDrivers” folder copy “WIN AVR 2009-03-13” on the PC and click on WinAVRxxxx.exe file.

    Figure 2.1

    WIN AVR installation package will open. Choose language as “English”.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 9

  • 8/17/2019 ATMEGA 128 Development Board

    10/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 2.2

    Click “Next” in the WIN AVR setup wizard.

    Figure 2.3

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 10

  • 8/17/2019 ATMEGA 128 Development Board

    11/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Press “I Agree” after going through license agreement.

    Figure 2.4

    Make sure that you select drive on which operating system is installed.

    Figure 2.5

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 11

  • 8/17/2019 ATMEGA 128 Development Board

    12/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Select all the components and press “Install”.

    Figure 2.6

    Click “Finish” to complete WIN AVR installation

    Figure 2.7

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 12

  • 8/17/2019 ATMEGA 128 Development Board

    13/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.2 Installing AVR StudioGo to “Software and Drivers” folder from the documentation CD, copy folder “AVR Studio4.17” on the PC and click on “AvrStudio417Setup.exe” to start the installation process.

    Figure 2.8

    Click on “Run”

    Figure 2.9

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 13

  • 8/17/2019 ATMEGA 128 Development Board

    14/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Click “Next” to start installation of AVR Studio 4

    Figure 2.10

    After clicking “Next” go through the license agreement. If it is acceptable then click “Next”

    Figure 2.11

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 14

  • 8/17/2019 ATMEGA 128 Development Board

    15/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Now choose the destination drive. Select the same drive in which your operating system andWINAVR is installed.

    Figure 2.12

    Select for the “Install / upgrade Jungo USB Driver” to support In System Programming (ISP) byAVRISP mkII

    Figure 2.13

    Important:  If “Install / upgrade Jungo USB Driver” is not selected then AVRISP mkIIprogrammer will not work with the AVR Studio.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 15

  • 8/17/2019 ATMEGA 128 Development Board

    16/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Click “Next” to start the installation process.

    Figure 2.14

    Click “Finish” to complete the installation process.

    Figure 2.15

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 16

  • 8/17/2019 ATMEGA 128 Development Board

    17/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.3 Setting up Project in AVR Studio

    AVR studio is an Integrated Development Environment (IDE) for writing and debugging AVRapplications. As a code writing environment, it supports included AVR Assembler and anyexternal AVR GCC compiler in a complete IDE environment.

    AVR Studio gives two main advantages:

    1. Edit and debug in the same application windows. Faster error tracking.2. Breakpoints are saved and restored between sessions, even if codes are edited.

    Figure 2.16

    Middle window shows current code under development. Window on the left side shows view ofsource files, header files, External dependencies, and other files. Right side window shows all theports and other peripheral’s status. Bottom window is known as Build window. It shows resultsof the compilation, errors, HEX file size and other warning messages etc.

    1. Open AVR Studio. If any project is running it can be closed by clicking on Project in the

    menu and select Close Project.

    2. To create new project click on Project in the menu and select “New Project”.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 17

  • 8/17/2019 ATMEGA 128 Development Board

    18/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 2.17

    3. Select Project Type as “AVR GCC”. Type project name in the “Project name” window. In thiscase it is “1_Buzzer_Beep”. Also check on Create folder check box. This will create all the filesinside the new folder. In the Location window select the place where would like to store your

    project folder and then click “Next”.

    Figure 2.18

    4. Select debug platform and Device. In this case we have selected “AVR simulator” and“ATMEGA128” microcontroller and click finish.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 18

  • 8/17/2019 ATMEGA 128 Development Board

    19/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 2.19

    5. Now we are almost ready to write our first code. Before we start coding we will check othersetting to make sure that they are set properly.

    Figure 2.20

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 19

  • 8/17/2019 ATMEGA 128 Development Board

    20/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    6. Open Project menu and click on the Configuration option.

    Figure 2.21

    7. In the Project Option “General” tab will open. Select device as “ATMEGA128” and frequency

    (Crystal Frequency) as 14.7456MHz i.e. 14745600Hz. Set the optimization level be at “-O0”.

    Figure 2.22

    Selecting proper optimization options

    “Optimization” option defines the optimization level for all files. Higher optimization levels willproduce code that is harder to debug. Stack variables may change location, or be optimizedaway, and source level debugging may "skip" statements because they too have been optimizedaway.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 20

  • 8/17/2019 ATMEGA 128 Development Board

    21/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    The levels of optimization are:•   -O0 No optimization. This is the same as not specifying any optimization.

    • -O1 Optimize. Reduces code size and execution time without performing anyoptimizations that take a great deal of compilation time.

    • -O2 Optimize even more. avr-gcc performs almost all optimizations that don't involve a

    space-time tradeoff.• -O3 Optimize yet more. This level performs all optimizations at -O2 along with -finline-

    functions and -frename-registers.

    • -Os Optimize for size. Enables all -O2 optimizations that don't increase code size. It alsoperforms further optimizations designed to reduce code size.

    For more information on optimization, see the 'man' pages for avr-gcc.

    Important: While you writing the code, choose appropriate optimization option. If you feel thatcode is not working properly as it should be then turn off all optimization by selectingoptimization option as “-O0”. Once you know that your code is properly working then you can

    incrementally increase optimization level.

    We suggest that always use optimization level as “-O0” at the beginner level.

    8. Make sure that in the External Tools, proper path for avr-gcc.exe and make.exe are given andpress ok.

    Figure 2.23

    Now we are ready to write our first code.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 21

  • 8/17/2019 ATMEGA 128 Development Board

    22/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.4 Writing your first code in AVR StudioWe are going to write our first code for our ATMEGA128 Development Board.

    This program will make ATMEGA128 Development Board’s buzzer beep.

    Copy the following code in window “code area”. We will see how this code works in the nextchapter.

     //Buzzer is connected at the third pin of the PORTC //To turn it on make PORTC 3rd (PC3 )pin logic 1#include #include #include 

     //Function to initialize Buzzervoid buzzer_pin_config (void)

    { DDRC = DDRC | 0x08; //Setting PORTC 3 as output PORTC = PORTC & 0xF7; //Setting PORTC 3 logic low to turnoff buzzer}

    void port_init (void){ buzzer_pin_config ();}

    void buzzer_on (void){ unsigned char port_restore = 0; port_restore = PINC; port_restore = port_restore | 0x08; PORTC = port_restore;}

    void buzzer_off (void){ unsigned char port_restore = 0;

     port_restore = PINC; port_restore = port_restore & 0xF7; PORTC = port_restore;}

    void init_devices (void){ cli ();  //Clears the global interrupts

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 22

  • 8/17/2019 ATMEGA 128 Development Board

    23/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

     port_init (); sei ();  //Enables the global interrupts}

     //Main Function

    int main (void){init_devices ();while (1){

    buzzer_on (); //delay_delay_ms (1000);buzzer_off (); //delay_delay_ms (1000);

    }}

    We are now going to compile this code to generate the hex file, which we will load on theATMEGA128 microcontroller. Select “Build” menu and click on “Rebuild All”. It will compilethe “1_Buzzer_Beep.c” code and will generate “1_Buzzer_Beep.hex” file for the ATMEGA128microcontroller.

    Figure 2.24

    You can verify successful compilation in the bottom most “Build” window of the AVR Studio.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 23

  • 8/17/2019 ATMEGA 128 Development Board

    24/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 2.25

    You can also verify that “1_Buzzer_Beep.hex” file is generated in the “default” folder inside thefolder you have selected.

    2.5 Debugging the code in AVR studioAfter successful compilation of the code we can debug the code by AVR Debugger provided byAVRStudio. Here is the illustration of debugging of code given in Exp1 (buzzer ON-OFF

    folder).

    Click on Debug tab in the menu and click on “Start Debugging”.

    Figure 2.26

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 24

  • 8/17/2019 ATMEGA 128 Development Board

    25/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Now debugging mode is started and an arrow is visible at the first line of our main function fromwhere the debugging will start.

    Figure 2.27

    Press “F11” key or “Step into” button from the toolbar to start debugging statement bystatement. Processor details are visible at left window and the I/O port status is displayed at therightmost window.

    Figure 2.28

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 25

  • 8/17/2019 ATMEGA 128 Development Board

    26/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    By this way we can continuously monitor the bit changes in any of the registers ofmicrocontroller and debug the code before actually burning it to the microcontroller. PORTC bitschanges as per our commands and these changes can be seen in right window. After debugging isdone select “Stop Debugging” from Debug tab.

    Figure 2.29

    2.6 Loading your code on ATMEGA128 Development Board using AVR Boot

    loader from NEX Robotics

    All AVR microcontrollers can be programmed using In System Programming (ISP), externalprogrammer or using boot loader. Advantage with the boot loader is that you don’t need anyexternal hardware to load the .hex file on the microcontroller.

    2.6.1 Boot loader operating principle

    If Bootloader firmware is loaded on the microcontroller then it can be programmed directly viaserial port or USB (using USB to Serial converter) using PC. In the boot loading method a smallpiece of code is loaded on the microcontroller in the configurable boot memory section. Whensignaled using external switch while resetting the microcontroller it gets active and waits for

    communication from the PC. Bootloader software from NEX Robotics, which is installed on thePC, communicates with the microcontroller. Boot loader software loads the .hex file on themicrocontroller. After the boot loading process is complete, newly loaded code can be executedby pressing reset. Once the code is loaded on the microcontroller UART is free and can be usedfor other applications. Bootloader get invoked only if boot switch is kept pressed whilemicrocontroller is reset using reset switch.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 26

  • 8/17/2019 ATMEGA 128 Development Board

    27/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Note: Bootloader code is loaded on the ATMEGA128 Microcontroller of the Development Boardusing ISP programmer. It is recommended that you only use Bootloader to the load the hex file.If you use ISP programmer with the Development Board to load .hex file then boot section codeget erased and ATMEGA128 Development Board will no longer support boot loading.

    2.6.2 Boot LoadingThe .hex file is loaded on the ATMEGA128 via bootloader. ATMEGA 128 has 2 UART Portsfrom UART0 to UART1. The Bootloader is designed to support only UART0. For bootloadingwe can use either Serial port or USB port. Board is shipped with UART0 connected to the USBport. The following section describes Bootloading via serial port and USB port. For bootloadingwe have to use, boot switch along with the reset switch. To enable the boot switch you need toconnect 1 to 1 connector between Boot load pin and PD6 as shown in figure below.

    2.6.2.1 Boot loading via serial port

    To use Serial RS232 module for boot loading, we have to short the RXD0 and TXD0 jumpers to

    connect TXD and RXD of MAX232 RS232 to serial TTL converter to RXD and TXD ofUART0. For connection details refer to figure 2.30.

    Note: When you use Serial Port for Boot loading connect UART0  jumper and remove USB jumper near the POWER PORT as shown in figure below.

    Figure 2.30

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 27

  • 8/17/2019 ATMEGA 128 Development Board

    28/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Connections: Insert the two 2-pin jumpers on TXD0 and RXD0 below the ATMEGA128 socketConnect 1 to 1 connector between Boot load pin and PD6.Connect the 9 pin DB serial cable between Board serial connector and PC serial port.

    2.6.2.2 Boot loading via USB port

    To do bootloading via USB port, we need to connect TXD and RXD of the FT232 IC (USB toserial converter) with RXD and TXD of the UART0. For connection details refer to figure 2.31.

    Note:  Remove the RXD0 and TXD0 jumpers below the ATMEGA128 Plug-In Module, ifinserted.

    Figure 2.31

    Connections: Insert the two 2-pin jumpers on TXD0 and RXD0 near the POWER PORT.Connect 1 to 1 connector between Boot load pin and PD6.Connect the USB cable between Board USB connector and PC USB port.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 28

  • 8/17/2019 ATMEGA 128 Development Board

    29/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.6.2.3 Installing FT232 USB to Serial converter drivers

    Before using USB port we need to install the driver software for FT232 USB to serial converter.The software is located in the “Software and Drivers \ CDM 2.06.00 WHQL Certified” folder,provided in the ATMEGA128 Development Board CD or can also be downloaded from the NEXRobotics website.

    Steps to install the drivers for USB to serial converter:

    Step 1:

    Copy the driver installation folder on your PC from “Software and Drivers \ CDM 2.06.00WHQL Certified” Folder in the CD.

    Step 2:

    Connect the USB to serial converter cable between ATMEGA128 Development Board and thePC.Step 3:

    On connecting the device “Found New Hardware” message will appear in the taskbar tray andthe following window opens.

    Figure 2.32

    Step 4:Check on the radio button “No, not this time” and then click on the next button. 

    Figure 2.33

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 29

  • 8/17/2019 ATMEGA 128 Development Board

    30/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    The following window will appear.

    Figure 2.34

    Select the second option manually to install the drivers and click on next button.

    Step 5:

    Now check the second option and set the location of folder containing driversE.g.(C:\CDM 2.06.00 WHQL Certified).

    Figure 2.35

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 30

  • 8/17/2019 ATMEGA 128 Development Board

    31/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Step 6:

    On clicking next driver installation will begin.

    Figure 2.36

    Step 7:

    On successfully installing the driver following window will appear. Click Finish to complete theinstallation.

    Figure 2.37

    After installation of FT232 USB UART software, PC may ask for USB serial port software. Toinstall this software follow steps 1 to 7 of USB serial converter software installation.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 31

  • 8/17/2019 ATMEGA 128 Development Board

    32/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Important: When using USB port for the communication, for proper operation first turn on theBoard then insert the USB cable in the Board. We have to follow this sequence because USB toserial converter chip is powered by USB. If any fault occurs then turn off the Board and removethe USB cable and repeat the same procedure. After complete installation of USB Serialconverter driver, we need to identify the comport number, where the USB cable is connected to

    which USB port.

    2.6.2.4 Identifying and changing COM Port number of the Serial Port.

    To use terminal.exe or any other serial program, we need to first identify communication portwhich is generally referred as COM n, i.e. COM1 or COM2 etc. on which USB to serialconverter or wireless device or MAX232 is connected. Follow these steps to identify your COMPort number.

    Step 1: Right Click My Computer and click on properties. System properties window will appear.

    Figure 2.38

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 32

  • 8/17/2019 ATMEGA 128 Development Board

    33/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Step 2: Click on the Device manager in the Hardware tab.

    Figure 2.39

    Step 3: Expand Ports (Com & LPT) tree. COM Port number is mentioned in the parenthesis next to USBSerial Port.

    Figure 2.40

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 33

  • 8/17/2019 ATMEGA 128 Development Board

    34/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Step 4: If the COM port number is greater than 10 Terminal will not be able to detect it. To resolve thisproblem, change the port number by right clicking on “USB serial Port” and select properties.

    Figure 2.41

    In the Port settings tab click on the “Advanced” button, the following window will appear.

    Figure 2.42

    You can change the COM port number by clicking on the Com Port number drop down list andselect the appropriate number. Make sure the new COM port is not being used by any otherdevice.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 34

  • 8/17/2019 ATMEGA 128 Development Board

    35/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.6.3 Installing and using Bootloader GUIInsert the ATMEGA128 Development Board documentation CD and from the “Software andDrivers” folder copy “AVR Bootloader” on the PC and click on “setup” application file.

    Figure 2.43

    It pop-up with the “AVR Bootloader Setup wizard”

    Figure 2.44

    Click on the “Next” button.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 35

  • 8/17/2019 ATMEGA 128 Development Board

    36/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 2.45

    Select the installation location and click on the “Next” button.

    Figure 2.46

    Click on the close button and the installation is complete. Now you can use the Boot loader.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 36

  • 8/17/2019 ATMEGA 128 Development Board

    37/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.6.4 Using Boot loader

    Step1: Turn on the ATMEGA128 Development Board.

    Step2: Connect a DB9 Serial cable between the Serial port on your PC and the Serial connector

    on ATMEGA128 Development Board.ORIf you are using the USB Port of ATMEGA128 Development Board, do the connectionexplained in section 2.6.2.2.

    Step3: Enter in to boot load mode by keeping the BOOT switch pressed and then press andrelease RESET switch. Release BOOT switch after releasing reset.

    Step4:  To start the Bootloader you can click on the desktop icon which is created whileinstallation or you can open it by going to “Start” menu using following path.

    "C:\Program Files\Nex Programmer\AVR Bootloader Setup\"

    Figure 2.47

    Step5: Identify the COM port used by the USB port as mentioned in the section 2.6.2.3Select the COM port, in this case COM5 is selected.Set he baud rate at 115200bpsSelect Microcontroller as ATMEGA128Select the .hex file to be loaded by clicking on the brows button

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 37

  • 8/17/2019 ATMEGA 128 Development Board

    38/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

     Figure 2.48

    Step6:

    Click on the “Program” button to start the programmingIf the microcontroller is programmed successfully it will show the below message

    Figure 2.49

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 38

  • 8/17/2019 ATMEGA 128 Development Board

    39/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    If error occurs then repeat the all steps from step1. Otherwise press the reset the microcontrollerusing the reset switch to execute the loaded .hex code.

    Note:  Section 2.7 and 2.8 describes how to use In System Programming (ISP) basedmicrocontroller programmers. If you use ISP then boot loader might get erased. If boot loader is

    erased then AVR Boot loader from NEX Robotics cannot be used any more.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 39

  • 8/17/2019 ATMEGA 128 Development Board

    40/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.7 Loading your code on the ATmega128 microcontroller using AVR USB

    programmer (STK500v2) from NEX Robotics

    This is the second option for loading the program. NEX AVR USB ISP STK500V2 is a highspeed USB powered STK500V2 compatible In-System USB programmer for AVR family of

    microcontrollers. The compatibility with different window platform is given in below table.

    Compatibility Chart

    Operating System AVR Studio (CDC) Avrdude (HID)

    Windows XP YES YES

    Windows Vista X YES

    Windows 7 X YES

    Table 2.1

    2.7.1 Driver Installation

    Figure 2.50: NEX AVR USB ISP STK500V2 programmer from NEX Robotics

    Jumper Description

    J1: If inserted, provides 5V at VTG (pin no.2) of ISP connector. If removed 0V at VTG (pinno.2) of ISP connector. In default mode, this jumper is not inserted.

    J2: If inserted, enables UBS HID mode. If removed enables USB CDC mode. In default mode,

    this jumper is not inserted.

    J3: If inserted, enables slow clock speed (for 32 KHz to 1MHz speed microcontrollers). Ifremoved enables normal clock speed. In default mode, this jumper is not inserted.

    First we need to install driver. The driver installation for CDC mode and HID mode areexplained in details in the following sections.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 40

  • 8/17/2019 ATMEGA 128 Development Board

    41/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Driver Installation

    Case 1: Installing drivers for STK500 CDC Mode

    Download software package from NEX Robotics website and unzip the contents on your local

    drive. This zip file is containing documentation, driver files and Avrdude software. You can alsocopy it from documentation CD.

    1. If connected, disconnect programmer from PC and remove HID/CDC jumper (J2). Nowreconnect programmer to PC and observe the task bar for “Found New Hardware” message.

    Figure 2.51

    2. After identifying the hardware, the windows driver installation wizard should start. Select“No, not this time” and click next to continue.

    Figure 2.52

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 41

  • 8/17/2019 ATMEGA 128 Development Board

    42/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    3. Select “Install from a list of specific location” and click next to continue.

    Figure 2.53

    4. Browse to AVRUSBSTK500\Drivers directory and click next to continue.

    Figure 2.54

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 42

  • 8/17/2019 ATMEGA 128 Development Board

    43/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    5. In the next window click Continue Anyway to proceed.

    Figure 2.55

    6. After successful installation of drivers following window will appear. Click finish to completethe installation.

    Figure 2.56

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 43

  • 8/17/2019 ATMEGA 128 Development Board

    44/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    7. To identify the COM port assigned to NEX AVR USB programmer, refer to section 2.6.2.4.

    Note : NEX AVR USB ISP STKV2 programmer use 10 pin FRC connector for ISP whileATMEGA128 on Development Board uses 6 pin FRC connector for programming. We need touse AVR ISP adaptor to convert 10 pin to 6 pin connector which is available on NEX Roboticswebsite.Connect AVR ISP adaptor between ATMEGA128 plug-in module ISP socket on controllerboard and AVR USB ISP STKV2 programmer. Insert 6 pin FRC cable in the ISP socket presenton the ATMEGA 128 socket of the ATMEGA128 microcontroller Plug-In module.

    Figure 2.57

    Turn ON the ATMEGA128 Development Board.

    8. Open AVR Studio from Start Menu. Click Con button on the tool bar to open Connect Dialog.

    Figure 2.58

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 44

  • 8/17/2019 ATMEGA 128 Development Board

    45/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    9. In the connect dialog, select platform as STK500, select appropriate port and click connect. IfConnect Dialog reappears, then recheck that the COM port is available and try again.

    Figure 2.59

    10. In the next window, click cancel to skip firmware upgrade.

    Figure 2.60

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 45

  • 8/17/2019 ATMEGA 128 Development Board

    46/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    11. After clicking cancel, AVR Studio will open STK500 interface. In the main tab, select theappropriate microcontroller and read its signature. Observe that the signature matches theselected device.

    Figure 2.61

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 46

  • 8/17/2019 ATMEGA 128 Development Board

    47/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    12. Select correct “Fuse” setting before programming ATMEGA128. Do not change them unlessyou have very clear understanding of the fuse settings. Below Figure shows the Fuse setting forATmega128 Microcontroller. This information is only given for the reference.

    Figure 2.62

    Figure 2.63

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 47

  • 8/17/2019 ATMEGA 128 Development Board

    48/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Go the “Fuse” tab while development board is powered on and STK500V2 USB ISPprogrammer is connected. Press “Read” button. All the fuse settings will be visible.Brown-out detection is disabled.JTAGEN is set at Brown-out detection at VCC=2.7VBoot size is at 2048 words with Boot address = $F800

    SUT_CKSEL is set at External crystal greater than 8MHz with Start-up time of 64msIf needed you can set appropriate Fuse setting and write it by pressing “Program” button.

    13. In the Program tab, select the appropriate hex file and click program to load the hex file inthe microcontroller.

    Figure 2.6414. The programming status can be observed in the bottom area of the window.

    Figure 2.65

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 48

  • 8/17/2019 ATMEGA 128 Development Board

    49/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Case 2: Installing drivers for HID mode (Works on all windows operating systems)

    1. If connected, disconnect programmer from PC and insert HID/CDC jumper. Now reconnectprogrammer to PC and observe the task bar for “Found New Hardware” message.

    2. HID mode does not require additional drivers. It uses generic windows drivers.

    3. Go to Device Manager and observe that new Human Interface Device (HID) is installed. Ifthere are other HID devices connected to PC, you may optionally identify each device byviewing its properties.

    Figure 2.66

    4. Before proceeding ensure that you have AVRDude.exe and AVRDude.conf on your PC.These files are available in the zip file that was downloaded earlier from NEX Robotics website.

    Turn off the ATmega128 Development Board.

    NEX AVR USB ISP STKV2 programmer use 10 pin FRC connector for ISP, while ATmega128Development Board uses 6 pin FRC connector for programming. We need to use AVR ISPadaptor to convert 10 pin to 6 pin connector which is available on NEX Robotics website.

    Connect AVR ISP adaptor between ATmega128 plug-in module ISP socket on controller boardand AVR USB ISP STKV2 programmer. Insert 6 pin FRC cable in the ISP socket (shown infigure on section 1.3) of the ATmega128 microcontroller Plug-In module.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 49

  • 8/17/2019 ATMEGA 128 Development Board

    50/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 2.67

    Turn ON the ATMEGA128 Development Board.

    5. Go to Start Menu>Run and type “cmd” to open command prompt.

    Figure 2.68

      6. On the command prompt, type the path of the folder that contains avrdude.exe andavrdude.conf files. For e.g. refer fig. below.

    Figure 2.69

    7. On the command line type the command as shown in the fig. below. Here -p m128refers to themicrocontroller part number. The last section after ‘–U’ in quotes specifies the location of hexfile, that is to be load on microcontroller.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 50

  • 8/17/2019 ATMEGA 128 Development Board

    51/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 2.70

    8. Press enter. You should see the programming status in the command prompt window. If thereis any error, recheck ISP connection and command line parameters.

    Figure 2.71

    After successful loading of the “buzzer_test.hex” you will hear beeping sound being ON-OFFcontinuously after some delay.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 51

  • 8/17/2019 ATMEGA 128 Development Board

    52/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.8 Loading your code on the ATMEGA128 Development Board using

    ATMEL’s AVRISP mkII Programmer

    AVRISP mkII programmer from the ATMEL is the most versatile programmer. It is very easy touse and has more features. Only flip side is that its bit expensive.

    Figure 2.72: AVRISP mkII

    Step 1: Connect AVRISP mkII to the PC. It will install driver automatically provided that USBdriver installation option is selected while installing AVR Studio. For more details refer toFigure 2.13.

    Start AVR StudioGo to “Tools tab and click on “Program AVR”. Select connect option.Following window will open.

    Figure 2.73

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 52

  • 8/17/2019 ATMEGA 128 Development Board

    53/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 2.74

    Step 2: Select “AVRISP mkII”, select “USB port” and press “Connect”.

    Following window will open.

    Step 3:  Insert 6-pin connector of AVRISP mkII in the 6-pin ISP Socket of ATMEGA128Microcontroller plug-in module, and turn on the power.

    Step 4: Go to Main tabSelect “ATMEGA128” microcontroller.Click on the “Read Signature” button.It will read the signature and if its matches with the microcontroller signature then we are readyto load hex file on the ATMEGA128 Microcontroller.

    Figure 2.75

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 53

  • 8/17/2019 ATMEGA 128 Development Board

    54/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    If ISP does not work properly then try to reduce the ISP frequency and try it again.

    Figure 2.76: Changing ISP frequency if required

    Step 5: Go to “Program” tab.Check on Erase device before programming and Verify device after programming check box.Browse and select the desired hex file in the flash sectionPress “Program” buttonLook at the comments at the bottom to verify that hex file is loaded in the flash.

     Figure 2.77

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 54

  • 8/17/2019 ATMEGA 128 Development Board

    55/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    2.8.1 Fuse settings for ATMEGA128 microcontroller

    Correct Fuse settings are done in the ATmega128 microcontroller before shipping outATmega128 Development Board. Do not change them unless you have very clear understanding

    of the fuse settings. Below Figure shows the Fuse setting for ATmega128 Microcontroller. Thisinformation is only given for the reference.

    Figure 2.78

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 55

  • 8/17/2019 ATMEGA 128 Development Board

    56/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 2.79: Fuse settings of ATMEGA128 microcontroller

    Go the “Fuse” tab while ATMEGA128 Development Board is powered on and AVRISP mkII isconnected. Press “Read” button. All the fuse settings will be visible.

    Brown-out detection is disabled.JTAGEN is set at Brown-out detection at VCC=2.7VBoot size is at 2048 words with start address = $F800SUT_CKSEL is set at External crystal greater than 8MHz with startup time of 64msIf needed you can set appropriate Fuse setting and write it by pressing “Program” button.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 56

  • 8/17/2019 ATMEGA 128 Development Board

    57/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    3.0 Hardware Description

    In this chapter various components mounted on the board and their principal of operation isexplained in detail. It is very important that you go through this chapter before starting to use theATMEGA128 Development Board.

    3.1 Power and IO Port Configuration

    Figure 3.1 Power and IO Port configuration

    3.1.1 Power section

    ATMEGA128 Development board can be powered by 9 to 14V AC /DC supply. You can useany AC adaptor or SMPS which can supply 9V to 14V DC and at least 1Amp current. Board hasonboard bridge rectifier, filter capacitors and 7805 voltage regulator with heat sink which cansupply up to 1Amp current at regulated 5V. Power of the board can be turned on or off usingpower switch.

    3.1.2 I/O PORT FRC connector pin connections

    ATMEGA128 has many 8 bit ports. To make interfacing simple all the ports are taken out onstandard 10 pin FRC connector. While pin number 1 to 8 represents bit 0 to bit 7 of the port andpin no. 9 and 10 represents 5V and ground.

    Pin No. Pin Function1 Pin 0 of PORT X

    2 Pin 1 of PORT X

    3 Pin 2 of PORT X

    4 Pin 3 of PORT X

    5 Pin 4 of PORT X

    6 Pin 5 of PORT X

    7 Pin 6 of PORT X

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 57

  • 8/17/2019 ATMEGA 128 Development Board

    58/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    8 Pin 7 of PORT X

    9 5V-1A output of 7805 voltage regulator

    10 Ground

    Table 3.1 I/O Port Header Configuration

    Note: X corresponds to any port name from PORTA to Port J.

    3.1.3 Power Port pin connections

    Development board has a dedicated power port which is common in all the development boardsof the NEX Robotics. It can give regulated Vin, 5V to the external device.

    Pin No. Pin Function

    1 5V 1A output of 7805 voltage regulator

    2 5V 1A output of 7805 voltage regulator

    3 Ground

    4 Ground5 Vin DC (Input supply – 1.2V DC drop due to bridge rectifier)

    6 Vin DC (Input supply – 1.2V DC drop due to bridge rectifier)

    7 NC

    8 NC

    9 NC

    0 NC

    Table 3.2 Power Port configuration

    Warning: Never ever connect power port to any of the I/O port or interface port. It willimmediately damage the circuit.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 58

  • 8/17/2019 ATMEGA 128 Development Board

    59/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    3.2 LED Interface 

    ATMEGA128 Development Board has 8 LEDs connected to 10 pin FRC header for display /debug purpose. Each LED has 4.7K ohm series resistor for current limiting. 10 pin LED headercan be connected to any port header using FRC cables provided with the board.

    Figure 3.2 LED Schematic

     

    Figure 3.3 LEDs configuration

    LED Connections

    • For connecting a single LED, connect 1-1 cable between a single pin of LED header andI/O pin.

    • For using entire eight LEDs connect the 10-pin FRC cable between LED Header and the8-bit IO port header.

    Application example:

    For controlling LEDs when switch is pressed refer to the example code on “IO interfacing”which is located in the experiments folder in the documentation CD.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 59

  • 8/17/2019 ATMEGA 128 Development Board

    60/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    3.3 Switch Interface

    ATMEGA128 Development Board has 8 Switches connected to 10-pin FRC Header. EachSwitch has 4.7K ohm Pull-Up resistor as shown in Figure 3.4. The switch header can beconnected to any port of the microcontroller using 10 pin FRC cables provided with the board.

    Figure 3.4 Switch Schematic

    Figure 3.5 Switch configuration

    When switch is not pressed it gives logic 1 output because of 4.7K ohm pull-up resistor. When

    switch is pressed it gives logic 0 output.

    Switch Connections

    • For connecting a single switch, connect 1-1 cable between a single pin of switch headerand I/O pin.

    • For using entire eight switches connect the 10-pin FRC cable between switch header andthe 8-bit IO port header.

    Application example:

    For controlling LEDs when switch is pressed refer to the example code on “IO interfacing”which is located in the experiments folder in the documentation CD.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 60

  • 8/17/2019 ATMEGA 128 Development Board

    61/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    3.4 RC Servo Motor Interface

    The ATMEGA128 Development board allows independent control of 8 RC servo motors. TheRC servo motor requires (Pulse Width Modulation) PWM signal, VCC and GND for itsoperation. The servo connector as shown in Figure.3.6 provides these connections, where you

    can connect the servo motors directly. The PWM inputs are obtained from servo header which inturn can be connected to any IO port using FRC cables. The power for the servo motors shouldbe provided from the external supply through the terminal block as board will not be able tosupply sufficient current to the servo motors. The connection details are shown in Figure 3.7.

    Figure 3.6 Schematic of the servo motor

    Figure 3.7 Servo configuration

    Servo Connections

    • For connecting a single servo, connect 1-1 cable between a required pulse input pin ofservo header and I/O pin. Also give 5 to 6V DC for powering up servo motor via theterminal block connector.

    • For using all eight servos, connect the FRC cable between servo and the 8-bit IO portheader. Also connect the +Ve pin terminal block connector to 5V with the externalsupply and give 5 to 6V DC for powering up servo motor via the terminal block

    connector.

    Application Example: 

    Refer to the experiment “Servo Control” which is located in the “experiments” folder in thedocumentation CD

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 61

  • 8/17/2019 ATMEGA 128 Development Board

    62/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    3.5 RS232 Serial Communication

    ATMEGA128 development board has onboard MAX232 (RS232 to serial converter) IC forRS232 serial port interfacing. ATMEGA128 has 2 serial ports. You can connect MAX232 to anyof the serial port by shorting UART0 jumpers. When you use Serial Port remove USB jumper

    near the POWER PORT as shown in figure 2.30.

    Figure 3.8 Basic Schematic of the RS232 Interface

    Figure 3.9 RS232 communication configuration on board

    RS232 communication Connection

    You need to do the following connection for running the example experiment given in theDocumentation CD,

    • Insert the 2-pin jumpers on the RXD0 and TXD0 connector below theATMEGA128socket.

    • Insert the DB9 serial cable between the PC and the serial DB9 port of Developmentboard.

    Note: Remove USB jumper near the POWER PORT as shown in figure 2.30.

    Application Example:

    Refer to the experiment “UART0_Serial” which is located in the folder experiments in thedocumentation CD.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 62

  • 8/17/2019 ATMEGA 128 Development Board

    63/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    3.6 USB Communication

    ATMEGA128 development board has onboard FT232 based USB to serial converter. It gives outand accepts serial signals at the TTL / CMOS level. To connect FT232 USB to serial converter toany serial port use 1 to 1 connector. You can also use all the other serial pins of the FT232 such

    as DTR, DSR etc. to implement flow control. You can also connect USB to Serial converter tothe UART 0 and use bootloader to load the hex file.

    Figure 3.10 Schematic of the USB communication

     

    Figure 3.11 USB communication configuration on board

    Prior to use the USB Module, we need to install the USB to RS232 Driver on the PC. Refer theSection 2.6.2.2 and 2.6.2.3 for Driver Installation and Identify and changing the COMPORTNumber.

    In the terminal program select the COMPORT that is assigned by the PC and you are ready forUSB communication.

    USB to Serial Converter Connection

    You need to do the following connection for running the example experiment given in theDocumentation CD,

    • Insert the 2-pin jumpers on the RXD0 and TXD0 connector near the Power Port header.

    • Insert the USB cable between the PC and the USB port of Development board.

    Note: Remove the 2-pin jumpers on the RXD0 and TXD0 connector below the ATmega128socket if inserted.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 63

  • 8/17/2019 ATMEGA 128 Development Board

    64/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Application Example:

    Refer to experiment “UART0 USB” from “Experiments” folder from the documentation CD

    3.7 XBEE Wireless Communication

    XBee wireless module from the Digi International is an easy to use module for wireless serialcommunication. 2.4GHz XBee wireless module has 16 frequency separated channels. On eachchannel you can have many simultaneous communications by giving different PAN ID to eachdevice. You can do lots of things with this device. It can be configured by XCTU software fromDigi. For more details, read the XBee wireless module documentation from the documentationCD which is located in the “datasheet” folder.

    The ATMEGA128 Development Board has standardized 20 pin socket for the XBee wirelessmodule along with the 3.3V supply for the module. You can connect TXD and RXD pins of theXBee module to the any RXD, TXD pins of the microcontroller. It is also possible to connect

    FT232 USB to serial converter to XBee module directly and use it as XBee USB wirelessmodule.

    Figure 3.12 Schematic of the Xbee communication

    Figure 3.13 XBee communication configuration

    XBee Connections

    TXD and RXD pins of the XBee wireless module can be directly connected to the RXD andTXD of the UART 1 directly by shorting XBee header. If you want to connect XBee to different

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 64

  • 8/17/2019 ATMEGA 128 Development Board

    65/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    UART then use 1 to 1 connectors supplied with the boards for the connections. For more detailsrefer to Figure 3.13.Note: Remove the 2-pin jumpers on the RXD1 and TXD1 connector below the ATMEGA128socket.

    Application Example:

    Refer to experiment “UART1_XBee” from “Experiments” folder from the documentation CD

    3.8 SD/MMC Card Interface

    ATMEGA128 development board has onboard SD/MMC card holder. SD/MMC card can beused as external removable storage media for the data logging purpose. The SD/MMC card isaccessed in two modes, as SD/MMC mode or SPI mode. For the Simplicity we are using SPImode. The SPI signals are taken on the SD/MMC header (10pin FRC) and a SD/MMC socket isprovided to insert the MMC card or SD with MMC adaptor.

    SD/MMC card pin configuration:

    Pin No.(10pin FRC) Pin Function

    1(CS) Chip select input for SD/MMC card

    2(SCK) Clock signal input for SD/MMC card

    3(MOSI) Serial Data input for SD/MMC card

    4(MISO) Serial Data output for SD/MMC card

    5 to 10 Not connected

    Table 3.3: SD/MMC card connections

    Figure 3.14. Schematic of SD/MMC card interfacing

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 65

  • 8/17/2019 ATMEGA 128 Development Board

    66/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 3.15 SD/MMC configuration on board

    SD/MMC card Connections

    Connect 10 pin FRC wire between SD/MMC header and Port B10 pin FRC wire connects the SD/MMC card with the uC in the following way

    • CS pin of SD/MMC SS pin of the PORTB• SCK pin of SD/MMC SCK pin of the PORTB• SDI pin of SD/MMC MOSI pin of the PORTB• SDO pin of SD/MMC MISO pin of the PORTB

    Application Example:

    Refer to experiment “SD card interface” from “Experiments” folder from the documentation CD

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 66

  • 8/17/2019 ATMEGA 128 Development Board

    67/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    3.9 Motor Controller Driver IC L293D Interface

    L293D dual DC motor driver can drive 2 DC motors with up to 4.5V to 36V and up to 600mAcurrent rating each or a single bipolar stepper motor. To change the direction of the motor,appropriate logic levels (High/Low) are applied to L293D direction control Pins. Velocity

    control is done using the Pulse Width Modulation (PWM), the motor power supply is separatedfrom the logic supply. The input and control signal are taken from the L293D motor driver IC onL293D Header (10pin FRC). Output from motor driver and the motor power supply are taken onseven pin berg-strip.

    Figure 3.16 L293D Motor driver configuration

    L293D logic input header:

    Pin No. Pin Name. Pin Function3 Input4 Direction Control Logic input pin B2

    4 Inhibit1 Driver 1 Enable Pin

    5 Inhibit2 Driver 2 Enable Pin

    6 Input3 Direction Control Logic input pin B1

    7 Input2 Direction Control Logic input pin A2

    8 Input1 Direction Control Logic input pin A1

    10 GND Ground pin

    1,2&9 NC Not connected

    Table 3.4

    L293D output connector:

    Pin N0. Pin Name Pin Function1 GND Ground

    2 VINB Regulated supply from the bridge rectifier with current rating ofthe AC adaptor / SMPS used.

    3 VINE Power supply to the motor drive block inside the L293D( Connect the supply 5V to 36V)

    4 A Channel A1 output

    5 B Channel A2 output

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 67

  • 8/17/2019 ATMEGA 128 Development Board

    68/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    6 C Channel B1 output

    7 D Channel B2 output

    Table 3.5

    Figure 3.17 Schematic of L293D Motor Driver interfacing

    L293D Connections

    Interface logic connections:

    Logic supply and Ground pin of L293D are already connected to the 5V and ground. We need toconnect the logic input pins with the microcontroller. 1 to 1 connectors are used for the logicconnections.

    Following table shows the pin connections done in the application example “L293D_ demo”which is located in the “Experiments” folder in the documentation CD.

    L293D Logic Input Header PORTE

    3 (Input4) PE24 (Inhibit1) PE3

    5 (Inhibit2) PE4

    6 (Input3) PE5

    7 (Input2) PE6

    8 (Input1) PE7

    Table 3.6

    Output connections:

    To power motor driver block inside the L293D you need to connect pin 3, VINE (Vin External)of the L293D output connector to either VINB (Vin supply of Board) or the external power

    source between 5V to 36V DC. Use VINB only if AC adaptor /SMPS which is powering theboard can give sufficient current to the motor without causing huge current surges.

    L293D Output Connector Output Connection

    GND NC

    VINB NC

    VINE 5V Supply Pin

    A LED Header Pin no. 1

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 68

  • 8/17/2019 ATMEGA 128 Development Board

    69/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    B LED Header Pin no. 2

    C LED Header Pin no. 3

    D LED Header Pin no. 4

    Table 3.7

    Application Example: Refer to experiment “L293D_demo” from “Experiments” folder from thedocumentation CD

    3.10 High Current Driver ULN2003 InterfaceULN2003 can drive 7 different loads, each with up to 500mA current. It can be used for drivingexternal inductive and resistive loads such as relays, solenoids, bulbs, heating elements, unipolarstepper motor etc.

    Figure 3.18 ULN2003 High current driver configuration

    Figure 3.19 Schematic of ULN2003 interface

    Connections:

    Input logic signals to drive ULN2003 are connected to standard 10 pin FRC connector. Table 3.8shows the connection diagrams.

    ULN2003 logic input header:

    Pin No. Pin Function

    1 to 7 (IN- IN7) Logic input signal for channel 1 to 7Table 3.8

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 69

  • 8/17/2019 ATMEGA 128 Development Board

    70/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    ULN2003 output connector:

    Pin Name. Pin Function

    1 to 7(OUT1-OUT7)

    Channel output from 1 to 7 to drive the load (With respect toVINE)

    VINB Regulated supply from the bridge rectifier with current rating

    of the AC adaptor / SMPS used.VINE Power supply to the ULN2003 and cathode of the built-in

    flyback diode. ( Connect the supply 5V to 50V)

    GND GroundTable 3.9

    Output connections:

    To drive the external load you need to connect pin 3, VINE (Vin External) of the L293D outputconnector to either VINB (Vin supply of Board) or the external power source between 5V to 50VDC. Load should be connected between VINE and pin OUT1 to OUT7. Use VINB only if ACadaptor /SMPS which is powering the board can give sufficient current to the motor without

    causing huge current surges.

    Application Example:

    Refer to experiment “ULN2003 interface” from “Experiments” folder from the documentationCD

    3.11 RTC Interface

    ATMEGA128 development board has DS1307 RTC (Real Time Clock) for time keeping. It hasbattery backup for continues clock operation in absence of external power. RTC can be used in

    embedded applications like Utility Metering, hand held devices GPS, Spying gadgets, vendingmachines, consumer electronics etc. RTC can be interfaced with the microcontroller over I2Cbus. For more details on the RTC, refer to DS1307 datasheet which is located in the “datasheet”folder for the documentation CD.

    Figure 3.20 Schematic of RTC interfacing

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 70

  • 8/17/2019 ATMEGA 128 Development Board

    71/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Figure 3.21 RTC configuration on board

    RTC Connections

    Connect SCK and SDA pins of the DS1307 with the uC by shorting jumpers as shown in theFigure 3.21. Make sure that RTC battery has sufficient charge level.

    The SQW pin on the RTC header is used to indicate the alarm condition, if the respective controlbits are properly set in the RTC chip.

    Application Example:

    Refer to experiment “RTC demo” from “Experiments” folder from the documentation CD

    3.12 LCD Interface

    To interface LCD with the microcontroller in default configuration requires 3 control signals and

    8 data lines. This is known as 8 bit interfacing mode which requires total 11 I/O lines. To reducethe number of I/Os required for LCD interfacing we can use 4 bit interfacing mode whichrequires 3 control signals with 4 data lines. In this mode upper nibble and lower nibble ofcommands/data set needs to be sent separately. The three control lines are referred to as EN, RS,and RW.

    The EN line is called "Enable" and it is connected to PC2. This control line is used to tell theLCD that microcontroller has sent data to it or microcontroller is ready to receive data fromLCD. This is indicated by a high-to-low transition on this line. To send data to the LCD, programshould make sure that this line is low (0) and then set the other two control lines as required andput data on the data bus. When this is done, make EN high (1) and wait for the minimum amountof time as specified by the LCD datasheet, and end by bringing it to low (0) again.

    The RS line is the "Register Select" line and it is connected to PC0. When RS is low (0), the datais treated as a command or special instruction by the LCD (such as clear screen, position cursor,etc.). When RS is high (1), the data being sent is treated as text data which should be displayedon the screen.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 71

  • 8/17/2019 ATMEGA 128 Development Board

    72/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    The RW line is the "Read/Write" control line and it is connected to PC1. When RW is low (0),the information on the data bus is being written to the LCD. When RW is high (1), the programis effectively querying (or reading from) the LCD. The data bus is bidirectional, 4 bit wide and is connected to PC4 to PC7 of the microcontroller.

    The MSB bit (DB7) of data bus is also used as a Busy flag. When the Busy flag is 1, the LCD isin internal operation mode, and the next instruction will not be accepted. When RS = 0 and R/W= 1, the Busy flag is output on DB7. The next instruction must be written after ensuring that thebusy flag is 0.

    Fig 3.22 LCD configuration

    Fig 3.23 Schematic of LCD interfacing

    Pin No. Pin Function

    1(RS) Data /Instruction Register Select

    2(R/W) Read/Write Control

    3(E) Enable

    4(Buzzer i/p) Input for buzzer (not used in this example)

    5-8(DB0-DB3) Data line 0 to 3

     Table 3.10: LCD connections

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 72

  • 8/17/2019 ATMEGA 128 Development Board

    73/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    LCD Connections

    LCD requires minimum seven I/O pins and two supply pins VCC and GND for its operation.The LCD header provides all the necessary connections for controlling LCD using a single 8-bitport.

    • For using LCD, connect the 10pin FRC cable provided with the board between LCD

    header and PORT C of the microcontroller.• Connect the 2pin jumper at LCD_BKL jumper connector if backlight is required.

    • Adjust the Contrast if required with LCD contrast Pot.

    Application Example:

    Refer to experiment “LCD interfacing” from “Experiments” folder from the documentation CD.

    3.13 Buzzer Interface

    The buzzer can be used as attention seeker or to indicate any event. Input pin of the buzzer is

    connected to the Pin no. 4 of the LCD header.

    Fig 3.24 Buzzer connections

    Fig 3.25 Schematic of Buzzer interfacing

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 73

  • 8/17/2019 ATMEGA 128 Development Board

    74/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    Buzzer Connection

    The Buzzer is connected to LCD header pin no. 4. For interfacing the buzzer, either use 1 to 1connector wire or use 10 pin FRC connector.

    Application Example:

    Refer to experiment “Buzzer_test” from “Experiments” folder from the documentation CD.

    3.14 ADC Interface

    ATMEGA128 has 16 ADCs connected to PORTF and PORTK. To test ADCs, threepotentiometers are connected on the board. They can be connected to ADC 0, ADC 1 and ADC 2by shorting jumpers on the ADC connection header as shown in the Figure 3.26.

    Fig 3.26 Potentiometer & ADC Header

    Fig 3.27 Schematic of ADC interfacing

    ADC Header (3 pin 2 line Berg strip):

    Pin No. Pin Function

    1 (POT no.0) variable analog output

    2 ADC0 input of ATMEGA128

    3 (POT no.1) variable analog output

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 74

  • 8/17/2019 ATMEGA 128 Development Board

    75/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    4 ADC1 input of ATMEGA128

    5 (POT no.2) variable analog output

    6 ADC2 input of ATMEGA128

    Table 3.11

    Note: You can also connect output of the potentiometer to any other microcontroller pin by

    using 1 to 1 connector wire.

    Application Example: Refer to experiment “ADC LCD” from “Experiments” folder from thedocumentation CD.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 75

  • 8/17/2019 ATMEGA 128 Development Board

    76/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    4. Application Examples

    The following examples codes are given in Documentation CD. All the codes are written usingthe AVRStudio Version 4.17. The installation of the software is explained chapter 2

    For easier learning follow the experiments in the sequence mentioned below.

    4.1 Buzzer test

    This program will make buzzer beep.To make Buzzer On and off third pin of the PORTC is used. To turn on the buzzer, makePORTC3 pin logic 1 and logic 0 to off.

    4.2 IO interfacing

    This experiment demonstrates simple Input and Output operation. When switch is pressed the

    respective LED will glow.

    4.3 ULN2003 interface

    This experiment demonstrates the ULN2003 testing .Alternate input made logic high andrespective LEDs are 'ON'

    4.4 L293D demo code

    This experiment demonstrates L293D driver for motor control application using PWM

    4.5 LCD interfacing

    This experiment demonstrates LCD interfacing in 4 bit mode.

    4.6 ADC LCD

    In this experiment three POTs are connected to the three channels of ADC module ofATMEGA128 Microcontroller and converted digital result is displayed on the LCD.

    4.7 UART0 Serial

    In this program Microcontroller receives data from the PC, adds one to the ASCII value andechoes back to the PC through Serial port.

    4.8 UART1 XBee

    In this program Microcontroller receives data from the PC, adds one to the ASCII value andechoes back to the PC through Xbee port.

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 76

  • 8/17/2019 ATMEGA 128 Development Board

    77/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    4.9 UART0 USB

    In this program Microcontroller receives data from the PC, adds one to the ASCII value andechoes back to the PC through USB port.

    4.10 RTC demoThis program demonstrate the interfacing of External RTC (DS1307) in I2C interfacing mode,we utilise the TWI module of 640microcontroller, in master mode with freq of 100 KHz.

    4.11 Servo control

    In this program we demonstrate the servo motor interfacing.Six servos will be controlled with TIMER1 interrupts to get the better resolution. Servo motorsmove between 0 to 180 degrees proportional to the pulse train with the on time of 1 to 2 ms withthe frequency between 40 to 60 Hz. 50Hz is most recommended. 

    4.12 SD card interface

    This application is for SD card interfacing.It will first initialise the SD card and write at 1st block of 512 bytes, and then it read the sameblock. Finally compared for valid read

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 77

  • 8/17/2019 ATMEGA 128 Development Board

    78/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    5.0 Schematics

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 78

  • 8/17/2019 ATMEGA 128 Development Board

    79/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL

    © NEX Robotics Pvt. Ltd. and ERTS Lab IIT Bombay, INDIA 79

  • 8/17/2019 ATMEGA 128 Development Board

    80/80

    ATMEGA128 DEVELOPMENT BOARD MANUAL