Pantech.AI

Introduction to the PIC microcontroller

PIC Microcontrollers

PIC microcontrollers, produced by Microchip, come in 8-bit, 16-bit, and 32-bit versions. The 8-bit PIC microcontrollers are organized into several distinct families, including:

FeaturesBaselineMid-RangeEnhanced Mid-RangeAdvanced PIC18
  Families PIC10, PIC12, PIC16PIC10, PIC12PIC12Fxxx,PIC16FxxxPIC12Fxxx,PIC16Fxxx
 Program     Memory  Max 3 KB  Max 14 KB  Max 28 KB  Max 128 KB
Data MemoryMax 138 BytesMax 368 BytesMax 28 KBMax 4 KB
Performance5 MIPS5 MIPS8 MIPS16 MIPS
Features
8-bit ADC,
Internal Oscillator,
Comparator
Addition to baseline
I2C/SPI,
PWM,
UART,
10-bit ADC
Addition to midrange
Multiple Peripheral communication
High Performance
PWM with independent Time-Space
CAN
USB
ETHERNET
LIN
PLL Clock generator

Many PIC microcontroller families are pin-compatible, although the functions assigned to certain pins may differ. For instance, while the PIC16F877A has I2C pins (SDA and SCL) multiplexed with PORTC, the PIC18F4550 has them multiplexed with PORTB, yet both remain pin-compatible.

The family names of PIC microcontrollers include specific suffixes that indicate certain characteristics:

  • PIC18FXXX – “F” signifies Flash Program Memory
  • PIC16CXXX – “C” indicates EPROM Program Memory
  • PIC18LFXXX – “LF” denotes Low Voltage operation

These suffixes vary across families. When a newer part is developed to replace an older one, an additional letter is added to the end of the part number, as seen with the 16F877 and its newer version, 16F877A.

The following section will provide a detailed overview of the PIC18 family, which is often preferred for development purposes.

Let’s begin with the PIC18F4550 microcontroller from the PIC18 family.

The PIC18F4550 is an 8-bit microcontroller based on RISC architecture. Key specifications include:

  • Timers: One 8-bit and three 16-bit timers (Timer0 to Timer3)
  • USART: 1 built-in Enhanced USART
  • ADC: 10-bit Analog-to-Digital Converter with 13 channels
  • CCP and Enhanced CCP Modules: Capture, Compare, and PWM functionality
  • USB: USB V2.0 support with transfer speeds ranging from 1.5 Mb/s to 12 Mb/s
  • MSSP (Master Synchronous Serial Port): Supports both I2C and SPI protocols
  • Memory: 256 Bytes of EEPROM, 32 KB of Flash memory, and 2 KB internal SRAM
  • Ports: Includes Ports A, B, C, D, and E
  • Streaming Parallel Port: Facilitates USB streaming transfers
  • Interrupts: Three external interrupts
  • Oscillator:
  • Four crystal modes, including a High Precision PLL for USB functionality
  • Two external clock modes supporting frequencies up to 48 MHz
  • Internal oscillator with 8 user-selectable frequencies ranging from 32 kHz to 8 MHz
  • Secondary oscillator using Timer1 at 32 kHz
  • LIN Bus Support

PIC18F4550 Pin Diagram

The PIC18F4550 microcontroller includes five ports, each with three key registers:

  • TRIS Register: Configures data direction for each pin (0 for output, 1 for input).
  • LAT Register: Acts as the Data Output register.
  • PORT Register: Used to read the levels on input pins.

Additionally, PORTB and PORTD have weak internal pull-up resistors. Upon Power-On Reset (POR), pins that are multiplexed with ADC functions default to ADC mode. To utilize these pins as digital I/O, the ADC mode must be switched to digital using the PBADEN register.

Features of PIC18F4550 MCU

Timer

The PIC18F4550 features a built-in Timer module that can be used for various applications, such as generating precise delays, pulse counting, and pulse measurement.

  • Timer0, Timer2, and Timer3 are 16-bit timers, while Timer1 is an 8-bit timer.
  • Each timer has its own dedicated Control and Status Registers for configuration.

To use the timers for counting external pulses or event counting, external signals must be connected to specific pins:

  • RA4 is used for Timer0, and this input is referred to as T0CKI.
  • RC0 is used for Timer1, and this input is referred to as T1CKI.

These pins receive the external pulse signals for the timers.

ADC

The PIC18F4550 features a 10-bit, 13-channel ADC (Analog-to-Digital Converter). The channels are labeled as AN0, AN1, AN2, … AN12. This ADC is used to read analog signals from various sensors, such as temperature, humidity, and accelerometers, and convert these analog signals into digital values for further processing.

UART

  • The PIC18F4550 includes a Universal Asynchronous Receiver Transmitter (UART), which facilitates serial communication between two devices.
  • For long-distance communication, the UART serial protocol is commonly used. Many electronic modules, such as GSM, GPS, Bluetooth, and Wi-Fi, utilize UART for communication, often supporting various baud rates like 9600, 115200, and others.
  • To implement UART communication, the Rx (Receiver) and Tx (Transmitter) pins are used for data reception and transmission, respectively.

External Interrupt

The INT0, INT1, and INT2 pins on the PIC18F4550 are used for External Interrupts. These interrupts are applied to detect specific events triggered by incoming pulses and take the appropriate action. The events can be triggered by either a positive edge or a negative edge.

Capture/Compare/PWM CCP Module

The PIC18F4550 includes a Capture/Compare/PWM (CCP) module, which serves various applications:

  • Capture: This mode is used to measure the frequency, pulse, or duty cycle of an input pulse. To use this, connect the input pulse to the RC2 pin and configure the module in capture mode.
  • Compare: This mode is used to generate a square wave. To use it, load a count value into a register, which is then compared with a timer. When a match occurs, a high or low pulse is generated at the RC2 pin.
  • PWM: This mode is used in applications such as controlling the speed of a DC motor, adjusting the intensity of an LED, or generating a sine wave.

Master Synchronous Serial Port (MSSP)

  • The Master Synchronous Serial Port (MSSP) module is a serial interface on the PIC18F4550, designed for communication with other peripheral or microcontroller devices. These peripherals may include serial EEPROMs, shift registers, display drivers, A/D converters, and more.
  • The MSSP module can operate in one of two modes:
  1. I2C (Inter-Integrated Circuit)
    I2C is a two-wire communication protocol that uses just two lines: SDA (Serial Data) and SCL (Serial Clock). These signals are multiplexed with PORTB.0 (SDA) and PORTB.1 (SCL). The communication speed typically ranges from 100 kHz to 400 kHz. I2C is widely used in applications such as interfacing with gyroscopes, magnetometers, and other peripheral devices.
  2. SPI (Serial Peripheral Interface)
    SPI is another serial communication protocol that utilizes four wires: SDI (Serial Data Input), SDO (Serial Data Output), SCK (Serial Clock), and SS’ (Slave Select). It is commonly used for communication between devices like SD cards, ADCs, and more. Both SPI and I2C protocols offer higher speeds compared to UART communication, and both operate under a master-slave configuration.
  • Universal Serial Bus (USB)
    The PIC18F4550 also includes an integrated USB interface, which serves as a parallel communication medium. The USB functionality provides a Streaming Parallel Port (SPP) for high-speed data transfer to and from external systems.
  • Power Saving
    For applications where power consumption is critical, the PIC18F4550 offers a sleep mode. This mode, also referred to as Power Saving Mode, allows the device to reduce power usage when idle.

Leave a Comment

Your email address will not be published. Required fields are marked *