Category Archives: AVR Microcontrollers

About Atmel ATMega, Attiny projects

Building and installing USBASP-USB programmer of AVR microcontrollers

USBASP is well known USB programmer for Atmel AVR microcontrollers originally supported by Thomas Fischl. USB ASP is made of an Atmega8 and few components. The programmer uses a firmware driver that makes this programmer attractive to many amateurs.

Another thin why this programmer is so popular – because it is officially included and supported in WinAVR (now version 20070122).

Once again lets see what this programmer is made off and how to set it up.

Original circuit you will find in authors site: http://www.fischl.de/usbasp/

usb_asp_cir_thumb.png

 

The core of USBASP adapter is Atmega8 microcontroller clocked by 12MHz crystal. Soldered board is ready to be connected via simple USB cable with B type connector (Computer side needs A type of connector). Resistors R2 and R6 are current limiting resistors, that protect computer USB port. Resistor R7 helps computer to recognize device as LS (Low Speed). Diodes D1 and D2 indicates about data transfer. Header SV1 is compatible with STK200/300 just 4 and 6 pins are used for RXD and TXD (may be used for other purposes).

STK200.png

 

SCK signal can work at two frequencies 1.5MHz and 8MHz 375kHz and 8kHz which can be selected by Jumper JP3. If Jumper is unconnected, then SCK speed is 8MHz 375kHz. Low speed SCK is used when MCU is clocked with low speed oscillator like 32kHz.

USB_ASP_block.png

 

Jumper JP1 is used for programming adapter itself via ISP adapter. And last Jumper JP2 is used for powering adapter from USB port (not recommended).

This is how my adapter looks like:

USBASP_Device_close.jpg

 

To make this adapter work you need to program Atmega8 with driver firmware which can be downloaded from http://www.fischl.de/usbasp/ page (usbasp.2006-12-29.tar.gz -118 kB).

Few words about setting up USBASP adapter for work in Windows XP system.

After firmware is uploaded, then connect USB cable to adapter.

  • Connect cable directly to USB port of computer avoiding Hubs (in my case computer didn’t detect adapter connected through hub);

  • Wait for windows information “New Hardware Found USBASP”. If device isnt detected, check the board for errors and reconnect again;

  • After device is detected Driver setup wizard opens. Select where USBASP driver is located. It is in directory you’ve downloaded with firmware. If you unpacked in C: drive, than driver should be in C:\usbasp.2006-12-29\bin\win-driver\ and press next:

instaling_uasbasp.jpg

 

After successful setup you should see following view in device list:

USBASP_Device_ready.jpg

 

When device is unplugged – the device disappears from the device list. This is it with first stage. Now it is time to start programming with usbasp adapter, but this will be discussed later.

You can download various PCB and circuit configurations directly from http://www.fischl.de/usbasp/ site. Good luck.

ATTiny2313 Monitor tester

This project was born for repairing broken PC monitors. This allows to avoid using a computer while testing monitor patterns. The Tiny monitor tester uses ATTiny2313 AVR MCU running at 20MHz speed. Such speed allows running synchro H and V signals directly form MCU ports. Also circuit converts R,G,B signals to analog using simple R-2R resistor network.

device_4_big.jpg

 

ATTiny2313 Monitor tester:

  • can generate 8 different raster images;

  • supports resolutions of 640x480x60Hz, 800x600x60Hz, 1024x768x60Hz;

  • is near to credit card size;

  • DC adapter or battery powered;

Circuit can be viewed here and single sided PCB

One of test patterns on LCD monitor:

lcd_1_big.jpg

 

I think it is a good device for testing used monitors when buying them in a public market. You don’t need a PC, just plug Tiny Monitor tester and you will see if there are any damages, are all colors working, dead pixels on LCD’s, are different resolutions OK and so on. This thing should be included to a must-to build list.

You can download ready to burn hex software and AVRASM source file in single archive.

Deogen - Tiny monitor tester

 

AVR Laser video projector

This project is made by HÃ¥kon A. Hjortland. The idea is pretty simple and original. He used rotating mirrors to create a video projection. 16 differently tilted mirrors were fixed on a round drum that spins at about 20 – 30 s-1. Each mirror draw a separate line on a screen. For each pixel, the laser is turned on or off. Resolution isn’t very bit -just 16 pixels at each line. But it gives a nice impression.

Avr_laser_projector.jpg

 

As Author states calibration is a hardest part of project. Especially Y direction of mirrors, that each mirror draw a separate line on screen. X calibration is done by software.

