Posted on Leave a comment

ATMega328P Microcontroller

What is ATMEGA328P Microcontroller and Its Pin COnfiguration

ATMEGA328P is elite, low power controller from Microchip. ATMEGA328P is a 8-piece microcontroller dependent on AVR RISC design. It is the most well known of all AVR controllers as it is utilized in ARDUINO sheets. ATMEGA328P is a 28 stick chip as appeared in stick outline above. Numerous pins of the chip here have more than one capacity. We will portray elements of each stick in underneath table.

Pin No.Pin nameDescriptionSecondary Function
1PC6 (RESET)Pin6 of  PORTCPin by default is used as RESET pin. PC6 can only be used as I/O pin when RSTDISBL Fuse is programmed.
2PD0 (RXD)Pin0  of  PORTDRXD (Data Input Pin for USART)USART Serial Communication Interface[Can be used for programming]
3PD1 (TXD)Pin1 of  PORTDTXD (Data Output Pin for USART)USART Serial Communication Interface[Can be used for programming] INT2( External Interrupt 2 Input)
4PD2 (INT0)Pin2  of  PORTDExternal Interrupt source 0 
5PD3 (INT1/OC2B)Pin3  of  PORTDExternal Interrupt source1 OC2B(PWM – Timer/Counter2 Output Compare Match B Output)
6PD4 (XCK/T0)Pin4  of  PORTDT0( Timer0 External Counter Input)XCK ( USART External Clock I/O)
7VCC Connected to positive voltage
8GND Connected to ground
9PB6 (XTAL1/TOSC1)Pin6  of  PORTBXTAL1 (Chip Clock Oscillator pin 1 or External clock input)TOSC1 (Timer Oscillator pin 1)
10PB7 (XTAL2/TOSC2)Pin7  of  PORTBXTAL2 (Chip Clock Oscillator pin 2)TOSC2 (Timer Oscillator pin 2)
11PD5(T1/OC0B)Pin5 of  PORTDT1(Timer1 External Counter Input) OC0B(PWM – Timer/Counter0 Output Compare Match B Output)
12PD6 (AIN0/OC0A)Pin6  of  PORTDAIN0(Analog Comparator Positive I/P) OC0A(PWM – Timer/Counter0 Output Compare Match A Output)
13PD7 (AIN1)Pin7  of  PORTDAIN1(Analog Comparator Negative I/P) 
14PB0 (ICP1/CLKO)Pin0  of  PORTBICP1(Timer/Counter1 Input Capture Pin) CLKO (Divided System Clock. The divided system clock can be output on the PB0 pin)
15PB1 (OC1A)Pin1  of  PORTBOC1A (Timer/Counter1 Output Compare Match A Output)
16PB2 (SS/OC1B)Pin2  of  PORTBSS (SPI Slave Select Input).  This pin is low when controller acts as slave.[Serial Peripheral Interface (SPI) for programming] OC1B (Timer/Counter1 Output Compare Match B Output)
17PB3 (MOSI/OC2A)Pin3  of  PORTBMOSI (Master Output Slave Input). When controller acts as slave, the data is received by this pin. [Serial Peripheral Interface (SPI) for programming]OC2 (Timer/Counter2 Output Compare Match Output)
18PB4 (MISO)Pin4  of  PORTBMISO (Master Input Slave Output). When controller acts as slave, the data is sent to master by this controller through this pin. [Serial Peripheral Interface (SPI) for programming]
19PB5 (SCK)Pin5  of  PORTBSCK (SPI Bus Serial Clock). This is the clock shared between this controller and other system for accurate data transfer.[Serial Peripheral Interface (SPI) for programming]
20AVCC Power for Internal ADC Converter
21AREF Analog Reference Pin for ADC
23PC0 (ADC0)Pin0  of  PORTC ADC0 (ADC Input Channel 0)
24PC1 (ADC1)Pin1  of  PORTCADC1 (ADC Input Channel 1)
25PC2 (ADC2)Pin2  of  PORTC ADC2 (ADC Input Channel 2)
26PC3 (ADC3)Pin3  of  PORTC ADC3 (ADC Input Channel 3)
27PC4 (ADC4/SDA)Pin4  of  PORTCADC4 (ADC Input Channel 4)SDA (Two-wire Serial Bus Data Input/output Line)
28PC5 (ADC5/SCL)Pin5  of  PORTCADC5 (ADC Input Channel 5)SCL (Two-wire Serial Bus Clock Line)

Features of ATMEGA328P

