Each AVR MCU has several internal peripherals that give powerful abilities to your projects. For example internal ADC can be used to convert analog value (say voltage output of some sensor) to a digital value that you can use. And a USART(Universal Synchronous Asynchronous Receiver Transmitter) can be used to connect your MCU with PC. (Example use - A PC serial mouse or A PC controlled Toy Rocket Launcher). This tutorial gives you overview of the process used to interface with these peripherals.
Internal peripherals.
Now you know the basics of peripherals, lets see what peripherals are available in ATmega16 MCU.
- Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
- One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
- Real Time Counter with Separate Oscillator
- Four PWM Channels
- 8-channel, 10-bit ADC 8 Single-ended Channels 7 Differential Channels in TQFP Package Only 2 Differential Channels with Programmable Gain at 1x, 10x, or 200x
- Byte-oriented Two-wire Serial Interface
- Programmable Serial USART
- Master/Slave SPI Serial Interface
- Programmable Watchdog Timer with Separate On-chip Oscillator
- On-chip Analog Comparator
Interfacing Technique.
| |
Fig: Using internal peripherals of AVR MCUs. |
A peripheral is connected to MCU by some special registers. The different registers of any peripherals can be logically of two types-
1)Data registers – which usually contains some data, say byte received from USART or data just read from internal EEPROM.
2)STATUS and CONTROL register – these are used to configure the peripheral according to your need, and to control them from your program. For example the ADMUX register has following bits.
Bit No. |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
| Name | REFS1 | REFS0 | ADLAR | MUX4 | MUX3 | MUX2 | MUX1 | MUX0 |
Interrupts.
As we saw the you can use the STATUS registers to see the what the peripheral has to say to the CPU, like it has just completed the conversion Analog value to digital and the data is ready. But in this way you have to constantly poll the registers. But one more advance feature is INTERRUPTs. Where the peripheral halts the CPU whenever it has something interesting. Then the CPU will jumps to a function called ISR (interrupt service routine) which is provided by you. You can configure which events should interrupt the CPU and also provide the ISR.Steps to use peripherals.
- First setup the peripheral according to your need.
- Set interrupts and ISRs (Optional)(beginners may skip for simplicity).
- Command the peripheral or read / write data.
Download PDF version| Get Adobe Reader Free !!!
| What's Next |
| We will use a very useful peripheral of AVR – The ADC (analog to digital converter). |



Good introduction.
Please try to include some example codes too (preferably in WinAVR C) to make it useful!
Hi Abhijeet,
ThanX for you comments.
This is just an introduction so that you have the overview when we jump start using the actual peripheral. This tutorial only provides the concepts that will help beginners. The later tutorials will have all the CODES !!!
So don’t worry.
The tutorial is so simple and so good.It makes things so easy for a beginner.Thanks a lot.keep postin.I’m eagerly waitin for the next post.
Hi Atiya,
Thanx
Many tutorials comming up !
Please do post comments and share your thoughts. This makes me improve the site
ThanX again
Hello I have read all you have write about AVR, because I must program in Atmega32.
You have help my very much.
Can you recommend mi a book for learn AVR “Atmega 32” or a page in internet?
Thanks for the help!!!!
@Percy
Welcome!
Best way to learn deeply about AVRs is their datasheets. Go through tutorial on my site and then when you have basic knowledge abt a topic go an explore the datasheets!
I also program with ATmega32 and all example you get here applies directly to ATmega8 , ATmega16 and ATmega32. These chips are best to get started with AVRs
i m very impressed with your website .. d tutorials written y u r so simple .n can b understood anyone ..me myself being a beginner can tell u that u have done an amazing job coz making things simple for others is the tougest job !!! keep it up !!!
simple, easy to understand , short tutorials
so these tutorials have all the qualities of good tutorial. you must write a book on avr fo beginners (hint: just combine the tutorials)
This tutorial very simple and good for beginners. i think you include some programe example in assambly language because there are many people include me we are use assembly language.
hello sir your portal is superb!
here i am beginner in avr atmega32
here got confused with term uint16_t,why we used or is this type we used for specific platform.
so please guide me.
thanks in advance
I’m learning a lot from this page
. Thanks…
hello thax 4 the intro can you recommend any good books on the subject?
@AvrBestever,
If you wait for a book to come out, then you will find that chip in Museum.
Tech world is fast and furious.