The fun part is a Firmware. Program is written in AVR-GCC language. What it does is redraws a frame every 4 or 5 frames.

Watch a video of this project: DivX video: projector.avi (3.5 MiB)

Source code:

projector.c
video_alf.h
test_pattern.h

Additional sources representing an idea:

Building a Laser Projector (PDF) – By Alex Hornstein
TinyProjector – Eight lasers and mirror

Original source by HÃ¥kon A. Hjortland.

Related

To project your photo from a digital camera, first add your photo to your computer. A wireless webcam could also take a great picture. Transfer the photo file to a laser video projector according to the user guide. In no matter than minutes, you’ll have your very own home theater.

AVRJTAG clone in action

Building AVR Jtag clone

Finally I found some time to finish AVRJTAG clone. It was hanging for a while on a breadboard with bunch of wires. I have made an Eagle CAD project with PCB layout you will find at the bottom of article.

AVR_JTAG_clone.jpg

 

I didn’t change the circuit very much from previous, just added ISP header(but didn’t have a chance to test it) and transferred to Eagle project as I didn’t find one ready to build:

AVRjtag_SCH.png

 

Description on how to update firmware is in previous article <Build your own AVR JTAG ICE clone>.

Testing AVR Jtag in action

Let’s give a test run. Using Jtag is easy as using AVR Studio simulator. Difference is only that you have to connect JTAG adapter to target board. Im my case I am using Atmega128L Piconomic board.

AVR_JTAG_clone_to_atmega128.jpg

In the board there is a connector for Jtag adapter/debugger. Second option is to set JTAGEN fuse for target MCU.

Atmega128_for_Jtag.jpg

Otherwise AVR Studio will throw an error:

Jtag_Valid_ID.jpg

After hardware is ready lets try with sample project. For this create AVR-GCC project in AVRStudio environment. Then select debugger platform (JTAG ICE) and AVR MCU(in my case Atmega128):

debug_platform.png

Write a simple program which controls a button and LED: button_led.c

Compile program and start debugger with run command. You can work with JTAG debugger as with simulator – stepping, auto-stepping, break-points, memory views, changing register and memory values and so on.

debugging.png

One difference that program is running in real world. So it is easy to debug platform with additional peripherals connected to MCU. And of course real time execution.

Project files for Eagle CAD and boot-loader are here: avr_jtag_clone.zip

Good luck.

 

24×24 LED dot matrix display control

This is pretty old circuit but I found it interesting to describe here.

24×24 LED display is formed by using 9 8×8 Dot LED matrix displays, that are connected to AT90S2313 MCU. MCU scans an indicator lines in series. Special PC program is written which allows drawing images on screen and transfer them via COM port to device. You can send images in series what gives an animation effect.

matrix2.png

Device circuit:

matrix1.png

Circuit is was built using obsolete AT90S2313 MCU which can be replaced by Attiny2313 MCU with minor modifications of firmware.

To make program work you event don’t need to connect device to computer COM port. You can store images in other master MCU EEPROM memory Each received byte from UART is immediately sent to 8 LEDs, second byte to next 8 LEDs and so on. Bytes has to be sent one by one without delay. USART is working at 115200 baud, 8bits, no parity.

Demo movie (137kB);

Source code

Originals source svv.on.ufanet.ru

IR remote control signal receiver using AVR microcontroller

IR remote control is a device you can find everywhere where you can find TV, VCR or home theatre. Why not to use one of them for controlling your own devices like light, air conditioning etc.

As we know remote control devices uses IR light. This is invisible light about 950nm wavelength. One biggest problem in using IR light is that there many other sources of it like sun, light bulbs, fire. In order to exclude other sources, IR signal is modulated by some frequency. Receiver has to be tuned for this frequency. Mostly remote controls transmit IR signal using 36kHz frequency signals. Transmitting and coding is one part which can be done more easily than receiving and decoding. Decoding is usually performed by using microcontrollers. Firs of all receiver has to get rid of 36kHz carrier frequency. This is not simple task to demodulate signal, this is why special IR receiver IC’s are produced. One of them is TSOP1736:

TSOP1736.jpg

this receiver simply removes 36KHz carrier signal and gives clean pulses that are used for device control. I won’t go too deep in how it works – you can find this information in datasheets. This module is convenient to connect to microcontrollers like AVR or PIC, because it forms TTL signal levels compatible to them.

Lets go further. Remote controls usually uses three different types of modulation: Bi-phase coding; Pulse-distance modulation and Pulse-length code.

pulse_distance.JPG

