Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

CHAPTER 1: INTRODUCTION TO MICROCONTROLLER

A generic microcontroller typically consists of several functional blocks that work


together to execute a wide range of tasks. Here is a simplified block diagram of a generic
microcontroller:

1. Central Processing Unit (CPU):


o The CPU is the brain of the microcontroller, responsible for executing
instructions.
o It includes an Arithmetic Logic Unit (ALU) for mathematical and logical
operations.
2. Memory:
o Program Memory (Flash/ROM): Stores the firmware or program code.
o Data Memory (RAM): Stores data temporarily during program execution.
3. Peripheral Interface:
o Input/output Ports (GPIO): Used to interface with external devices.
o Timers/Counters: Used for generating precise time delays or measuring
external events.
o Serial Communication Ports (UART, SPI, I2C): Enable communication
with other devices.
4. Analog-to-Digital Converter (ADC):
o Converts analog signals (e.g., sensor readings) to digital values for
processing.
5. Digital-to-Analog Converter (DAC):
o Converts digital signals to analog for generating analog output.
6. Clock Circuit:
o Generates the necessary clock signals for synchronization of internal
operations.
7. Interrupt Controller:
o Manages and prioritizes interrupt requests from various sources.
8. Control Unit:
o Manages the overall operation of the microcontroller, including instruction
decoding and execution control.
9. Bus System:
o Data bus: Transfers data between different components.
o Address bus: Specifies the memory location for read or write operations.
o Control bus: Carries control signals for coordinating activities.
10. Power Management Unit:
o Manages power supply and consumption, including sleep modes for low
power operation.
11. Reset Circuit:
o Generates a reset signal to initialize the microcontroller.
12. Watchdog Timer:
o Monitors the execution of the program and resets the microcontroller if
necessary.
Compare Microprocessor and microcontroller
Microprocessor Microcontroller
Microprocessors are designed for Microcontrollers are integrated systems
general-purpose computing tasks. They combining a processor core with various
focus on processing data and executing peripherals.
instructions.
Lack built-in peripherals for specific Designed for specific tasks, often in
applications. embedded systems where real-time
processing and interaction with the
environment are crucial.
Commonly used in devices that require Commonly used in embedded systems,
significant computing power, such as such as household appliances, automotive
personal computers, servers, and high- systems, industrial control, and IoT
performance systems. devices.
Relies on external components and Includes on-chip peripherals like GPIO,
support chips for peripheral functions timers, communication interfaces, and
and I/O operations. often on-chip memory (RAM,
Flash/ROM).
Offers greater flexibility in configuring Reduces the need for external
the system for specific needs. components for basic functions.
Intel Core series, AMD Ryzen series are Atmel AVR, Microchip PIC, and ARM
examples of microprocessors used in Cortex-M series are examples of
personal computers. microcontrollers commonly used in
embedded systems.

A brief History of PIC microcontroller

The history of PIC (Peripheral Interface Controller) microcontrollers traces back to the
development efforts of General Instrument's Microelectronics Division in the 1970s. Here
is a brief overview of the history of PIC microcontrollers:

1. Early Development (1970s):


o General Instrument (GI) developed the PIC microcontroller family, starting
with the PIC1650 and PIC1655, as part of their Microelectronics Division.
o These early PICs were based on the Harvard architecture and featured a
limited set of instructions.
2. Acquisition by Microchip Technology (1980):
o In 1985, Microchip Technology, a spin-off of GI, acquired the rights to the
PIC microcontroller technology.
o Microchip continued the development and expansion of the PIC
microcontroller family.
3. Introduction of PIC16 Series (1993):
o The PIC16 series, introduced in 1993, marked a significant advancement.
It featured an enhanced instruction set, flash memory for program storage,
and integrated peripherals.
o These microcontrollers gained popularity in various applications due to
their cost-effectiveness and ease of use.
4. PIC18 Series (2000):
o Microchip introduced the PIC18 series, which featured enhanced
capabilities, larger memory, and improved peripherals.
o The PIC18 series found applications in a wide range of industries, including
automotive, industrial control, and consumer electronics.
5. PIC32 Series (2007):
o The PIC32 series, introduced in 2007, represented a transition to 32-bit
microcontrollers, offering higher performance and expanded capabilities.
o These microcontrollers were designed for applications requiring more
processing power and featured MIPS32 architecture.
6. Introduction of Enhanced PIC16 Series (2010s):
o Microchip continued to enhance the PIC16 series with new features,
improved peripherals, and increased memory, making them suitable for a
broader range of applications.
7. Expansion of Families and Features (2010s-2020s):
o Microchip expanded the PIC microcontroller families to include specialized
series like PIC24, dsPIC (Digital Signal Controller), and others.
o Enhanced features, increased integration, and improved development
tools contributed to the popularity of PIC microcontrollers in diverse
industries.
8. Continued Evolution (2020s):
o As of my knowledge cut off in January 2022, Microchip continues to
innovate and release new PIC microcontroller products with advanced
features, improved performance, and increased integration.

