Showing posts with label STK200. Show all posts
Showing posts with label STK200. Show all posts

Thursday, March 1, 2012

STK 200: First Program (LED Blink)

For this program, you should already have AVR Studio 5 and AVRISP-U installed on your computer. If you don't, visit my previous post Getting Started Programming Guide (link). This is a simple program which simply makes the built-in LEDs to blink. I'm going to use C for this program because the code looks really simple. The assembly version is not really difficult either but we'll keep it simple for now. Note that AVR Studio 5 has a built-in C compiler. You might remember for AVR Studio 4, you had to download AVR GCC and integrate it. If you downloaded AVR Studio 5, you already have the C compiler.

What will the program do? If you look at the STK 200, there is a row of 10 LEDs numbered from 0 to 7 then "ISP" and "ON." These are the built-in LEDs. Our program will make the LEDs numbered from 0 to 7 blink on and off at a rate perceptible to the human eye. In microcontroller terms, this means physically connecting the LEDs to PORTB and sending alternating HIGH/LOW signals to PORTB. Note that is all output - no input. If you don't know what PORTB is, check my Basic Layout Guide (link).

Step 1 - Create a new project: Go ahead and open AVR Studio 5. From the startup screen, go to File>New>Project... and you should see a New Project dialog box. At the top left of the dialog box, select the C templates and then choose "C Executable Project" in the middle of the screen. At the bottom, fill in "blink" as the name and this should automatically fill the solution name field with the same text. Also, make sure that the "Create directory for solution" box is checked. This checkbox will not affect your code at all, but it will keep your AVRStudio folder better organized. Look at the picture below and make sure your screen looks the same:
STK 200: New Project Dialog Box

Friday, February 17, 2012

STK 200: Getting Started Programming Guide

To start programming the STK 200, you need to download some software. Namely, you need AVR Studio and AVRISP-U. I talked about the basic layout of the board in a previous post (link), so check that out if some of the terms I am using are unfamiliar. I broke the process into three steps below.

Step 1 - Download AVR Studio 5: I started programming with AVR Studio 4, but if you are starting today, you might as well start with the new AVR Studio 5 release. The program is built using the Microsoft Visual Studio Shell (VSS) so the user interface is very similar to Visual Studio. I suppose this can be a good thing for those who like Visual Studio and a bad thing for those who don't. Overall, it seems to have a lot of convenient features such as IntelliSense and debugging interface.

So to get the software, go to the AVR Studio 5 page (link) from Atmel and download the software package you need. I recommend downloading the package that includes VSS and .NET 4.0. The software is completely free but you do have to fill out a registration form. The installer is pretty big (the one including VSS and .NET is over 600 MB).
STK 200: AVR Studio 5

Wednesday, February 1, 2012

STK 200: Basic Layout Guide

The Kanda STK 200 has a lot of really cool features. But when I first got the board, I didn't even know where to begin. This post goes over the board's basic layout and the main features that it includes.

I/O: Really, the core function of a microcontroller is Input/Output. In fact, out of the ATmega32's 40 pins, 32 pins are set aside for I/O. They are organized into four 8-pin ports named PORTA, PORTB, PORTC, and PORTD. The STK 200 makes it really easy to access these ports by giving them each headers. The board even labels the headers using the standard naming convention established by the AVR family (PORTA, etc.). Each header includes it's own VCC and GND, which devices almost always require. LEDs and switches are probably the most common form of I/O; conveniently, the STK 200 has 8 LEDs and 8 switches built into the board. You can dedicate ports to the LEDs, the switches or both using a 10-pin ribbon cable provided with the board and pictured below. PORTB is lined up with the LED input header and PORTD is lined up with the switches output header for an easy connection.
STK 200: I/O

Friday, January 20, 2012

STK 200: Switching Microcontrollers

When I bought my Kanda STK 200, it was shipped with an ATmega8515 microcontroller. While the 8515 is a fine microcontroller, I wanted to replace it with an ATmega32 due to the latter's more robust features.  Namely, the ATmega32 has 32KB of flash memory compared to the 8515's 8KB. Also, the 8515 has no built-in analog to digital or digital to analog conversion while the 32 does. If you are also interested in switching the microcontroller on the STK 200, here is a quick guide:

Sockets on the development board: When you look at the board, you can see various sockets. Check out the following image to see the available sockets and what their name is:
STK 200: Sockets on the Development Board

Tuesday, June 7, 2011

blinky lights with interrupts

In the previous post, I kind of glossed over the problem with using the built in delay function. I said that it would be better to use interrupts so I'll go more in depth about that.

The problem with using the built in delay is that CPU clock cycles are essentially wasted. In such a simple program like we had in the previous post, we are not worried about conserving clock cycles but you can imagine that in a very complex program you would want every clock cycle to do something. Once interrupts are set up and enabled, they will "interrupt" the program when a certain condition is met. In the case of delay, a timer counts clock cycles and once a certain number is reached, the program is interrupted and carries out a "service routine" specified by the programmer. Once the service routine is finished, the program returns to the line of code it was executing when the interrupt occurred.

To illustrate the difference between the two types of delays, I wrote a program that does the exact same thing as the program in the previous post but it uses interrupts rather than the built in delay. This program simply makes the built in LEDs turn on and off at a rate that is perceptible to the human eye:
#include <avr/io.h>
#include <avr/interrupt.h>

int main(void)
{
    DDRB = 0xFF;        //PORT B (LEDs) output
    TCNT0 = 0;          //timer starts at zero
    OCR0 = 200;         //and counts up to 200
    TCCR0 = 0b00001101; //CTC mode, internal clk, 1024 prescaler

    sei();              //global interrupt enable
    TIMSK = (1<<OCIE0); //timer0 overflow interrupt enable
 
    while(1)
        asm("nop");     //stay here....
}

ISR (TIMER0_COMP_vect)
{
    PORTB ^= 0xFF;      //toggle PORTB (LEDs)
}

Saturday, June 4, 2011

STK 200 - blinky lights

* update: I wrote a revised version of this guide using AVR Studio 5. It uses the same code but I added new photos and wording. Check it out: STK 200: First Program (LED Blink)

As I mentioned previously, I was initially frustrated when I tried to program the STK 200 from Kanda because of the lack of documentation. So I thought it would be helpful to post some of my experiences. To start off, I'll explain the way I loaded a super simple, blinky lights program.

So lets assume you just got the kit in the mail and you have not done any AVR programming in the past. Lets start by installing some software. Go to the Atmel website and download AVR Studio 4 (you will have to register but it is free). Atmel released AVR Studio 5 beta in March 2011 but as of now I still use AVR Studio 4 because of the extensive support for it. Next go to the Kanda website and download their AVRISP-U software. Finally, we need AVR GCC (C Compiler). So you can check out the WinAVR website for a link to the download page or just go the WinAVR sourceforge page and find the latest stable release.

So what do we actually want our program to do? Our objective is to simply cause the built-in LEDs to blink. If you look at the kit, there is a row of 10 LEDs numbered from 0 to 7 then "ISP" and "ON." Looking along the edge of the board, there is a row of "PORTS" and across from "PORTB" there is a 10 pin header named "LED'S". We need to connect PORTB to the LED header using the supplied ribbon cable. I marked the two locations on the picture below:
STK 200: LED Layout