ATMEGA328P – Simplified Features
CPU8-bit AVR
Number of Pins28
Operating Voltage (V)+1.8 V TO +5.5V
Number of programmable  I/O lines23
Communication InterfaceMaster/Slave SPI Serial Interface(17,18,19 PINS) [Can be used for programming this controller]Programmable Serial USART(2,3 PINS) [Can be used for programming this controller]Two-wire Serial Interface(27,28  PINS)[Can be used to connect peripheral devices like Servos, sensors and memory devices]
JTAG InterfaceNot available
ADC Module6channels, 10-bit resolution ADC
Timer ModuleTwo 8-bit counters with Separate Prescaler and compare mode, One 16-bit counter with Separate Prescaler,compare mode and capture mode.
Analog Comparators1(12,13 PINS)
DAC ModuleNil
PWM channels6
External Oscillator0-4MHz @ 1.8V to 5.5V0-10MHz @ 2.7V to 5.5V0-20MHz @ 4.5V to 5.5V
Internal Oscillator8MHz  Calibrated Internal Oscillator
Program Memory TypeFlash
Program Memory or Flash memory32Kbytes[10000 write/erase cycles]
CPU Speed1MIPS for 1MHz
RAM2Kbytes Internal SRAM
Watchdog TimerProgrammable Watchdog Timer with Separate On-chipOscillator
Program LockYes
Power Save ModesSix Modes[Idle, ADC Noise Reduction, Power-save, Power-down, Standby and Extended Standby]
Operating Temperature-40°C to +105°C(+105 being absolute maximum, -40 being absolute minimum)

ATMEGA328P Replacements


ATMEGA328P Alternatives


Where to Use ATMEGA328P

Although we have many controllers ATMEGA328P is most popular of all because of its features and cost. ARDUINO boards are also developed on this controller because of its features.

  • With program memory of 32 Kbytes ATMEGA328P applications are many.
  • With various POWER SAVING modes it can work on MOBILE EMBEDDED SYSTEMS.
  • With Watchdog timer to reset under error it can be used on systems with minimal human interference.
  • With advanced RISC architecture, the controller executes programs quickly.  
  • Also with in chip temperature sensor the controller can be used at extreme temperatures.

These all features add together promoting ATMEGA328P further.

How to Use ATMEGA328P

ATMEGA328 is utilized like some other controller. All there to do is customizing. Controller essentially executes the program given by us at any moment. Without programming controller essentially waits without taking any kind of action. As stated, first we have to program the controller and that is finished by composing the suitable program document in the ATMEGA328P FLASH memory. Subsequent to dumping this program code, the controller executes this code and gives suitable reaction.

Entire process of using an ATMEGA328P goes like this:

  1. List the functions to be executed by controller.
  2. Write the functions in programming language in IDE programs.

You can download the IDE program for free in company websites. IDE program for AVR controllers is ‘ATMEL STUDIO’.

  1. ATMEGA328P programming can also be done in ARDUINO IDE.
  2. After writing the program, compile it to eliminate errors.
  3. Make the IDE generate HEX file for the written program after compiling.
  4. This HEX file contains the machine code which should be written in controller flash memory.
  5. Choose the programming device (usually SPI programmer made for AVR controllers) which establishes communication between PC and ATMEGA328P. You can also program ATMEGA328P using ARDUINO UNO board.
  6. Run the programmer software and choose the appropriate hex file.
  7. Burn the HEX file of written program in ATMEGA328P flash memory using this program.
  8. Disconnect the programmer, connect the appropriate peripherals for the controller and get the system started.

How to Use ATMega328P using Arduino

Since ATmega328P is used in Arduino Uno and Arduino nano boards, you can directly replace the arduino board with ATmega328 chip. For that first you need to install the Arduino bootloader into the chip (Or you can also buy a chip with bootloader – ATMega328P-PU). This IC with bootloader can be placed on Arduino Uno board and burn the program into it. Once Arduino program is burnt into the IC, it can be removed and used in place of Arduino board, along with a Crystal oscillator and other components as required for the project. Below is the pin mapping between Arduino Uno and ATmega328P chip.


ATMEGA328P Applications

There are hundreds of applications for ATMEGA328P:

  • Industrial control systems.
  • SMPS and Power Regulation systems.
  • Digital data processing.
  • Analog signal measuring and manipulations.
  • Embedded systems like coffee machine, vending machine.
  • Motor control systems.
  • Display units.
  • Peripheral Interface system.

2D Model

All measurements are in millimeters.


ATMega328P Microcontroller Datasheet