Throughout their history, PIC microcontrollers have become widely adopted in various
applications due to their reliability, cost-effectiveness, and a broad range of available
devices to meet different requirements. The microcontrollers have played a crucial role
in embedded systems, industrial automation, consumer electronics, and many other
fields.

Overview of PIC 18 family and features.

The PIC18 family of microcontrollers, developed by Microchip Technology, is a popular


series known for its versatility and broad range of applications. Here's an overview of the
PIC18 family and its features:

Key Features of PIC18 Microcontrollers:

1. Architecture:
o PIC18 microcontrollers use a modified Harvard architecture with an 8-bit
data path and a 16-bit instruction word.
o Features a RISC (Reduced Instruction Set Computing) architecture for
efficient and fast execution of instructions.
2. Memory:
o Flash Program Memory: PIC18 devices have flash memory for program
storage. The size of the flash memory varies across different devices within
the family.
o RAM (Random Access Memory): Includes on-chip RAM for data storage
during program execution.
3. Peripheral Integration:
o PIC18 microcontrollers offer a wide range of integrated peripherals,
making them suitable for diverse applications.
o Common peripherals include GPIO (General Purpose Input/Output),
timers, UART (Universal Asynchronous Receiver-Transmitter), SPI (Serial
Peripheral Interface), I2C (Inter-Integrated Circuit), and PWM (Pulse
Width Modulation).
4. Analog Features:
o Integrated Analog-to-Digital Converters (ADCs) for converting analog
signals to digital values.
o Some members of the PIC18 family may also include Digital-to-Analog
Converters (DACs) for generating analog output.
5. Communication Interfaces:
o UART, SPI, and I2C communication interfaces facilitate connectivity with
other devices.
o USB (Universal Serial Bus) support is available in certain PIC18
microcontrollers.
6. Timers and PWM:
o Multiple timers/counters for generating accurate time delays and
managing periodic events.
o Pulse Width Modulation (PWM) modules for controlling motor speed, LED
brightness, and other applications.
7. Interrupt System:
o An interrupt system for handling external events and prioritizing interrupt
requests.
8. Low-Power Modes:
o Power-saving features, including low-power modes and sleep modes, to
optimize energy consumption in battery-powered applications.
9. Security Features:
o Some PIC18 devices offer security features such as code protection and
data EEPROM/Flash write protection to safeguard intellectual property.
10. Development Tools:
o A variety of development tools, including integrated development
environments (IDEs) like MPLAB X, compilers, and debugging tools,
support PIC18 microcontroller development.
11. Variety of Packages:
o PIC18 microcontrollers come in various packages, offering flexibility in
terms of board design and space constraints.

Applications:

PIC18 microcontrollers find applications in a wide range of industries, including:

• Industrial automation
• Consumer electronics
• Medical devices
• Automotive systems
• Home appliances
• Lighting control
• Embedded control systems

Internal Bus Structure of PIC Microcontroller

The internal bus structure of PIC18 microcontrollers is designed to facilitate


communication and data transfer between various internal modules and subsystems.
Keep in mind that the specifics may vary slightly among different PIC18 microcontroller
models, but the following overview provides a general understanding:

1. Program Memory Bus:


o Responsible for fetching instructions from the program memory (Flash
memory).
o Utilizes the Harvard architecture, which means separate buses for program
memory and data memory.
o Allows parallel access to program instructions while performing data
operations.
2. Data Memory Bus:
o Handles data transfer between the CPU and various peripherals, as well as
between the CPU and data memory (RAM).
o Operates independently of the program memory bus for simultaneous data
access.
3. Internal Buses:
o System Bus: Connects the CPU to various internal modules, such as timers,
UART, SPI, I2C, and other peripherals.
o Peripheral Buses: Dedicated internal buses may exist to efficiently
connect the CPU to specific peripherals, enhancing communication speed.
4. Register File:
o Working registers within the register file are used by the CPU for
temporary storage and manipulation of data during program execution.
o Register banks allow for efficient context switching between different
tasks.
5. Interrupt Bus:
o Connects the CPU to various interrupt sources, allowing the
microcontroller to respond quickly to external events and interrupts.
6. Clock and Control Bus:
o Carries clock signals and control signals for synchronization and
coordination of internal operations.
o Includes control lines for managing data transfer, memory operations, and
peripheral interactions.
7. Direct Memory Access (DMA) Bus (if applicable):
o Some PIC18 microcontrollers may support Direct Memory Access (DMA),
allowing peripherals to directly access memory without CPU intervention
for enhanced performance.
8. Bus Matrix (if applicable):
o In more advanced PIC18 microcontrollers, a bus matrix may be used to
efficiently route data between different modules and peripherals,
optimizing data flow within the device.