Pulse-distance modulations is commonly used by LG, JVC, Acorp, Hitachi, Nokia, Aiwa, Akai, AverMedia, NEC. So further we will discuss only this modulation type.

As you have noticed pulse-distance modulation uses fixed length pulses while gap defines weather it is “1”(long gap) or “0”(short gap) logical value. When using Pulse-Distance modulation firs goes LSB then MSB bits. If remote control button is pressed for a long time, then it sends one full packet and then after som time continuously sends unitary pulses informing that button is still pressed. Note, that different manufacturers may use different length of pulses.

Let’s write decoding algorithm for AVR-GCC compiler (Atmega162):

//pin connected to TSOP1736

#define K1 (1<

uint8_t impulse_prev = 0;

uint8_t counter_impulse_1 = 0;

uint8_t flag_rx = 0;

uint8_t counter_impulse_0 = 0;

uint8_t impulse = 0;

uint64_t counter_ik = 0;

uint64_t code = 0;

ISR(TIMER0_OVF_vect)

{

uint8_t c;

uint8_t str[35];

uint64_t i;

//Timer0 initialization

TCNT0=0xFF;

//Invert input signal

if (K1==1) impulse=0; else impulse=1;

if ((impulse_prev==0)&&(impulse==1))

{//rising edge detection

//reset counter

counter_impulse_1=0;

if ((counter_impulse_0>3)&&(flag_rx==1)&&(counter_impulse_0<23))

{//if receiving symbols

if(counter_impulse_0>12)

//logical 1 received

code |=(1<

counter_ik++;

};

};

if((impulse==1)&&(counter_impulse_1<50))

//counting positive pulses

counter_impulse_1++;

if((impulse_prev==1)&&(impulse==0))

{//negative front

counter_impulse_0=0;

if(counter_impulse_1>30)

{//one long synchro pulse

code=0;

counter_ik=0;

flag_rx=1;

}

};

if((impulse==0)&&(flag_rx==1)&(counter_impulse_1<150))

//counting negative pulses

counter_impulse_0++;

if((counter_impulse_0>50)&&(flag_rx==1)&&(impulse==0))

{//end of receive

flag_rx=0;

counter_impulse_0=0;

counter_impulse_1=0;

counter_ik=0;

code=0;

};

impulse_prev=impulse;

}

Interrupt service routine ISR(TIMER0_OVF_vect) is called with frequency of 10.8kHz. This frequency is more than enough comparing with pulse frequency of receiving code. At the beginning of procedure signal is inverted. Current signal level from photo-sensor is defined by variable impulse. Signal reference is signal front (variable impulse_prev). Duration of positive and negative impulses are defined by variables counter_impulse_0 and counter_impulse_1. They show how much time have passed since signal front was registered.

flag_rx variable indicates beginning of signal transfer.

Received code is stored in 64-byte variable code. Variable counter_ik indicates bit number in received code.

Algorithm can receive one code. Using this ISR you can program any control from your fantasy :)

Further example demonstrates hos this can be used to control remote light switch:

remote_light_switch.PNG

Download hex code for this circuit here: remote_light_switch.zip

Remote control button code is stored in EEPROM. It can be programmed by pressing remote control button 20 times. After this code is saved to EEPROM. If you missed button then start again from 0 to 20.

RS232 interface is optional if you want to expand functionality of remote switch by connecting it to another embedded platform or PC. Circuit sends code in ASCII format at kB/s speed.

LED D1 indicates that MCU works OK; LED D2 – indicates about receiving signal; LED D3 – indicates that Light switch is ON/OFF.

Of course it is easy to construct algorithm to another AVR MCU and for different purposes. This article only gives an idea of using a remote control with embedded platforms.

More about microcontroller oscillators

Choice of the microcontroller oscillator depends on many factors. Before choosing one you should consider: Cost, accuracy and environmental parameters. Clock sources can be grouped in two major groups: based on mechanical resonance(crystals and ceramic resonators) and RC (resistor, capacitor) oscillators.

Most popular form of mechanical resonant generators in microcontrollers are Pierce oscillators:

Pierce.PNG

Ceramic and crystal based generators provide very high accuracy and low temperature coefficient. But they have slower startup comparing to RC generators. But RC generator’s accuracy suffer from temperature variations and supply voltage. Nominal frequency can variate from 5% to 50%:

RC.PNG

Oscillator stability can be expressed in figures as ‘±20ppm’ what means 20 parts per million. How to understand this? Imagine that there are 32 million seconds per year. Then in every million seconds generator may miss 20 seconds. SO over a year generator will miss 32×20 seconds, what is around 10 minutes. Standard crystals are rated from ±10ppm to ±100ppm what means from 5 to 50 minutes a year.

