Mechatronics Lab with AVR ATmega16 and I/O Board

Originally, I used PIC16F877 microcontroller to teach mechatronics class (see the page PIC & I/O Board). While most PIC compilers are expensive, AVR has WinAVR, which is a open source compiler, widely used and supported by a huge community. So I wrote example programs for AVR ATmega16 to use with ET EXP4 I/O board in the same way as I did for the PIC.

  • ET-CP-AVR v3 Board
    ET-CP AVR V3ET-CP-AVR v3 Board is developed by ETT company. It uses AVR ATmega16 with an 8 MHz oscillator. I chose this board because it is designed to conveniently connect with ET-EXP I/O Board through 34-pin IDC connectors. The board is shipped with AVR-ISP programmer via a parallel port with PonyProg program. For short, I will call this AVR board in the rest of this page.

  • ET-EXP4 I/O Board
    ET-EXP4 I/O BoardET-EXP4 I/O Board is also developed by ETT company. It contains many input/output modules that is often used in mechatronic systems such as LEDs, 7-segment, dot-matrix LED, LCD display, matrix switches, stepper and dc motor, relay, speaker, and DAC. The AVR board is designed to conveniently connect with ET-EXP I/O Board through 34-pin IDC connectors. Because both boards were made by the same company, so the pin configurations are matched. This device will be later referred to as I/O board.

  • Wiring AVR and I/O Boards
    The picture below shows the cable connection from AVR board to I/O board as follows:

    • Connect a 34-pin cable from both boards.
    • Connect a single wire from 5V pin on AVR board to VCC pin on I/O board (34-pin connector doesn't supply 5 volt to I/O board).
    • On I/O board, connect 14-pin cables from PORTA, B or C to I/O device(s), as instruct by each tutorial.
    • Connect 10-pin cable from AVR-ISP programmer to AVR board.
    • Connect DC adapter to power the boards.

    Connect AVR to ET-EXP4 I/O

  • Software
    • WinAVR is an open source software development tools for the Atmel AVR microcontrollers on Window platform. It includes the GNU GCC compiler for C language. Since the compiler was built from GCC for AVR chips, the compiler alone is called AVR-GCC. WinAVR can be download at the WinAVR page.
    • PonyProg is a programmer software that can be used with parallel AVR-ISP programmer. It is important to setup fuse bits correctly, or the AVR chip cannot be programmed again. Read the instruction how to use PonyProg program with ATmega16 in the document below. See PonyProg page for more detail.
    • Procyon AVRlib is a library of easy-to-use C functions for a variety of common tasks (like LCD, I2C, SPI, etc) using AVR processors. The source code is available to download at Procyon AVRlib page. I install AVRlib manually and use makefile to compile the code without any problems.
    Note: How to Compile Source Files on Command Line
    I find that using AVR-GCC with AVRlib library on command line is simpler and easier than with AVR Studio (Window GUI). However, we need to modify makefile (which can be obtained from AVRlib examples) manually. Here is what you need to modify in the makefile.

    • Put the name of target MCU. In my case, it is Atmega16.
    •     MCU = atmega16

    • Put the name of the target file (the file which contains your main() function). For example if I have function main in file ex2_1.c, then I write
    •     TRG = ex2_1

    • Put the name of the directory where you "installed" or unzipped the AVRlib files so the compiler can find them. The directory should not contain spaces in its name or path. For example,
    •     AVRLIB = C:/Code/AVR/avrlib

    • List any C source files which are used by your target files. For example,
    •     SRC = $(AVRLIB)/rprintf.c $(AVRLIB)/timer.c $(AVRLIB)/lcd.c $(TRG).c

    Then, to compile, simply change directory to the source file. Then type command:
    > make clean
    > make

Related Documents (Thai language)

Example Source Codes

The following source codes are made in attempt the match the flow of the mechatronics lab with PIC. To use the source code, you need to download, modify the makefile (check the directory name where you install your AVRlib), and then compile with command make

*Note that there are no lab documents for this page. Please use the lab documents in the page Mechatronics Lab with PIC16F877 and I/O Board for board and wiring setup. You can also find this information in the source code.

Labs*
Source Codes
AVR-GCC
Lab1: Seven-Segment & LED Display ex01_1.zip
ex01_2.zip
Lab2: Character LCD Display ex02_1.zip
Lab3: Dot-Matrix LED Display ex03_1.zip
Lab4: Matrix Keyboard & Switch ex04_1.zip
ex04_2.zip
ex04_3.zip
Lab5: Stepping Motor, Speaker and Relay ex05_1.zip
ex05_2.zip
ex05_3.zip
ex05_4.zip
ex05_5.zip
ex05_6.zip
Lab6: Serial Communication ex06_1.zip
Lab7: Digital-to-Analog Converter (DAC) ex07_1.zip
Lab8: DC Motor Control
Lab9: PWM
Lab10: Analog-to-Digital Converter (ADC)
Lab11: Data Acquisition System (DAS)
Lab12: Window Application with C#
Lab13: Design and Fabrication of a PCB with Eagle