Clock Frequency

The clock frequency of a PIC18 microcontroller is a critical parameter that influences the
speed at which the microcontroller executes instructions and performs operations. The
clock frequency is determined by an external oscillator or a crystal connected to the
microcontroller.

PIC18 microcontrollers typically support a wide range of clock frequencies, allowing


designers to choose the most suitable frequency for their applications. The clock
frequency can be configured based on the oscillator configuration settings in the
microcontroller's configuration registers.

Here are some key points regarding the clock frequency of PIC18 microcontrollers:

1. Oscillator Types:
o PIC18 microcontrollers can use various types of oscillators, including
internal oscillators, external crystals, resonators, or external clock sources.
o The choice of oscillator depends on the specific requirements of the
application, such as accuracy, stability, and power consumption.
2. Internal Oscillator:
o Some PIC18 microcontrollers have an internal oscillator, which eliminates
the need for an external crystal or resonator.
o The internal oscillator frequency is usually specified in the
microcontroller's datasheet.
3. External Crystal or Resonator:
o Many PIC18 microcontrollers are designed to work with an external crystal
or resonator for improved accuracy and stability.
o The clock frequency is determined by the external oscillator's frequency.
4. Clock Frequency Configuration:
o The clock frequency can be configured using the configuration bits in the
microcontroller. This is typically done in the configuration word or
configuration registers.
o The configuration bits specify the oscillator source, frequency range, and
other settings.
5. Frequency Ranges:
o PIC18 microcontrollers often support different frequency ranges, such as
low-frequency ranges (LF), medium-frequency ranges (MF), and high-
frequency ranges (HF).
o The specific frequency range may vary based on the microcontroller model.
6. Crystal Oscillator Modes:
o PIC18 microcontrollers may support different crystal oscillator modes,
such as HS (High-Speed Crystal), XT (Crystal), and LP (Low-Power Crystal).
o The oscillator mode influences the stability and accuracy of the clock
source.
7. Maximum Frequency:
o The maximum clock frequency that a PIC18 microcontroller can support is
specified in its datasheet.
o It is important to ensure that the chosen clock frequency does not exceed
the microcontroller's maximum rated frequency.
8. Power Consumption:
o The clock frequency can impact the power consumption of the
microcontroller. Higher clock frequencies generally lead to higher power
consumption.

Machine Cycle and Instruction Cycle

Machine Cycle:

A machine cycle is the basic unit of time during which the PIC 18 microcontroller
performs a single operation. It consists of a sequence of states required to execute one
instruction. The machine cycle is further divided into several clock cycles, and the number
of clock cycles in a machine cycle depends on the oscillator frequency and the specific
instruction being executed.

The machine cycle is typically divided into four states:

1. Fetch: During this state, the microcontroller retrieves the instruction from
memory.
2. Decode: The microcontroller decodes the fetched instruction to determine the
operation to be performed.
3. Execute: The actual execution of the operation specified by the instruction takes
place in this state.
4. Write: If necessary, the results of the operation are written back to memory or
registers.

Instruction Cycle:

The instruction cycle, also known as an "execution cycle" or "execution time," is the time
required to complete the execution of a single instruction. It is measured in terms of the
number of machine cycles needed to execute the instruction. The instruction cycle is
determined by the specific instruction being executed and the oscillator frequency.

For PIC 18 microcontrollers, most instructions require multiple machine cycles to


complete. The number of machine cycles per instruction can vary, typically ranging from
1 to 4 or more, depending on the complexity of the instruction.

The instruction cycle is a crucial parameter when calculating the execution time of a
program or when determining the maximum achievable throughput of the
microcontroller.

Example:

As an example, consider a PIC 18 microcontroller running at a certain oscillator


frequency. If an instruction takes, say, 2 machine cycles to complete, and each machine
cycle consists of 4 clock cycles, then the instruction cycle would be 8 clock cycles.

Keep in mind that the specific details, such as the number of machine cycles per
instruction, can vary between different PIC 18 microcontroller models. Therefore, it's
essential to refer to the specific datasheet and reference manual of the PIC 18
microcontroller you are working with for accurate and detailed information on machine
cycles and instruction cycles.

You might also like