DOC PREVIEW
USC EE 459Lx - ATmega168

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Ming Hsieh Department of Electrical EngineeringEE 459Lx - Embedded Systems Design LaboratoryThe Atmel ATmega168A Microcontrollerby Allan G. Weber1 IntroductionThe Atmel ATmega168A is one member of the Atmel 8-bit microcontroller family. Each member of the familyhas different amounts of RAM, ROM, I/O ports, etc. Depending on the number of external pins requiredthey may come in packages with more than a hundred pins, or with as few as eight. The ATmega168A wasselected for the EE 459 class for a variety of reasons:• Availability of both the chips and development software.• Available in 28-pin DIP (dual-inline package) that fits into available IC sockets.• Enough TTL compatible I/O pins (21) to handle most EE 459L project tasks.• FLASH memory for easy and fast reprogramming.The following notes are meant as a short guide to getting started using the 168A. Additional documentson the EE 459 web site describe using the C software development systems. For more complete informationon any of the topics below, see the full Atmel datasheet or programming manual.2 HardwareThe ATmega168A contains the following components:• 16kb of FLASH memory for program storage.• 1kb of RAM memory.• 512 bytes of EEPROM memory• Two 8-bit and one 16-bit timer/counters. These can count internal clock cycles or external events andgenerate an interrupt when reaching a specified count value.• 6 channels of 10-bit analog-to-digital converter (ADC).• Serial communications port. This can be used to communicate to the COM port of a computer.• I2C interface port for communication with other I2C compatible ICs• 21 lines of general purpose I/O.Not all of these functions are available at the same time. Most of the pins on the chip are connected tomultiple functional units and it is up to the designer to decide what a particular pin does. For example, a pinmight be use as a general purpose I/O line, or it might be ADC input, but it can’t be both simultaneously.EE 459Lx, Rev. 1/15/13 12.1 Minimum ConnectionsIn order to make the microcontroller operate the following connections must be made.2.1.1 Power and GroundThe power supply voltage (5 volts) must be connected to the VCC input on pin 7. The ground connectionsare on pins 8 and 22.2.1.2 ClockSome sort of clock signal must be provided in order for the microcontroller to operate. On the ATmega168Athe clock can come from one of three different sources. The selection of the clock source is done by program-ming fuse bits in the chip.A TTL-compatible clock signal can be generated externally by other logic and connected to the XTAL1input (pin 9.) This probably the easiest way to generate the clock for the EE 459 projects. The lab has asupply of DIP oscillators in some of the more common frequencies. These output a TTL level square wavethat can be fed directly into the microcontroller and to other chips.Alternatively, the processor can generate a clock if a crystal is connected to the XTAL1 and XTAL2inputs. This method uses a plain crystal, not the DIP crystal oscillators as described above.The third method uses an internal oscillator that runs at approximately 8MHz. This is probably theleast accurate way to generate a clock. Do not use this method if your project requires a clock running closeto a specified frequency. The advantage of using the internal clock is that you do not need to provide anyexternal signal and other functions are now available on pin 9. For example it can now be used as Port Bbit 6 (PB6) thus giving the microcontroller 22 I/O pins.In applications where the UART0 serial communications interface is being used, the choice of clockfrequency determines the baud rates that can be used for transmitting and receiving serial data. Theaccuracy of the frequency of the baud rate depends on the clock frequency used for the microcontroller. Ifa high degree of accuracy is required, an external oscillator of the correct frequency will be needed. SeeSec. 2.4 for more information.2.1.3 ResetThe reset input (RESET, pin 1) must be in the high state for the processor to operate normally. This pinhas an internal pull-up and does not have to be externally pulled-up to VCC in order for the processor tooperate normally.2.1.4 SPI ProgrammingThe Flash memory on the ATmega168A is programed using connections to the reset input and three otherpins: PB3, PB4 and PB5. These three I/O pins can be used for other purposes as long as the design allowsthe programming hardware to have sole access to these pins during the programming process. Make surethat none of these pins is used as in input from some source that will continue to drive a signal at the 168Awhile the reset line is in the low state.2.2 I/O PortsWhen used with an external clock, the ATmega168A has 21 pins that can be configured for general purposeI/O. Many of these can also be used for other purposes such as analog-to-digital conversion, timers, etc. Allthe I/O port bits are capable of sourcing or sinking current to drive higher-current devices like LEDs.For each port there are three registers that control the actions of the individual bits of the port:Data Direction Register (DDRx) - These registers determine whether the pins for that port are serving asinputs or outputs. Initially, or upon a reset signal, the bits in the DDRs are all zero which makes thecorresponding I/O port bits inputs. To use a I/O port bit as an output, the corresponding bit in theDDR must be set to a one.EE 459Lx, Rev. 1/15/13 20, 00, 11, 11, 0DDxn, PORTxnInput,pull-up offInput,pull-up onOutput = 1Output = 0Figure 1: State of port bits when changing between input and outputData Register (PORTx) - When an I/O bit is configured as an output the corresponding bit in the PORTxregister control the state of the output. If the bit is a one, the output line will go high. If the bit is azero, the output line will go low. When an I/O bit is configured as in input, the bits in the PORTxregister determine whether the internal pull-up resister is enabled. Writing a one to a bit in PORTxregister turns on the corresponding pull-up resistor, and writing a zero turns it off.Port Input Pins (PINx) - The PINx registers are read-only registers that contain the value on the corre-sponding pin when the pin is configured to be an input. If the pin is high the value in the register is aone, and if the pin is low the value is a zero.A potential problem can sometimes occur in a design that requires switching bits in a port between inputand output. Since


View Full Document

USC EE 459Lx - ATmega168

Download ATmega168
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view ATmega168 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view ATmega168 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?