What to do is you want more stability. One issue would be to calibrate oscillator and keep it all time in constant temperature like in fridge. But it is not practical. There is another option – Temperature Compensated Crystal Oscillators (TCXO). These oscillators in their package include circuitry that is responsible for temperature compensation. Such devices can provide stability to up to ±0.1ppm, what means around 1 minute every 20 years. But…these crystals are expensive (can be about 100$ cost).

You don’t always have to buy TCXO – sometimes you may add temperature sensor and adjust timing according to temperature.

Other disadvantages of crystals are that they are susceptible to vibrations and they loose stability with the age.

To reduce vibration affect you may chose to use ceramic resonators. They may not be damaged by vibrations as crystals can, but they have much lower stability- typically ±5000ppm what means about 50 minutes/week.

Armega128 bootloader using windows hyper terminal

If you are windows user, there is an easiest solution to program Atmega128 microcontrollers. In http://piconomic.co.za there is nice bootloader binary you can download and use for personal purposes.

First of all you will need to upload bootloader hex file (which is packed in) to Atmega128 and properly program fuses. For my Piconomic board I set fuses like this:

Atmega128 boot fuses

Then plug RS232 cable to computer COM2 (or COM1) port and then from windows select Start->All Programs->Accessories->Communication->HyperTerminal. HyperTerminal is program used for multiple communication purposes like connecting to other computer, telnet, modems and null modems.

Firs of all select connection type – COM2:

Hyper_Settings.JPG

After pressing OK you will be taken to COM2 connection properties:

connection_settings.JPG

After connection settings are done it is time to start bootloading. I have never thought it can be so easy. Just select Transfer->Send file in HyperTerminal program:

send_file_to_Atmega128.JPG

In the opening window select file you want to download. Just remember that binary has to be compiled as BIN not HEX. Second option is to select protocol – how data will be sent to booloader. Bootloader is programmed to support Xmodem protocol:

Xmodem.JPG

Press Send button then Hyperterminal starts waiting for bootloader to respond:

bootload_atmega128.JPG

Just press “Reset” button on your target board and sending will begin automatically. After sending of bin is finished program starts to execute uploaded program.

The AVR fuse bits have been set so that execution starts from the boot vector address. This means that the bootloader will always be executed first. The bootloader sends a ‘C’ character to start a transfer and waits for 1 second for a valid XMODEM-CRC data packet. If the transfer is not successful, it will jump to address 0×0000 and execute the application. This is why we start sending from Hyperterminal first and then press Reset button.

KontrollerLab IDE development software for AVR under Linux

Good news for Linux lovers. The new IDE development software for AVR microcontrollers has shown up. This is KDE based IDE under GPL. It is fully-featured editor which includes serial terminal for debugging, uses AVR-GCC compiler, uisp for serial downloading and avrdude programming software.

Few screen-shots of this tool:

main_window.jpg
Main project window
fuses.jpg
Fuse settings window
proj_config.jpg
Project configuration window
kompiler.jpg
Compiller  settinds
programmer_configuration.jpg
Programmer configurations
linker.jpg
Linker settings

This is first release but is is already ready to start developing AVR projects. I think it’s a nice beginning. Download and try KontrollerLab from http://sourceforge.net/projects/kontrollerlab/

ATMEL announced 3 new low power Tiny AVR microcontrollers with high speed timers

Atmel’s new devices are 20-pin tiny-AVR microcontrollers with high-speed timers.
All three devices are pin-compatible, differing only in the size Flash, EEPROM and SRAM memories.

  • The ATtiny261 has 2 Kbytes of self-programmable Flash memory;
  • The ATtiny461 has 4 Kbytes of self-programmable Flash memory;
  • The ATtiny861 has 8 Kbytes of self-programmable Flash memory.

All devices deliver 20 MIPS throughput when running at maximum 20 Mhz frequency.
The internal 8 MHz RC oscillator and the on-chip PLL can run the 10-bit timer/counter up to 64 Mhz speed. The high-speed timer/counter with three independent PWM generators is ideal for battery chargers, battery monitoring, power monitoring and motor-control applications. All devices have internal EEPROM, pull-up resistors, an internal 8 MHz precision oscillator and 12 general I/O pins for application use. Alternatively, the I/O pins work as ADC inputs or PWM outputs.
ATtiny261, ATtiny461 and ATtiny861 are available in 20-pin SOIC and PDIP and 32-pad QFN packages.

New on WinAVR Tutorial New on WinARM Tutorial