The Atmel®
ATmega328/P is a low-power CMOS 8-bit
microcontroller based on the AVR® enhanced RISC architecture. By
executing powerful instructions in a single clock cycle, the ATmega328/P
achieves throughputs close to 1MIPS per MHz. This empowers system
designer to optimize the device for power consumption versus processing
High Performance, Low Power Atmel®AVR® 8-Bit Microcontroller Family
• Advanced RISC Architecture
– 131 Powerful Instructions
– Most Single Clock Cycle Execution
– 32 x 8 General Purpose Working Registers
– Fully Static Operation
– Up to 20 MIPS Throughput at 20MHz
– On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory Segments
– 32KBytes of In-System Self-Programmable Flash program
– 1KBytes EEPROM
– 2KBytes Internal SRAM
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data Retention: 20 years at 85°C/100 years at 25°C(1)
– Optional Boot Code Section with Independent Lock Bits
• In-System Programming by On-chip Boot Program
• True Read-While-Write Operation
– Programming Lock for Software Security
• Atmel® QTouch® Library Support
– Capacitive Touch Buttons, Sliders and Wheels
– QTouch and QMatrix® Acquisition
– Up to 64 sense channels
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
– Real Time Counter with Separate Oscillator
– Six PWM Channels
– 8-channel 10-bit ADC in TQFP and QFN/MLF package
• Temperature Measurement
– 6-channel 10-bit ADC in PDIP Package
Temperature Measurement
– Two Master/Slave SPI Serial Interface
– One Programmable Serial USART
– One Byte-oriented 2-wire Serial Interface (Philips I2C compatible)
– Programmable Watchdog Timer with Separate On-chip Oscillator
– One On-chip Analog Comparator
– Interrupt and Wake-up on Pin Change
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated Oscillator
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby, and Extended Standby
• I/O and Packages
– 23 Programmable I/O Lines
– 28-pin PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-pad QFN/MLF
• Operating Voltage:
– 1.8 – 5.5V
• Temperature Range:
– -40°C to 105°C
• Speed Grade:
– 0 – 4MHz @ 1.8 – 5.5V
– 0 – 10MHz @ 2.7 – 5.5V
– 0 – 20MHz @ 4.5 – 5.5V
• Power Consumption at 1MHz, 1.8V, 25°C
– Active Mode: 0.2mA
– Power-down Mode: 0.1μA
– Power-save Mode: 0.75μA (Including 32kHz RTC)

The Atmel AVR® core combines a rich instruction set with 32 general purpose working registers. All the
32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers
to be accessed in a single instruction executed in one clock cycle. The resulting architecture is more code
efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers.
The ATmega328/P provides the following features: 32Kbytes of In-System Programmable Flash with
Read-While-Write capabilities, 1Kbytes EEPROM, 2Kbytes SRAM, 23 general purpose I/O lines, 32
general purpose working registers, Real Time Counter (RTC), three flexible Timer/Counters with compare
modes and PWM, 1 serial programmable USARTs , 1 byte-oriented 2-wire Serial Interface (I2C), a 6-
channel 10-bit ADC (8 channels in TQFP and QFN/MLF packages) , a programmable Watchdog Timer
with internal Oscillator, an SPI serial port, and six software selectable power saving modes. The Idle
mode stops the CPU while allowing the SRAM, Timer/Counters, SPI port, and interrupt system to
continue functioning. The Power-down mode saves the register contents but freezes the Oscillator,
disabling all other chip functions until the next interrupt or hardware reset. In Power-save mode, the
asynchronous timer continues to run, allowing the user to maintain a timer base while the rest of the
device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules except
asynchronous timer and ADC to minimize switching noise during ADC conversions. In Standby mode, the
crystal/resonator oscillator is running while the rest of the device is sleeping. This allows very fast start-up
combined with low power consumption. In Extended Standby mode, both the main oscillator and the
asynchronous timer continue to run.
Atmel offers the QTouch® library for embedding capacitive touch buttons, sliders and wheels functionality
into AVR microcontrollers. The patented charge-transfer signal acquisition offers robust sensing and
includes fully debounced reporting of touch keys and includes Adjacent Key Suppression® (AKS™)
technology for unambiguous detection of key events. The easy-to-use QTouch Suite toolchain allows you
to explore, develop and debug your own touch applications.
The device is manufactured using Atmel’s high density non-volatile memory technology. The On-chip ISP
Flash allows the program memory to be reprogrammed In-System through an SPI serial interface, by a
conventional nonvolatile memory programmer, or by an On-chip Boot program running on the AVR core.
The Boot program can use any interface to download the application program in the Application Flash
memory. Software in the Boot Flash section will continue to run while the Application Flash section is
updated, providing true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System
Self-Programmable Flash on a monolithic chip, the Atmel ATmega328/P is a powerful microcontroller that
provides a highly flexible and cost effective solution to many embedded control applications.
The ATmega328/P is supported with a full suite of program and system development tools including: C
Compilers, Macro Assemblers, Program Debugger/Simulators, In-Circuit Emulators, and Evaluation kits.

Leave a Reply

Your email address will not be published.