ATMega16 is one of the cheapest and most used microcontrollers due to its multiple pins and feature. It is closest to the ATmega328P but it is smaller in memory size and larger in pins. ATMEL designed ATMega16 by using RSIC CPU and 8-bit CMOS technology which helps it to operate with other TTL/CMOS devices by consuming less power. Its internal structure allows the designer to use the sleep mode, power vs performance methods to use it efficiently by consuming less power. The microcontroller comes in tow packaging and their pins vary at different packages.
Introduction to ATmega16 Microcontroller
The AVR ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. The throughput of AVR ATmega16 is about 1 MIPS per MHz using a single clock per instruction allowing the system designer to optimize power consumption versus processing speed. The AVR has 32 general purpose working registers and a rich instruction set. They are directly connected to the ALU and allow two independent registers to be accessed in one single instruction executed in one clock cycle. Getting started with the Avr microcontroller tutorial helps you to understand real-time examples. Atmel Studio 6 is used for writing c code and generating hex file.
ATmega16 Microcontroller Pinout Diagram Details
This section consists of pin configuration details and step by step information on each GPIO pin.
Power: Every microcontroller required power to operate and ATMega16 gives three power pins, one is power input and the remaining two are ground pins, those are internally connected with each other. Those pins in the microcontroller are:
- VCC – Pin10
- GND – Pin11, Pin31
Oscillator: ATMega16 has internal 8 MHz changeable oscillator but to extend the clock speed an external oscillator will be used at the oscillator pins of the microcontroller which are given below:
- XTAL2 – GPIO12
- XTAL1 – GPIO13
Digital Input/Output: Input and output is the requirement of each device and micro-controller need these functions to communicate with external devices. In ATMega16 there are four ports (A, B, C & D) which comes with a total of 32 input/output pins. All these pins can be used for any input/output control function with external peripherals. Those pins in ATMega16 are given below:
- PA0 – GPIO40
- PA1 – GPIO39
- PA2 – GPIO38
- PA3 – GPIO37
- PA4 – GPIO36
- PA5 – GPIO35
- PA6 – GPIO34
- PA7 – GPIO33
- PB0 – GPIO1
- PB1 – GPIO2
- PB2 – GPIO3
- PB3 – GPIO4
- PB4 – GPIO5
- PB5 – GPIO6
- PB6 – GPIO7
- PB7 – GPIO8
- PC0 – GPIO22
- PC1 – GPIO23
- PC2 – GPIO24
- PC3 – GPIO25
- PC4 – GPIO26
- PC5 – GPIO27
- PC6 – GPIO28
- PC7 – GPIO29
- PD0 – GPIO14
- PD1 – GPIO15
- PD2 – GPIO16
- PD3 – GPIO17
- PD4 – GPIO18
- PD5 – GPIO19
- PD6 – GPIO20
- PD7 – GPIO21
Interrupt: It is one of the most used functions during variating the high voltages but the basic purpose of this function is to get the attention of CPU. In this microcontroller, there are total three interrupt function which can be used by external modules or by an external button to get the attention of CPU. These pins in ATmega16 are listed below:
- INT0 – GPIO16
- INT1 – GPIO17
- INT2 – GPIO3
USART: External devices need to communicate with the microcontroller for multiple kinds of operations. ATMega16 gives a serial communication method for communication and programming. The UART pins are available in the microcontroller to operate with devices serially. It uses two communication pins and some internal programming to communicate but those pins can also be used for programming by using a third pin known as clock pins. The clock pins can also be used for simple data communication instead of programming. All those pins in the microcontroller are listed below:
- TX (output) – GPIO15
- RX (input) – GPIO14
- XCK (clock I/O) – GPIO1
SPI: SPI protocol is one of the best serial communication protocols for multiple modules. It can be used in the case of multiple peripherals to communicate efficiently with the microcontroller. The communication wires consist of three wires two for data and one for the clock, but it also has a third wire which is used for device selection. The device selection pin is knowing as Select Slave pin and it is predefined in the microcontroller but any output pin can be made as a select slave pin by programming. SPI protocol not only use for communication, but it can also be used to program the microcontroller. All SPI pins of ATMega16 are:
- SS’ – GPIO5
- MOSI – GPIO6
- MISO – GPIO7
- SCK – GPIO8
I2C: Some sensors and servos come with another serial communication protocol called I2C. To communicate with those peripherals ATMega16 also gives I2C pins interface. One pin is used for data communication and one for a clock. Both pins are listed below:
- SDA – GPIO23
- SCL – GPIO22
JTAG: These pins are present in most of the board for testing purposes. The reason for designing the JTAG was to test the device and PCB after the manufacturer has completed the design. JTAG is connected to the internal test port but it can also be used for programming the microcontroller and even the bootloader. JTAG pins in the microcontroller are:
- TDI (test data in) – GPIO27
- TDO (test data out) – GPIO26
- TMS (test mode selects) – GPIO25
- TCK (test clock) – GPIO24
Timer: The microcontroller has three internal timers/counter. They can perform by using the internal oscillator or they can also be operated with oscillators used by the microcontroller, but they also could perform the counter by using their own external oscillator. Two timers are 8-bit and one of 16 pins, only two timers support the external pulse input pins to operate. All timers and oscillator pins for timers are given below:
- T0 – GPIO1
- T1 – GPIO2
- TOSC1 – GPIO28
- TOSC2 – GPIO29
Analog Comparator: To compare the analog signal a comparator is being used in the microcontroller. The comparator takes the two inputs of the same signal and the input will be in inverting and non-inverting form. After comparing the analog signal internally their output can be used internally or it can be used to perform any other function on the output pins but all of them will be handled by programming. Analog comparator pins in ATMega16 are listed below:
- AN0 – GPIO3
- AN1 – GPIO4
Capture/Compare/PWM: PWM becomes a basic function for most of the devices to control their voltages. In ATMega16 there are four PWM pins that use Prescaler to generate the desired output signal. Those pins are:
- OC0 – GPIO4
- OC1A – GPIO19
- OC1B – GPIO18
- OC2 – GPIO21
Input Capture: ATMega16 can calculate the external impulse pulse duty cycle and frequency. This calculator can be used to perform the further operation. There is only one pin in the microcontroller which could do that, which is listed below:
- ICP – GPIO20
Analog to Digital Converter: ADC is the requirement of every microcontroller due to the output of multiple modules in analog signal and ATMega16 gives the 8 A/D channels. In the microcontroller, all ADC can be used for analog converter individually but the first analog converter will require external power to act at its AVCC pins. All these pins are given below:
- AVCC – GPIO30
- ADC0 – GPIO33
- ADC1 – GPIO34
- ADC2 – GPIO35
- ADC3 – GPIO36
- ADC4 – GPIO37
- ADC5 – GPIO38
- ADC6 – GPIO39
- ADC7 – GPIO40
AREF: Analog signal maximum value is decided by the supply voltages which sometimes affect the output because of different voltage levels by the analog output device. To overcome this issue an analog Reference pin will be used, where analog output device voltages will be used to measure the output according to the given voltages. Aref pin in the microcontroller is listed below:
- AREF – GPIO32
RESET: To reset the microcontroller ATMega16 an external an internal reset is used. An internal reset can be used through programming but to use the external, a low pulse signal will be required.
- Reset – GPIO9
ATmega16 Microcontroller Features
The AVR ATmega16 provides the following features:
We used Atmega16 because of the following features:
- It has low power CMOS 8-bit controller with AVR RISC
- Its throughput is up to 16MIPS per
- It has 32 General purpose registers directly connected to
- 16 Kbytes In-System programmable flash
- 512 bytes of EEPROM, 1k byte SRAM, JTAG
- Three timer/counter for comparison
- Internal and external interrupts
- Serial programmable USART+I2C protocol
FEATURES & SPECIFICATIONS | |
---|---|
CPU Architecture | 8-bit RISC Architecture |
CPU Frequency | 16MHz |
Operating Voltage Range | (4.5V – 5.5V) |
GPIO PORTS | 32 I/O Pins |
Interrupts | 3 |
Timers | 3 (Two 8-bit and one 16-bit timer) |
PWM | 4 CCP |
ICP | One ICP Pin |
USART | One USART channel |
Serial Interface | One serial interface (two wired) |
I2C | One I2C channel |
SPI | One SPI channel |
JTAG | Available |
Self-Programming | Available |
Watchdog timer | Available |
LAN | Not Available |
CAN | Not Available |
ADC | 8 Channel |
Enhanced USART Module | 1 Channel |
SRAM | 1Kb |
FLASH (Program Memory) | 16Kb |
EEPROM | 512 bytes |
Comparator | 1 |
Packages | PDIP (40-Pins), TQFP (44-Pins) & MLF (44-Pins) |
ATmega16 Microcontroller GPIO Ports and Peripherals
Port A (PA7-PA0) It is used for analog inputs of A / D. But if A/D converter is not enabled it also serves as a self in 8-bit bi-directional port for input and output. Port pins can provide internal pull-up resistors (selected for each bit).
Port B (PB7-PB0) Port B is used as input/output 8-bit bi-directional port having internal pull- up resistors. The output buffers of Port B are of symmetrical drive characteristics having high sink and source capability. When acting as input pins, Port B pins; if pulled externally low; will source current if the pull-up resistors are activated.
Port C (PC7-PC0) Port C’s special feature is JTAG interface. If the JTAG interface is enabled, the pull-up resistors on pins PC5 (TDI), PC3 (TMS) and PC2 (TCK) will be activated even if a reset occurs. Along with this Port C can also be used as input/output 8-bit bi-directional port having internal pull-up resistors.
Port D (PD7-PD0) Port D serves the functions of various special features of the ATmega16 like interrupts input, timer/counter output and UART. In addition to this Port D is used as input/output 8-bit bi-directional port having internal pull-up resistors.
Microcontroller CLOCK SOURCES
ATmega16 has the following clock source options, selectable by Flash Fuse bits as shown below. The clock from the selected source is input to the AVR clock generator and routed to the appropriate modules. In device clocking option for External Crystal or Ceramic Resonator combination for bits is 1111 or 1010. For External Low-frequency Crystal it is 1001 and for External RC Oscillator 1000 or 0101. Calibrated Internal RC Oscillator 0100 or 0001 and for External Clock it is 0000. Bit “1” means un-programmed while “0” means programmed.
Microcontroller USART Module
Main feature used from microcontroller is USART used for serial communication between controller and GSM modem. The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a highly supple serial communication device.General Baud rates supported are 1200, 1800, 2400, 4800, 7200, 9600, 14400, 19200, 38400,57600, 115200. In our project we are using 9600. Serial USART Hardware Elements include:
- USART Clock Generator to provide clock source and set baud rate using UBRR
- USART Transmitter to send a character through TxD pin and handle start/stop bit framing, parity bit, shift
- USART Receiver to receive a character through RxD pin and performs the reverse operation of the
- USART Registers to configure control and monitor the serial
USART Baud Rate Registers comprises of two registers, UBRRH and UBRRL, i.e. in total 16 bits. The UBRRH Register shares the same I/O location as the UCSRC Register. To cater this bit 15 (URSEL) i.e. Register Select is used. This bit selects between accessing the UBRRH or the UCSRC Register. It is read as zero when reading UBRRH. The URSEL must be zero when writing the UBRRH. Bit 14:12 are reserved bits for future use. For compatibility with future devices, these bits must be written to zero when UBRRH is written. Bits 11-0 contain the USART baud rate. The UBRRH contains the four most significant bits, and the UBRRL contains the 8 least significant bits of the USART baud rate. Ongoing transmissions by the transmitter and receiver will be corrupted if the baud rate is changed. Writing UBRRL will trigger an immediate update of the baud rate Prescaler.
USART Control & Status Registers comprises of three registers; UCSRA, UCSRB, and UCSRC; and hold flags and control bits for USART. UCSRA contains following flags: RXC (USART Receive Complete), TXC (USART Transmit Complete), UDRE (USART Data Register Empty), FE (Frame Error), DOR (Data OverRun), PE (Parity Error), MPCM (Multi-processor Communication Mode) and control bit U2X (Double the USART Transmission Speed). UCSRB contains following control bits: RXCIE (RX Complete Interrupt Enable), TXCIE (TX Complete Interrupt Enable), UDRIE (USART Data Register Empty Interrupt Enable), RXEN (Receiver Enable), TXEN (Transmitter Enable), UCSZ2 (Character Size), RXB8 (Receive Data Bit 8) and TXB8 (Transmit Data Bit 8). UCSRC contains following control bits: URSEL (Register Select), UPM1:0 (Parity Mode), USBS (Stop Bit Select), UCSZ1:0 (Character Size) and UCPOL (Clock Polarity).
USART Data Register is the buffer for characters sent or received through the serial port. To start sending a character, write it to UDR. Then to check a received character, read it from UDR. Serial USART main tasks are initializing the serial port, sending a character, receiving a character and sending/receiving formatted strings. Initializing serial port includes setting USART communication parameter (data bit, stop bit, and parity bit), enable transmitter and receiver, setting USART for asynchronous mode and set the baud rate. For sending a character UDRE flag has been set to 1 and then write the character to register UDR for transmission. For receiving a character RXC flag has been set to 1 and then read the received character from register UDR.
ATMega16 Block Diagram
The block diagram of the ATMega16 is given below:
Applications
- The microcontroller found in commercial products.
- It is compatible with multi-sensor devices because most of the pins perform only a single operation.
- Smart industrial machines also use the ATMega16 due to its cheapness and functionality.
- To calculate the frequency and duty cycle of the external device, the ATMega16 is used.
2D Dimension diagram
This is a 2D physical dimension diagram for the DIP package.