Tag Archive : embedded

/ embedded

Linux is dominating embedded system. It is mainly because of broad support of processor, such as: ARM, MIPS, PowerPC, etc. For some gadget, touch screen is an extra feature, other must have it. Whatever the reason, Linux support it. The fundamental thing in programming a system with touch screen is how to get coordinate of point touched by user.

This article will discuss about how to capture coordinate of point in touch screen. When I write this article I use Castles Technology’s EDC. I won’t disclose internal of the system used, but I should tell you that our discussion could be applied to Linux in general.

Some Knowledge

As usual, before we start we need to know some basic knowledge.

Linux is unix-like operating system. Everything in Linux is a file, including device. They are all stored inside /dev. Your first SCSI disk should be recognized as /dev/sda. Your DVD ROM might be recognized as /dev/sr0 (or /dev/dvd, a symlink to it).

You might also learn that device is categorized mainly as character device and block device. A character device is a class of device which send data by amount of character at a time, while block device will give you a block of data (typically some bytes).

Now direct our focus toward /dev/input. This is the location where device files for our input devices located. By input devices we means mouse, keyboard, or perhaps touch screen. Good, now spot eventX file where X is a number. Well, the number of files is depends on how much input device you have.

So how can we pinpoint the device?

In desktop I can see the /dev/input/by-id or /dev/input/by-path and see to which device they are pointing at. However, we don’t always have this luxury.

ls -la /dev/input/by-id/
ls -la /dev/input/by-path/

Another quick way to figure it out is by inspecting /proc/bus/input/devices. Yet, this might be not the case for most device. Also we need to parse some unneeded information.

cat /proc/bus/input/devices

Next option is dumping the raw data from file. Again this is not always the case.

cat /dev/input/event0 | hexdump -c

Last option is writing a small program, open the device, and read it. This works for me and we will discuss it deeper later.

Preparation

I will leave the idea of “how you can connect to device” to you. I assume you have some way to write a program. We also need a way to direct I/O to device.

I also assume you can produce code for the device. Whether you have compiler inside, or just do cross compilation doesn’t matter.

Last, I assume you know our great programming language, C.

Capturing

This is the sample working code I use to enumerate the device, open it, and capture the coordinate.

#include <stdio.h>
#include <stdlib.h>

/* For open and read data */
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>

/* For directory listing */
#include <sys/stat.h>
#include <dirent.h>

/* Miscs */
#include <limits.h>
#include <string.h>

// We don't care it for now, let it be global.
DIR *dir = NULL;

