Monday, July 28, 2008

AVR Assembler Tutorial

I found a very good site about programming AVR in assembly. The main idea of this site is that Learning by practical examples!

Some highlights:
1) Stepper motor control with AVR Tiny13
2) Egg timer design with AVR Tiny2313

Here is the site: http://www.avr-asm-tutorial.net/

Sunday, July 27, 2008

The Last lecture is really inspiring!

The Last lecture is really inspiring! We will remember you, Prof. Randy!
Official Google Research Blog: Remembering Randy Pausch

Saturday, July 26, 2008

Using only AVR to produce both Video & Sound

The device is called "Craft" by www.linusakesson.net, it used only one ATmega88 to producce both video & sound on the TV. The animation is awesome, please take a look:


Thursday, July 24, 2008

Nixie Tube Clock.

I always want to build a nixie clock, but it is difficult to find the nixie tube and also the tube driver ICs. The kit available on the internet is still expensive for me.

Here is a cool video of nixie tube filling with blue led, it becomes more attractive!

Sunday, July 6, 2008

CTC mode on Tiny13

There are two OC0A and OC0B compare outputs in Tiny13. It is useful to generate waveform . In this example, we use OC0A to output a square wave to blink the LED which is very similar to the previous timer interrupt example instead the output is generate inside Tiny13 but not our interrupt routine.

int main (void)
{
b0_output; //OC0A as led output

TCCR0B = 0x03; //select timer clkio/64

TCCR0A = (0x01)<<6 | 0x02; // Toggle OC0A | CTC MODE
TCNT0 = 0x0; //starting couter value

OCR0A = 0x7F; //around frequency @ 2.2HZ

//make the clk cpu slower
CLKPR = 1<<CLKPCE; //tell cpu to update the CLKPR

CLKPR = 0x8; //clkio = clkcpu/256


while(1) {
;; //interrupt do the rest
}
}

We set the output to be toggled every time the counter value match our OCR0A value. Thus, a square wave is generated:



The complete project can be found here: http://labs.bitartist.org/compare_int.tar.gz

Timer interrupt on Tiny13

Sometimes we have to do somethings in certain period, so timer may be useful for you.
AVR tiny13 have one timer and it count until to 0xFF value for each clock. An interrupt will be then generated and call your interrupt routine.

In our example, we have the following interrupt routine:

ISR(TIM0_OVF_vect) {
if (led){
b0_high;
led = 0;
} else {
b0_low;
led = 1;
}
}


This routine is used to toggle the LED On or Off.

The complete project code can be found here: http://labs.bitartist.org/timer_int.tar.gz

Testing external interrupt INT0 on tiny13

Tiny 13 have an external interrupt "INT0" on PB1, We have created a test project on avr-gcc to have a quick testing on the INT0.



#include <avr/io.h>
#include <avr/interrupt.h>
#include "pin_macros.h"

unsigned char led=0;

ISR(INT0_vect) {
if (led){
b0_high;
led = 0;
} else {
b0_low;
led = 1;
}
}

int main (void)
{
b1_input; //switch
b0_output; //led output

MCUCR = 1<<isc01; //set INT0 as falling edge trigger

GIMSK = 1<<INT0; //enable INTO in global interrupt mask


sei(); //enable interrupt

while(1) {
;; //interrupt do the rest
}
}



B1 is connected to a switch, and B0 is connected to a LED.
When B1 is pressed, it would toggle the LED On or Off.

Download the whole project : http://labs.bitartist.org/test_int0.tar.gz

Reference:
http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html