/* Find first valid device which we can open */
int enum_and_open_dev()
{
    struct dirent *dirent;
    int fd;
    
    // Is it first time? Open it if yes.
    if (!dir)
        dir = opendir("/dev/input");

    if (dir)
    {
        while ((dirent = readdir(dir) != NULL)) {
            if (!memcmp(dirent->d_name, "event", 5)) {
                fd = open(dirent->d_name, O_RDONLY);
                if (fd == -1)
                    continue;   // Not a valid file

                return fd;   // file is opened
            }
        }
        closedir(dir);
        dir = NULL;
        return 0;
}

int get_dev_name(int fd)
{
    char buf[256] = "Unknown";

    /* Print Device Name */
    ioctl(fd, EVIOCGNAME(sizeof(buf)), buf);
    write(ofd, buf, strlen(buf));
}

int touch_screen_getxy(int fd)
{
    struct input_event ev;
    size_t ev_size = sizeof(struct input_event);
    size_t size;
    
    while (1) {
        size = read(fd, &ev, ev_size);
        if (size < ev_size) {
            write(ofd, "Error size when reading", 23);
            return -1;
        }
        
        if (ev.type == EV_ABS && 
            (ev.code == ABS_X || ev.code == ABS_Y))
        {
            sprintf(buf, "%s = %d\n", ev.code == ABS_X ? "X" : "Y", ev.value);
            write(ofd, buf, strlen(buf));
        }
    }
    return 0;
}

int test_()
{
   int fd;

   fd = enum_and_open_dev();
   if (fd == 0) {
      write(ofd, "No readable device found", 24);
      return -1;
   }

   get_dev_name(fd);
   touch_screen_getxy(fd);
}

Just a note, ofd is a file descriptor where will pipe to my host, in other words a debug means for me.

enum_and_open_dev() is a function to enumerate available file in /dev/input/ and trying to open it. In my sample code, I only use the first valid file descriptor. After I got it, I want to know it’s name and then the main dish: the coordinates.

Next?

Just a single point is not enough. What about two or three simultaneous touch (multitouch) ? Well, save it for later.

In this article we will about how to build GCC ARM Toolchain, which is a cross compiler to build ARM program. The built GCC can be used to compile application into ARM’s machine codes. The toolchain then reside on /usr/local path.

For this article, I use:

  1. Slackware64 14.0
  2. GCC 4.9.2
  3. GDB 7.8.1
  4. Binutils 2.24
  5. Newlib 2.1
  6. GMP 6.0.0
  7. MPFR 3.1.2
  8. MPC 1.0.2

Deciding the Target

In ARM, there is a naming convention which explain what toolchain will do. The target alias, or target, is the target of the toolchain. It’s more than just an architecture. The tools on this toolchain will have some profix, such as: arm-none-eabi-gcc, arm-linux-eabi-gcc, etc.

This distinguish one toolchain from native host compiler and have different purpose for each name.

Basically, “arm-none-eabi” is consist of three part:

  1. architecture / processor name. Which is ARM architecture (ARM, Thumb, Thumb-2, etc)
  2. something about OS/libraries. This part is varies. Some have none and other has linux, etc. The ‘none’ means that the toolchains are not targetting specific operating system (aka ‘bare-metal’). ‘unknown’ is the same as ‘none’ while ‘linux’ designed to be used to build programs with glibc under a Linux environment, usually for built for embedded linux ARM devices.
  3. ABIs. This part describes how binary files (libraries, etc) are stored (the actual file formats), and calling conventions, register usage, etc. Some common are gnuabi, eabi, etc.

In this article, we will build arm-none-eabi to make bare metal arm compiler.

Preparation

We will need some disk space (~2GB should be enough). We also need root access to install it on “system-wide”.

Slackware64 14.0 is optional. You can use any linux distribution you like.

We will create a working directory. We will refer it as $ARMGCC, so $ARMGCC/src should really be something like ~/ARMGCC/src (the ~ means your home directory). So go ahead and create following directory structure:

# set aliases
export ARMGCC=~/ARMGCC
export TARGET=arm-none-eabi
export PREFIX=/usr/local

export BINUTILS_BUILD=${ARMGCC}/build/binutils-build
export GCC_BUILD=${ARMGCC}/build/gcc-build
export GDB_BUILD=${ARMGCC}/build/gdb-build

export BINUTILS_SRC=${ARMGCC}/src/binutils-2.24
export GCC_SRC=${ARMGCC}/src/gcc-4.9.2
export GDB_SRC=${ARMGCC}/src/gdb-7.8.1
export NEWLIB_SRC=${ARMGCC}/src/newlib-2.1.0

# make base dir, original archives dir (orig), source code dir (src), 
# and working / building dir (build) 
mkdir ${ARMGCC}{,/{orig,src,build}}

# Make build directory for each component
mkdir ${ARMGCC}/build/{binutils,gcc,gdb}-build

Acquiring the Materials

Download latest packages of GCC, GDB, binutils, and Newlib.You can download it using wget or alternatively download via browser and move it to $ARMGCC/orig. The version we will use is GCC 4.9.0, GDB 7.7, binutils 2.24, and newlib 2.1.0.

cd ${ARMGCC}/orig
wget ftp://ftp.gnu.org/pub/gnu/gcc/gcc-4.9.2/gcc-4.9.2.tar.bz2
wget ftp://ftp.gnu.org/pub/gnu/gdb/gdb-7.8.1.tar.xz
wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2
wget ftp://sources.redhat.com/pub/newlib/newlib-2.1.0.tar.gz

wget ftp://ftp.gnu.org/pub/gnu/gmp/gmp-6.0.0a.tar.xz
wget ftp://ftp.gnu.org/pub/gnu/mpc/mpc-1.0.2.tar.gz
wget ftp://ftp.gnu.org/pub/gnu/mpfr/mpfr-3.1.2.tar.gz

Then, extract them to src directory.

cd ${ARMGCC}/src

tar -jxf ${ARMGCC}/orig/gcc-4.9.2.tar.bz2
tar -Jxf ${ARMGCC}/orig/gdb-7.8.1.tar.xz
tar -jxf ${ARMGCC}/orig/binutils-2.24.tar.bz2
tar -zxf ${ARMGCC}/orig/newlib-2.1.0.tar.gz

Next we need to download some prerequisites, especially GMP (GNU Multiple Precision), MPC (Multiple-Precision Complex), and MPFR (Multiple-Precision Floating Point Reliably) which is used for computation. The prerequisites can be downloaded by invoking following command:

The MPFR, GMP, and MPC is not the latest version, but at least we can build GCC. Suppose your working directory at /home/xathrya/ARMGCC, to obtain MPDR, GMP, and MPC invoke following command:

cd ${GCC_SRC}
./contrib/download_prerequisites

However, the version of GMP, MPC, MPFR, PPL, CLOOG, and ISL is not the latest version. We can switch to the latest version by download the latest version and create symbolic link to it.

cd ${GCC_SRC}

rm {gmp,mpc,mpfr}

tar -Jxf ${ARMGCC}/orig/gmp-6.0.0a.tar.xz
tar -zxf ${ARMGCC}/orig/mpc-1.0.2.tar.gz
tar -zxf ${ARMGCC}/orig/mpfr-3.1.2.tar.gz

ln -s gmp-6.0.0 gmp
ln -s mpc-1.0.2 mpc
ln -s mpfr-3.1.2 mpfr

Building the Toolchains

Building stage is pretty simple. Honestly speaking, the tricky part is about how GCC and built concept and ordering them in correct order.

Binutils

First, built binutils. This will provide lots of useful tools in building ARM libraries and binaries (like objdump, ld, ranlib, etc). Invoke following commands:

cd ${BINUTILS_BUILD}
${BINUTILS_SRC}/configure \
   --target=${TARGET} \
   --prefix=${PREFIX} \
   --enable-interwork \
   --enable-multilib \
   --with-gnu-as \
   --with-gnu-ld \
   --disable-werror \
   --disable-nls
make configure-host
make -j4 all
make install
make clean

You will notice a few configure options that are really critical for getting things to work properly.

  • –target=arm-none-eabi Says we want a compiler to generate binaries for the arm-none-eabi platform.
  • –enable-interwork This allows for assembling Thumb and ARM code mixed into the same binaries (for those chips that support that)
  • –enable-multilib Multilib allows the use of libraries that are compiled multiple times for different targets/build types
  • –enable-shared – enable the creation of the shared libraries.

GCC

Next we will build the GCC. But please note that we are only intereset on C and C++ so we will ignore other language. To built GCC, do this:

cd ${GCC_BUILD}
${GCC_SRC}/configure \
   --target=${TARGET} \
   --prefix=${PREFIX} \
   --enable-interwork \
   --enable-multilib \
   --enable-languages="c,c++" \
   --with-newlib \
   --without-headers \
   --disable-shared \
   --with-system-zlib \
   --with-gnu-as \
   --with-gnu-ld \
   --disable-nls \
   --enable-c99 \
   --enable-long-long \
   --enable-__cxa_atexit
make -j4 all-gcc install-gcc
make clean

Now, the important points are:

  • –enable-languages=”c,c++” – means build C and C++ only.
  • –with-newlib – use Newlib instead of the standard C libraries.
  • –with-headers – this adds a header inlude path during build time and will allow the build to find the newlib header files
  • –enable-__cxa_atexit – allows use of __cxa_atexit, rather than atexit, to register C++ destructors for local statics and global objects and is essential for fully standards-compliant handling of destructors. It also affects the C++ ABI and therefore results in C++ shared libraries and C++ programs that are interoperable with other Linux distributions.
  • –enable-c99 – enable C99 support for C programs.
  • –enable-long-long – enables long long support in the compiler.

Newlib

Now build our newlib

cd ${NEWLIB_BUILD}
${NEWLIB_SRC}/configure \
  --target=${TARGET} \
  --prefix=${PREFIX} \
  --enable-interwork \
  --enable-multilib \
  --with-gnu-as \
  --with-gnu-ld \
  --disable-nls \
  --enable-target-optspace \
  --enable-newlib-reent-small \
  --enable-newlib-io-c99-formats \
  --enable-newlib-io-long-long \
  --disable-newlib-multithread \
  --disable-newlib-supplied-syscalls \
  CFLAGS_FOR_TARGET="
make -j4 all
make install
make clean

GCC (again)

Now that we have our runtime libraries, go back and ginish the GCC build:

cd ${GCC_BUILD}
make all-install

GDB

Optionally you can build GDB. To do so, invoke following:

cd ${GDB_BUILD}
${GDB_SRC}/configure \
   --target=${TARGET} \
   --prefix=${PREFIX} \
   --enable-interwork \
   --enable-multilib
make -j4 all 
make install

And that’s it. You should have them now.

Testing

The toolchain can be tested with the minimal code here:

int main()
{
   return 0;
}

void exit(int code)
{
   while(1);
}

Building GCC AVR Toolchain Cross Compiler

December 11, 2015 | Article, Labs | No Comments

In this article we will about how to build GCC AVR Toolchain, which is a cross compiler to build AVR program. The built GCC can be used to compile application into AVR’s machine codes. The toolchain then reside on /usr/local path.

For this article, I use:

  1. Slackware64 14.0
  2. GCC 4.9.0
  3. GDB 7.7
  4. Binutils 2.24
  5. AVR-libc 1.8
  6. GMP 6.0.0
  7. MPFR 3.1.2
  8. MPC 1.0.2

Preparation

We will need some disk space (~2GB should be enough). We also need root access to install it on “system-wide”.

Slackware64 14.0 is optional. You can use any linux distribution you like.

We will create a working directory. We will refer it as $AVRGCC, so $AVRGCC/src should really be something like ~/AVRGCC/src (the ~ means your home directory). So go ahead and create following directory structure:

# set aliases
export AVRGCC=~/AVRGCC
export TARGET=avr
export PREFIX=/usr/local

export BINUTILS_BUILD=${AVRGCC}/build/binutils-build
export GCC_BUILD=${AVRGCC}/build/gcc-build
export GDB_BUILD=${AVRGCC}/build/gdb-build

export BINUTILS_SRC=${AVRGCC}/src/binutils-2.24
export GCC_SRC=${AVRGCC}/src/gcc-4.9.0
export GDB_SRC=${AVRGCC}/src/gdb-7.7
export AVRLIBC_SRC=${AVRGCC}/src/avr-libc-1.8.0

# make base dir, original archives dir (orig), source code dir (src), 
# and working / building dir (build) 
mkdir ${AVRGCC}{,/{orig,src,build}}

# Make build directory for each component
mkdir ${AVRGCC}/build/{binutils,gcc,gdb}-build

Acquiring the Materials

Download latest packages of GCC, GDB, binutils, and Newlib.You can download it using wget or alternatively download via browser and move it to $AVRGCC/orig. The version we will use is GCC 4.9.0, GDB 7.7, binutils 2.24, and newlib 2.1.0.

cd ${AVRGCC}/orig
wget ftp://ftp.gnu.org/pub/gnu/gcc/gcc-4.9.0/gcc-4.9.0.tar.bz2
wget ftp://ftp.gnu.org/pub/gnu/gdb/gdb-7.7.tar.bz2
wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2
wget ftp://ftp.twaren.net/Unix/NonGNU//avr-libc/avr-libc-1.8.0.tar.bz2

wget ftp://ftp.gnu.org/pub/gnu/gmp/gmp-6.0.0a.tar.xz
wget ftp://ftp.gnu.org/pub/gnu/mpc/mpc-1.0.2.tar.gz
wget ftp://ftp.gnu.org/pub/gnu/mpfr/mpfr-3.1.2.tar.gz

Then, extract them to src directory.

cd ${AVRGCC}/src

tar -jxf ${AVRGCC}/orig/gcc-4.9.0.tar.bz2
tar -jxf ${AVRGCC}/orig/gdb-7.7.tar.bz2
tar -jxf ${AVRGCC}/orig/binutils-2.24.tar.bz2
tar -jxf ${AVRGCC}/orig/avr-libc-1.8.0.tar.bz2

Next we need to download some prerequisites, especially GMP (GNU Multiple Precision), MPC (Multiple-Precision Complex), and MPFR (Multiple-Precision Floating Point Reliably) which is used for computation. The prerequisites can be downloaded by invoking following command:

The MPFR, GMP, and MPC is not the latest version, but at least we can build GCC. Suppose your working directory at /home/xathrya/AVRGCC, to obtain MPDR, GMP, and MPC invoke following command:

cd ${GCC_SRC}
./contrib/download_prerequisites

However, the version of GMP, MPC, MPFR are not the latest version. We can switch to the latest version by link it to our downloaded one.

cd ${GCC_SRC}

rm {gmp,mpc,mpfr}

tar -Jxf ${AVRGCC}/orig/gmp-6.0.0a.tar.xz
tar -zxf ${AVRGCC}/orig/mpc-1.0.2.tar.gz
tar -zxf ${AVRGCC}/orig/mpfr-3.1.2.tar.gz

ln -s gmp-6.0.0 gmp
ln -s mpc-1.0.2 mpc
ln -s mpfr-3.1.2 mpfr

Building the Toolchains

Building stage is pretty simple. Honestly speaking, the tricky part is about how GCC and built concept and ordering them in correct order.

Binutils

First, built binutils. This will provide lots of useful tools in building ARM libraries and binaries (like objdump, ld, ranlib, etc). Invoke following commands:

cd ${BINUTILS_BUILD}
${BINUTILS_SRC}/configure --target=${TARGET} --prefix=${PREFIX} \
    --enable-interwork --enable-multilib --enable-shared 
make configure-host
make -j4 all
make install

You will notice a few configure options that are really critical for getting things to work properly.

  • –target=avr Says we want a compiler to generate binaries for the avr platform.
  • –enable-multilib Multilib allows the use of libraries that are compiled multiple times for different targets/build types
  • –enable-shared – enable the creation of the shared libraries.

GCC

Next we will build the GCC. But please note that we are only intereset on C and C++ so we will ignore other language. To built GCC, do this:

cd ${GCC_BUILD}
${GCC_SRC}/configure --target=${TARGET} --prefix=${PREFIX} --enable-interwork \
   --enable-multilib --enable-languages="c,c++" --with-dwarf2 --disable-libssp \
   --enable-c99 --enable-long-long --enable-__cxa_atexit --enable-shared
make -j4 all-gcc 
make -j4 all-target-libgcc

make install-gcc install-target-libgcc

Now, the important points are:

  • –enable-languages=”c,c++” – means build C and C++ only.
  • –with-headers – this adds a header inlude path during build time and will allow the build to find the newlib header files
  • –enable-__cxa_atexit – allows use of __cxa_atexit, rather than atexit, to register C++ destructors for local statics and global objects and is essential for fully standards-compliant handling of destructors. It also affects the C++ ABI and therefore results in C++ shared libraries and C++ programs that are interoperable with other Linux distributions.
  • –enable-c99 – enable C99 support for C programs.
  • –enable-long-long – enables long long support in the compiler.

avr-libc

Now build our avr-libc

cd ${AVRLIBC_SRC}
./configure --host=avr --build=`./config.guess` --prefix=${PREFIX}
make
make install

GDB

Optionally you can build GDB. To do so, invoke following:

cd ${GDB_BUILD}
${GDB_SRC}/configure --target=${TARGET} --prefix=${PREFIX} \
  --enable-interwork --enable-multilib
make -j4 all 
make install

And that’s it. You should have them now.

Testing

The toolchain can be tested with the minimal code here:

int main()
{
   return 0;
}

Getting Started to Microcontroller

December 11, 2015 | Article | No Comments

In this article we will discuss things we need to get started to microcontroller, especially programming and engineering a microcontroller.

All the things we need can be categorized into two:

  • Hardware
  • Software

The Hardware Part

Mostly we are facing hardware. In typical we will need following hardware:

  • Computer
  • In-System Programmer (ISP)
  • Target Board
  • Microcontroller

Computer

We need computer / laptop to write, edit, compile, and debugging the code before we send the program to the microcontroller. The requirements are not too much, at least it has spare resource to do our job. Any decent PC / laptop will do.

In-System Programmer (ISP)

We have our PC at one end with binary file ready to be written and a target board at another end. How can we transfer the program? For this we need a hardware called In-System Programmer or abbreviated as ISP (not Internet Service Provider). This devices programs the Microcontroller by burning the file (typically in hex format) into flash memory of microcontroller.

There are three type of ISP, according to the connector shape: Parallel programmer, Serial programmer, USB programmer. However, most ISP are now USB-based.

Parallel programmer – data is transferred through the parallel port of the PC. Technically the parallel port is called DB25 port as it has 25 pins. Any old school computer has this, usually referred as the “printer port”.

DB25

Serial programmer – The data is transferred throught the serial port of the PC. Technically the serial port is called DB9 port as it has 9 pins.

DB9

USB programmer – the data is transferred through the USB port of the PC. Typically, it use USB 2.0 standards.

SONY DSC

Target Board

Microcontroller cannot function on its own. If Microprocessor need motherboard to function, microcontroller need a board with an appropriate circuit to make it work. Sometimes we call it development board which have slot for the MCU to fit in, slots for other accessory drivers, ICs pins outlet of GPIO pins, etc.

There are many ready made development board out there. You can buy one of them or make them by yourself. It is always recommended for beginner to buy one or two different types of development board, but don’t go and buy random board. We need to consider the type of ISP and MCU and then choose the one according to our requirement and budget.

Microcontroller

Selecting the microcontroller is the biggest dilemma. There are more than 150 IC manufactures which manufacture MCUs, and each one of them can have more than dozens of different models in their account. So which one to choose?

By the popularity, there are two most popular microcontrollers: PIC by Microchip and AVR by Atmel.

When we are choosing microcontroller, we should consider many factors. But at least, we can consider following factors to decide what MCU we need:

  • Cost – A cheap MCU is always preferred. But many chips might offers competitive price with competitive features. Also remember that sometimes price and capability always been a tradeoff.
  • Speed – Speed of execution also matters. Running faster means accomplish work faster.
  • Ease of use – How ease of use means how many effort we need to learn the chip, assemble the system, maintain it or even upgrade the system if necessary.
  • Architecture – In simple words: RISC or CISC? There are two different categories of architecture, the Reduced Instruction Set Computing (RISC) and Complex Instruction Set Computing (CISC). In RISC, the instructions are highly optimized set of instructions rather than a more specialized set of instruction. While the CISC is the counterpart. In RISC less amount of instructions will result in more output, whereas in CISC more amount of instructions will result in less output. To do a particular job, RISC require lesser number of instruction than CISC. AVR and PIC are examples of RISC, while Intel 8051 and Motorola 68000 are based on CISC.
  • Compiler – Availability of compiler means ease our access to learn and code the microcontroller. Some manufacturer such as Atmel gives free compiler for their AVR, while other might charge it for some cost. Practically, they are more specific domain or specific purpose.
  • Durability – How long the microcontroller will last? How is the maximum or minimum constraint which tolerated by the microcontroller? This should be proven.

Choose any MCU you want.

The Software Part

In softwares, we have several subcategories:

  • Compiler
  • Debugger
  • Programmer

Compiler

We want to program the microcontroller. Like microprocessor, microcontroller only know machine code in some manners. They don’t understand human language. To bridge the gap, a programming language is created and a compiler is used to translate the programming language to the code known by the microcontroller. There are many different language and compilers available for different OS.

For programming language, C is preferred over other (such as BASIC), as it is more organized and gives us the power to do substantially more. Apart from this, C is a language which widely used in low level programming. It is powerful, like a sharp sword you should know what kind of weapon you are using.

Different microcontroller use different machine code and hence can have different compiler. You can use compiler for AVR to write a program for PIC microcontroller. You can however if there is a compiler which can translate our code to different target microcontroller.

Debugger

Debugger is a tool used to test and debug other program. Typically, the debugger will execute the instruction one by one and stop to whichever instruction interest us. The target program is the program written specifically for microcontroller.

Debugging process can be done in two different location: local and remote.

Debugging in local means the target program is run on our computer. We don’t upload the program to the microcontroller to know the execution, instead we let the debugger to run it in our system.

Remote debugging means the target program is run on the microcontroller. We connect our computer to debugging line of microcontroller and control the execution flow from our debugger. We then can set some register values, change the behavior, and stop at specific instructions.

Programmer

A programmer software is a bit confusing term. It is a special software used to utilize hardware programmer or ISP so we can transfer the program from our computer to the board. Most of the compilers have an inbuilt programmer. But sometimes people prefer to use a separate one because of greater flexibility it offers.

Some popular programmers are: PonyProg, avrdude, ProgISP.

Atmel Studio 6 and Arduino

December 11, 2015 | Article | No Comments

Atmel Studio, formerly known as AVR Studio, is a good development application to create program for Atmel’s processor (Atmel’s AVR and Atmel’s ARM). The 6th version promises to be better, faster, and easier to use than before. Here, we will discuss about the way to set up the platform for the use with Arduino.

In this article, I use:

  1. Windows 8.1 64-bit
  2. Atmel Studio 6.2
  3. Arduino 1.5.8 (BETA)

Our objective:

  1. Successfully create binary file for Arduino
  2. Successfully flash the image to Arduino
  3. Know some of Arduino core library

It is recommended that we install both Atmel Studio and Arduino IDE.

Introduction to Atmel Studio 6

This Integrated Development Platform is a rich feature development platform for developing and debugging Atmel ARM Cortex-M and Atmel AVR microcontroller (MCU) based application.

Atmel Studio 6 is released in 2011 and based on Microsoft Visual Studio. The latest version at the time of writing this article is Atmel Studio 6.2 which can be downloaded from here.

Atmel studio 6 is free of charge and is integrated with the Atmel Software Framework (ASF), a large library of free source code with 1600 ARM and AVR project examples. In summary, what Atmel Studio 6 offers in addition to creating new software for MCU:

  1. Facilitates reuse of existing software and, by doing so, enables design differentiation.
  2. Supports the product development process with easy access to integrated tools and software extensions through Atmel Gallery.
  3. Reduces time to market by providing advanced features, an extensible software eco-system, and powerful debug integration.

Why Switching from Arduino IDE to Atmel Studio 6?

Arduino is a great tools. But, it does so much under the hood that it can actually be quite limiting for experienced programmers. The lacks of compiler warnings and debugging capabilities make life hard when working on advanced projects. And here Atmel Studio comes to the rescue.

Atmel Studio is a huge step up from those limitations. If you have a big project, porting the entire thing to pure C can be a daunting task. Plus, some of those Arduino libraries are just so darn convenient.

So, why not have the best of both worlds? Arduino is basically a wrapper on top of C/C++, technically it’s possible to combine any Arduino sketch or library with your own custom code (and that it is). The trick is in setting up your project properly. Once accomplished, you can keep access to the huge Arduino user-contributed code library, but enjoy all the features of advanced AVR and a real IDE.

Arduino Core Library

Arduino is an open-source physical computing platform based on simple I/O board. Stripped the IDE part, Arduino has a library which consists of seberal things like: EEPROM, Esplora, Ethernet, Firmata, etc. But down to the innermost, Arduino has a set of library known as the Arduino core. This Arduino core is the software library which is compiled to any board of Arduino and make Arduino as Arduino.

The Arduino core can be found at “<ArduinoPath>\hardware\arduino\cores\arduino\” where <ArduinoPath> is the path you install Arduino IDE. Well, if you don’t install Arduino IDE, you can clone it from git

git clone git://github.com/arduino/Arduino

and head to “hardware\arduino\cores\arduino”. You can read the content of Arduino core library in the appendix A below.

In order to build Arduino projects, we need to grab the arduino core library. Normally, the Arduino IDE compiles this for us whenever we compile a sketch. To use it in Atmel Studio we need to compile it first.

Steps:

  1. Open Arduino IDE. Open preferences (File -> Preferences) and check on “compile” next to “Show verbose output during:”.
  2. Make sure Arduino IDE is set to whichever chip you want to use with Atmel Studio.
  3. Compile any example sketch, for example “01.Basics\Blink”. In output window at the bottom of the IDE window you should see information on where the IDE put the temporary build output. It will look something like this: “C:\Users\{Your User}\AppData\Local\Temp\build1249632912679374352.tmp”
  4. Copy the “core.a” file and paste it as “libcore.a” so Atmel Studio (and GCC toolchain) can recognizes it as a standard library.

Converting the Sketch

Now the sketch part. There are two things you can do:

  1. If you are converting an existing sketch called Sketch, open the Sketch.cpp file from temporary build directory in text editor. You can then simply copy-paste the code into AVR Studio project. This file is generated by Arduino from our sketch. Arduino automatically fix the messes for us, for example we can define function anywhere in the sketch but Arduino would make appropriate function prototype for us. This is a solution if you are compiling the sketch via Arduino IDE.
  2. Copy and paste the source code from sketch file into the project’s main .cpp file. You can also copy-paste the source from Arduino .pde sketch. If you do this, you should define the function prototypes by yourself. Adding function prototypes is easy actually. Remember to incluse prototypes for setup() and loop() and then add #include “Arduino.h” to the very beginning.

Compiler and Linker Setup

In this section we will setup the compiler and linker setup for any of our project. Our objective:

  • Define Symbols for compilation, especially F_CPU and Arduino software version.
  • Point additional Include directory.
  • Set some Optimization
  • Set Linker to include our libcore
atmel-arduino
Picture 1

Steps:

  1. Open the Project Properties (Project -> <ProjectName> Properties or press Alt+F7), then click on “Toolchain”. We need to setup a bunch of compiler options here. Select “All Configuration from the Configuration drop-down menu to modify both release and debug configuration at same time.
  2. Click on “Symbols” in the left-hand “AVR/GNU C++ Compiler” dropdown menu (see number 1 on picture 1). We need to tell some symbols to our compiler. To do it, click the green plus icon and then enter the symbol. Here is what you need to enter:
    • F_CPU=16000000L
    • ARDUINO=158
  3. Click on “Directories” in the same C++ Compiler menu (see number 2 on picture 1). We need to add the include directories, the directories that contain our Arduino core code and libraries. For any Arduino project, we’ll need to tell the compiler where to find “Arduino.h” and “pins_arduino.h”. In my case I install Arduino on C:\Arduino so the library should be on “C:\Arduino\hardware\arduino\cores\arduino” and “C:\Arduino\hardware\arduino\variants\standard”.
  4. Click on “Optimization” immediately after “Directories” (see number 3 on picture 1). Choose “Optimize for size” under “Optimization Level”. Add “-fdata-sections” to “other optimization flags” and check the box for “prepare functions for garbage collection”.
  5. Next click on “Miscellaneous” (see number 4 on picture 1). Add “-fno-exceptions” to the “Other flags” field.
  6. Now we will move to the linker. Click on “Libraries” in the left hand “AVR/GNU Linker” dropdown menu (see number 5 on picture 1).
    1. In the Libraries section you should already see an entry for “m” which is the AVR math library. Add an entry called core, which is our libcore.a file that we grabbed earlier.
    2. We also need to tell where to find the libcore.a, so add that directory path under “Library search path”
  7. Click on “Optimization” (see number 6 on picture 1) and check the box for “Garbage Collect unused sections (-Wl,-gc-sections)”. This tells the linker to leave out unused portions of each library, which reduces the final code size.

Build Project

Building process is similar like other project. Hit the “F7” button to build our solution and watch the output window.

AVRDude and Flashing

The instruction in this section is similar to other “Adding ISP Programmer to Atmel Studio”.

Once you have build the project, we need to upload it. We can achieve this using the similar method as the Arduino IDE. Arduino uses the avrdude utility to flash via serial, and we will do the same.

atmel-exttools
picture 2
atmel-exttools2
picture 3

Ignore entries other than Arduino on picture 3.

Steps:

  1. Open External Tools by clicking Tools -> External Tools (see picture 2)
  2. When the window popups, click “Add” (see number 1 on picture 3)
  3. Note which COM port Arduino uses and make the title like “Arduino on COM24” for easy identification (see number 2 on picture 3)
  4. In the “Command field” (see number 3 on picture 3), put the path to avrdude.exe in Arduino installation. For example in my case: “C:\arduino\hardware\tools\avr\bin\avrdude.exe” without the quotes.
  5. In the “Arguments” (see number 4 on picture 3), paste this line.
-CC:\arduino\hardware\tools\avr\etc\avrdude.conf -patmega328p -carduino -P\\.\COM24 -b57600 -D -Uflash:w:"$(ProjectDir)Debug\$(ItemFileName).hex":i

Edit the path to Arduino installation and change the COM port, chip target, and baud rate if necessary.

 

Appendix A: Arduino Core Library files

The Arduino core library is consists of following file:

utility function

Arduino.h
binary.h
main.cpp
new.cpp
new.h
Platform.h
WCharacter.h
WInterrupts.c
WMath.cpp
WString.cpp
WString.h

CDC communication.

CDC.cpp

Human Interface Device (HID) communication.

HID.cpp

Hardware serial, for serial communication capability.

HardwareSerial.cpp
HardwareSerial.h

Internetwork connection.

Client.h
IPAddress.cpp
IPAddress.h
Server.h
udp.h

Printing.

Print.cpp
Print.h
Printable.h

Stream oriented communication

Stream.cpp
Stream.h

USB serial communication.

USBAPI.h
USBCore.cpp
USBCore.h
USBDesc.h

Tone Generator.

Tone.cpp

Wiring project

wiring_analog.c
wiring_digital.c
wiring_private.h
wiring_pulse.c
wiring_shift.c

Linux udev Rule for AVR USB Programmer

December 11, 2015 | Article | No Comments

In previous article, we have discussed about AVR development in both Linux and Windows. As you might see, we are using software avrdude to write our binary code to avr chip.

Now, when executing avrdude on Linux, it may give an error such as

avrdude: error: usbtiny_transmit: error sending control message: Operation not permitted.

This problem arise when we run avrdude without root privilege.

We can quickly fix this by run avrdude as root or doing sudo. The other choice we have is creating an udev rule for certain programmer. And that’s what we will discuss in this article.

Create udev Rule

First, what is udev?

Any device attached to Unix (and its derivation) will be represented as a node in /dev directory.For each device, it will receive a (major, minor) pair of integers. In the old school way, we can call “mknod” to create device. Starting from kernel version 2.6, Linux use udev to provide a userspace solution for dynamic /dev directory with persistent device naming. With udev we won’t have hard time to manage all device.

We use udev to give us enough privilege to access to device node.

It’s easy to use udev. We need to create a file containing udev rule and save it to /etc/udev/rules.d/

Create file “/etc/udev/rules.d/99-avrprogrammer.rules” and write following this:

# /etc/udev/rules.d/99-avrprogrammer.rules
#
# Udev rules to make AVR programmers user-accessible

# USBtinyISP Programmer rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", GROUP="users", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="0479", GROUP="users", MODE="0666"

# USBasp Programmer rules http://www.fischl.de/usbasp/
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", GROUP="users", MODE="0666"

# Mdfly.com Generic (SiLabs CP2102) 3.3v/5v USB VComm adapter
SUBSYSTEMS=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GROUP="users", MODE="0666"

#Atmel AVR Dragon (dragon_isp) rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2107", GROUP="users", MODE="0666"

#Atmel AVR JTAGICEMKII rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2103", GROUP="users", MODE="0666"

#Atmel Corp. AVR ISP mkII
SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2104", GROUP="users", MODE="0666"

The above rules describe about six hardware programmers.

Introduction to AVR Registers

December 11, 2015 | Article | No Comments

What is Register?

Micro controller operations mostly involve processing data. Registers is used to do operations in CPU.

Registers are special storages in CPU with capacity of certain bits. In 8-bit AVR, a register is 8 bits wide which can hold data of 8-bits (1 byte). In nutshell, they do like this:

7 6 5 4 3 2 1 0

Note the numeration of these bits: the least significant bit starts with zero (20 = 1).

A register can either store numbers from 0 to 255 (positive number, no negative values), or numbers from -128 to +127 (whole number with a sign bit in bit 7), or a value representing an ASCII-coded character (e.g. ‘A’), or just eight single bits that do not have something to do with each other (e.g. for eight single flags used to signal eight different yes/no decisions).

The special character of registers, compared to other storage sites, is that

  • they can be used directly in assembler commands,
  • operations with their content require only a single command word,
  • they are connected directly to the central processing unit called the accumulator,
  • they are source and target for calculations.

Registers are commonly divided into three categories:

  1. General purpose registers
  2. Control & Status registers
  3. Segment registers

A general purpose registers are registers which is used to hold data for operations. They can be used as operand which will be operated by ALU (Arithmetic & Logic Unit), or as result of the operations.

The Control and Status registers are used to control the micro controller. They are used to determine the control flow of the program. Many instructions involve comparisons and mathematical calculations. Those operations will changes some part of flags. Other conditional instruction test the value of these status flags to take the control to other location.

Segment registers are registers which is used to point different segment in the memory. Segments are specific areas defined in a program for containing data or instruction.

Registers in AVR

General Purpose Register

AVR micro controllers have 32 general purpose 8-bit registers, named R0 to R31. All arithmetic operations operate on those registers, only load and store instructions access RAM. A limited number of instruction operate on 16-bit register pairs. The lower-numbered register of the pair holds the least significant bits and must be even-numbered. The last three register pairs are used as pointer registers for memory addressing. They are known as X (R27:R26), Y (R29:R28) and Z (R31:R30). Postincrement and predecrement addressing modes are supported on all three. Y and Z also support a six-bit positive displacement.

Instructions which allow an immediate value are limited to registers R16–R31 (8-bit operations) or to register pairs R25:R24–R31:R30 (16-bit operations ADIW and SBIW). Some variants of the MUL operation are limited to eight registers, R16 through R23.

Control and Status Register

In addition to those 32 general-purpose registers, the CPU has a few special-purpose registers:

  • PC: 16- or 22-bit program counter
  • SP: 8- or 16-bit stack pointer
  • SREG: 8-bit status register

The status register bits are:

  1. C Carry flag. This is a borrow flag on subtracts.
  2. Z Zero flag. Set to 1 when an arithmetic result is zero.
  3. N Negative flag. Set to a copy of the most significant bit of an arithmetic result.
  4. V Overflow flag. Set in case of two’s complement overflow.
  5. S Sign flag. Unique to AVR, this is always N⊕V, and shows the true sign of a comparison.
  6. H Half carry. This is an internal carry from additions and is used to support BCD arithmetic.
  7. T Bit copy. Special bit load and bit store instructions use this bit.
  8. I Interrupt flag. Set when interrupts are enabled.

The Carry flag is used for shift and rotate instructions.

If the Global Interrupt Flag is set, the mcu will perform the Interrupt Service Routine corresponding to the interrupt that occurred.

Just remember: They are important for mathematical operations, and changing them between calculating a value and comparing it with something else might be fatal. That’s why Interrupt Service routines should preserve the SREG and any other registers they use (unless these registers are unused in normal code). An interrupt might occur between comparing two values with each other and a following branch – the ISR might change status flags and corrupt the flags the branch relies on.

Segment Registers

AVR micro controller has some 8-bits segment registers, named: RAMPX, RAMPY, RAMPZ, RAMPD, and EIND. These registers are prepended to 16-bit addresses in order to form 24-bit address; only available in parts with large address spaces.

You should remember that AVR use modified Harvard architecture which separate the instructions and the data.It is different to Intel x86 where instruction and data are stored in same memory.

Gentle Introduction to AVR Assembly

December 11, 2015 | Article | No Comments

What is Assembly Language?

Assembly language is a low-level programming language for programmable device. It is an alphanumeric representation of machine code. In contrast to high-level programming language which are generally portable across multiple systems, assembly language is very architecture specific. Assembly language is very strong correspondence between the language and the architecture’s machine code instruction.

Assembly consists of a list of instructions that are in no way comparable to anything you might know from C, Basic or Pascal. It does not have structure like high-level language does (like for or while)

Let’s see the example below. The code below is an example of a AVR assembly code written in assembly language. Each line of the code is an instruction telling the micro controller to carry out a task.

            ADD     R16, R17       ; Add value in R16 to value in R17
            DEC     R17            ; Minus 1 from the value contained in R17
            MOV     R18, R16       ; Copy the value in R16 to R18
END:        JMP     END            ; Jump to the label END

As we stated before, the instruction or mnemonic are note general but specific. Each company provides a set of instructions for their micro controllers. Also note that not all instructions are available to all micro controllers. We should consult datasheet for each AVR microcontroller.

Why Assembly?

Assembler or other languages, that is the question. Why should I learn another language, if I already learned other programming languages? The best argument: while we live in France we are able to get through by speaking English, but we will  never  feel  at  home  then,  and  life  remains  complicated.  We can  get  through  with  this,  but  it  is  rather inappropriate. If things need a hurry, we should use the country’s language.

Many people who dwelling in higher-level language start diving into AVR assembly. The reasons are sometimes similar to people who come to assembly language in x86, such as:

  • to know the architecture better
  • analyze bug
  • use hardware features which aren’t supported by higher-level language
  • need time-critical code
  • just for fun

It is necessary to know assembly language, e.g. to understand what the higher-level language compiler produced. Without understanding assembly language we do not have a chance to proceed further in these cases.

High Level Languages and Assembly

High level languages insert additional nontransparent separation levels between the CPU and the source code. An example for such an nontransparent concept are variables. These variables are storages that can store a number, a text string or a single Boolean value. In the source code, a variable name represents a place where the variable is located, and, by declaring variables, the type (numbers and their format, strings and their length, etc.).

For learning assembler, just forget the high level language concept of variables. Assembler only knows bits, bytes, registers and SRAM bytes. The term “variable” has no meaning in assembler. Also, related terms like “type” are useless and do not make any sense here.

High level languages require us to declare variables prior to their first use in the source code, e. g. as Byte (8-bit), double word (16-bit), integer (15-bit plus 1 sign bit). Compilers for that language place such declared variables somewhere in the available storage space, including the 32 registers. If this placement is selected rather blind by the compiler or if there is some  priority rule used,  like  the  assembler  programmer carefully  does  it,  is  depending  more  from the  price  of  the compiler. The programmer can only try to understand what the compiler “thought” when he placed the variable. The power to decide has been given to the compiler. That “relieves” the programmer from the trouble of that decision, but makes him a slave of the compiler.

The instruction “A = A + B” is now type-proofed: if A is defined as a character and B a number (e. g. = 2), the formulation isn’t accepted because character codes cannot be added with numbers. Programmers in high level languages believe that this type check prevents them from programming nonsense. The protection, that the compiler provides in this case by prohibiting your type error, is rather useless: adding 2 to the character “F” of course should yield a “H” as result, what else? Assembler allows us to do that, but not a compiler.

Assembler allows us to add numbers like 7 or 48 to add and subtract to every byte storage, no matter what type of thing is in the byte storage. What is in that storage, is a matter of decision by the programmer, not by a compiler. If an operation with that content makes sense is a matter of decision by the programmer, not by the compiler. If four registers represent a 32-bit-value or four ASCII characters, if those four bytes are placed low-to-high, high-to-low or completely mixed, is just up to the programmer. He is the master of placement, no one else. Types are unknown, all consists of bits and bytes somewhere in the available storage place. The programmer has the task of organizing, but also the chance of optimizing.

Of a similar effect are all the other rules, that the high level programmer is limited to. It is always claimed that it is saver and of a better overview to program anything in subroutines, to not jump around in the code, to hand over variables as parameters, and to give back results from functions. Forget most of those rules in assembler, they don’t make much sense. Good assembler programming requires some rules, too, but very different ones. And, what’s the best: most of them have to be created by yourself to help yourself. So: welcome in the world of freedom to do what we want, not what the compiler decides for us or what theoretical professors think would be good programming rules.

High level programmers are addicted to a number of concepts that stand in the way of learning assembler: separation in different access levels, in hardware, drivers and other interfaces. In assembler this separation is complete nonsense, separation would urge us to numerous workarounds, if we want to solve your problem in an optimal way.

Because most of the high level programming rules don’t make sense, and because even puristic high level programmers break their own rules, whenever appropriate, see those rules as a nice cage, preventing us from being creative. Those questions don’t play a role here. Everything is direct access, every storage is available at any time, nothing prevents your access to hardware, anything can be changed – and even can be corrupted. Responsibility remains by the programmer only, that has to use his brain to avoid conflicts when accessing hardware.

The other side of missing protection mechanisms is the freedom to do everything at any time. So, smash your ties away to start learning assembler. We will develop your own ties later on to prevent yourself from running into errors.

What is Really Easier in Assembly?

All words and concepts that the assembler programmer needs is in the datasheet of the processor: the instruction and the port table. Done! With the words found there anything can be constructed. No other documents necessary. How the timer is started (is writing “Timer.Start(8)” somehow easier to understand than “LDI R16,0x02” and “OUT TCCR0,R16”?), how the timer is restarted at zero (“CLR R16” and “OUT TCCR0,R16”), it is all in the data sheet. No need to consult a more or less good documentation on how a compiler defines this or that. No special, compiler-designed words and concepts to be learned here, all is in the datasheet. If we want to use a certain timer in the processor for a certain purpose in a certain mode of the 15 different possible modes, nothing is in the way to access the timer, to stop and start it, etc.

What is in a high level language easier to write “A = A * B” instead of “MUL R16,R17”? Not much. If A and B aren’t defined as bytes or if the processor type is tiny and doesn’t understand MUL, the simple MUL has to be exchanged with some other source code, as designed by the assembler programmer or copy/pasted and adapted to the needs. No reason to import an nontransparent library instead, just because you’re to lazy to start your brain and learn.

Assembler teaches us directly how the processor works. Because no compiler takes over your tasks, we are completely the master of the processor. The reward for doing this work, we are granted full access to everything. If we want, we can program a baud-rate of 45.45 bps on the UART. A speed setting that no Windows PC allows, because the operating system allows only multiples of 75 (Why? Because some historic mechanical teletype writers had those special mechanical gear boxes, allowing quick selection of either 75 or 300 bps.). If, in addition, we want 1 and a half stop bytes instead of either 1 or 2, why not programming your own serial device with assembler software. No reason to give things up.

The Instruction Set

Instruction Set or Instruction Set Architecture (ISA) is set of instruction for computer architecture, including native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O. In simple word, it is the set of instruction we use to program the device.

Every instruction is actually a number. These numbers are stored in flash memory and when the chip is powered, the CPU then start to fetch instruction from storage and executed what the instruction want. The instructions are 16-bit number. But there is no need for us to learn that binary code and pattern, because in assembler those codes are mapped to human-readable instruction. The so called mnemonics are machine instruction represented as human-readable text.

Still, the CPU understands instruction expressed in 16-bit word. The mnemonics only represents those instruction.

Instruction Set can be divided into some categories:

  • Data handling and memory operations: set register to a fixed value, move data from memory location to register or vice.
  • Arithmetic and logic operations: add, subtract, multiply, divide, bitwise operations, comparison.
  • Control flow operations: branch, conditionally branch, function call.

You can see the complete AVR instruction set here: Download

The Directives

Apart from the microcontroller instruction set that is used in writing an AVR assembly code the AVR Assembler support the use of assembler directives. Assembler Directives are used as instruction to the AVR assembler and are in no way translated to machine language during the assembly process.

Assembler Directives are use by the programmer to assist in adjusting the location of the program in memory, defining macros and so fort. A list of the AVR assembler directives available to the AVR assembler is given below.

[table “9” not found /]

Each assembler directives in an AVR assembly program must be preceded by a period “.” as shown below where the directives INCLUDE and ORG are used.

.include "m8515def.inc"
.org $00

begin:     ADD R16, R17      ; Add R17 to R16
           MOV R17, R18      ; Copy R18 to R17

The Basics of Micro Controller You Should Know

December 11, 2015 | Article | No Comments

By definition, a micro controller (sometimes abbreviated µC, uC or MCU) is a single chip containing at least a CPU, memory, and programmable I/O peripherals. Sometimes it also has a timer unit. Basically a micro controller can be described as a small computer on a chip. It is designed for embedded application or specific purpose. Thus, it is programmed to do certain limited task.

A micro controller usually include, but not limited to, serial communication capabilities, interrupt controls and analog I/O capabilities.

There are many manufacturers of microcontroller, for example:

  • ATMEL Corp.
  • Freescale Semiconductor
  • Fujitsu
  • Microchip Technology
  • Texas Instruments Inc.
  • Renesas Technology Corp.

A complete list can be read here: http://en.wikipedia.org/wiki/List_of_common_microcontrollers

 

Micro Controller Components / Peripherals

Processor – The processor refers to the Central Processing Unit (CPU) of the micro controller. It contains the Arithmetic Logic Unit (ALU), Control Unit, Instruction Decoder and some Special Registers (Stack Pointer, Status Register, Program Counter, etc.).

Volatile Memory – This is memory used by ht micro controller for temporary data storage, system setup and peripherals configurations. Memory in this category includes SRAM and DRAM. AVR micro controllers utilize SRAM.

Non-Volatile Memory – This is memory used by the micro controller to store programs. Data can also be stored in this memory but the access time is much slower than that of RAM. Memory in this category includes ROM, PROM, EPROM, EEPROM and FLASH. The AVR micro controllers utilize Flash for program storage, some AVR controllers contains a bit of EEPROM as well.

Timer Module – Most micro controllers have at least one timer/counter peripheral. Timer/Counter modules are used to perform timing or counting operations in the controller. These include time stamping, measuring intervals, counting events, etc.

Interrupt Module – Interrupts enable the micro controller to monitor certain events in the background while executing and application program and react to the event if necessary pausing the original program. This is all coordinated by the interrupt module.

Digital I/O Module – This module allows digital/logic communication with the micro controller and the external world. Communication signals are that of TTL or CMOS logic.

Analog I/O Modules – These modules are use to input/output analog information from/to the external world. Analog modules include Analog Comparators and Analog-to-Digital Converters.

Serial Modules – These modules are used for serial communication with the external world. An example is the USART peripherial which utilizes the RS232 standard.

Comparing Micro controller and Microprocessor

At the basic level, a microprocessor and micro controller exist for performing some operations. They are fetching instructions from the memory and executing these instruction (arithmetic or logic operations) and the result of these executions are used to serve to output devices. Instructions are electronic instructions represented by a group of bits. These instructions are always fetched from their storage area.

First let’s take a look at block diagram of a microprocessor based-system and then look at micro controller.

Courtesy of www.circuitstoday.com
Courtesy of www.circuitstoday.com

You will se a microprocessor has many support device like Read only memory, Read-Write memory, Serial interface, Timer, Input/Output ports etc. All these support devices are interfaced to microprocessor via a system bus. So one point is clear now, all support devices in a microprocessor based system are external. The system bus is composed of an address bus, data bus and control bus.

Now look at micro controller.

microcontroller-system
Courtesy of www.circuitstoday.com

Now you see the point which differentiate microcontroller to microprocessor. All the support devices like Read only memory, Read – Write memory, Timer, Serial interface, I/O ports are internal. There is no need of interfacing these support devices and this saves a lot of time for the individual who creates the system. It is nothing but a microprocessor system with all support devices integrated inside a single chip.

Now after see the difference you might be thinking that if a microcontroller is the complete system in a compact size, do we still need microprocessor? Well, MCU is usually application specific or in other words, specific to some purposes that don’t require higher resources. Typical MCU gives us limited resource, enough for doing some task. For example, it is worthless to spend GigaHertz processor with dozens of HDD and RAMs just for powering a LED. It is wiseful to use a 16MHz single core processor, 16KB Flash, 1 KB RAM etc which gives lower cost. But in case of Microprocessor (or MPU), it can handle huge loads, features multitasking, and do more complex operation easily.

Some Microcontroller Applications

To give more insight of what microcontroller can do, let’s mention some examples of things that can be built using microcontroller:

  • alarm clocks, watch
  • telecommunications & networking – phones, mobile phones, wireless router, etc
  • day to day applications – washing machines, elevators, microwave ovens, automatic electric heaters
  • automotive – lighting, braking, speed control
  • traffic signals lamp
  • robots
  • harddisk, pendrives, printers, mouse, cameras, small electronic machines
  • etc

Installing USBasp Drivers on Windows 8.1

December 11, 2015 | Article | No Comments

When we are dealing with AVR programming, after create the codes in our development machine we should write the code into the device. For this purpose, we need a tool which we called Downloader or Programmer. This tool will “burn” the code into AVR CPU using spesific port.

One popular tool is USBasp (http://www.fischl.de/usbasp/). This tool is a USB in-circuit programmer which consists of an ATMega88 or an AtMega8 and a couple of passive components. In short, we need no special USB controller anymore.

usbaspver2

Sometimes, we might face a problem installing usbasp drivers on Windows 8.1. But, this article will discuss about how to install those drivers.

Precaution

The method described here will require machine to restart. Make sure you have write down the steps before proceeding.

Identify The Problem

The main problem is that Microsoft doesn’t allow us to install drivers which are not ‘digitally signed’ directly (or easily) on Windows Vista and later version (7, 8, and also 8.1). To get around this, we must temporarily disable the signature verification process.

Phase 1: Disable Driver Signature Enforcement

  1. Enter “start screen” and open “PC Settings”
  2. Choose “Update and recovery” option in the left panel.
  3. Choose “Recovery” option in the left panel
  4. Click on “Restart now” button, below the “Advanced startup” section then click “reset” button to begin resetting.
  5. Once machine is restarted, we will face several options which we can choose by pressing F1-F9. Choose F7 for “Disable driver signature enforcement”

Now, the machine will boot with no driver signature enforcement. We can then install the driver to our machine.

Phase 2: USBasp Driver Installation

Download the driver fro Windows from USBasp (http://www.fischl.de/usbasp/). The latest version is version 2011-05-28.zip which can be downloaded here. Read the readme first. Because I use WinAVR version 20100110, i will extract the libusb_0.1.12.1 folder as D:\libusb_0.1.12.1.

Plug the USBasp in to USB port. Windows will try to recognize the device. It should be recognized but it lacks of driver so the process is not finish.

Open “Device Manager” on “Control Panel”. Look for Other devices. We have USBasp device there.

usbasp-step-1

Right click on it and click on “Update Driver Software…”

usbasp-step-2

Click on “Browse my computer for driver software”.

usbasp-step-3

Type the location of folder “D:\libusb_0.1.12.1” and then click “Next”.

usbasp-step-4

Windows will give warning as it can’t verify the publisher of the driver. Just ignore it and select “Install this driver software anyway”

usbasp-step-5

Let the installation proceed and wait until it finish.

usbasp-step-6

Done.

Social media & sharing icons powered by UltimatelySocial