ARM Microcontroller Peripherals: GPIO, Timers, PWM, ADC/DAC, SPI, I2C, UART – Common Features - 8.3 | Module 8: Modern Microcontrollers: RISC and ARM | Microcontroller
K12 Students

Academics

AI-Powered learning for Grades 8–12, aligned with major Indian and international curricula.

Professionals

Professional Courses

Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.

Games

Interactive Games

Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.

8.3 - ARM Microcontroller Peripherals: GPIO, Timers, PWM, ADC/DAC, SPI, I2C, UART – Common Features

Practice

Interactive Audio Lesson

Listen to a student-teacher conversation explaining the topic in a relatable way.

General Purpose Input/Output (GPIO)

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Let's start with GPIO. General Purpose Input/Output pins are versatile and the most fundamental peripheral in our microcontrollers. They can be configured as either inputs or outputs. Can anyone tell me what happens in input mode?

Student 1
Student 1

In input mode, GPIO pins can read the state of an external signal!

Teacher
Teacher

Exactly! They can read HIGH or LOW states. And in output mode, what can we do?

Student 2
Student 2

We can drive the pin to HIGH or LOW voltage, right?

Teacher
Teacher

Right again! Also, GPIO pins often have additional features like interrupt capabilities. What does that mean?

Student 3
Student 3

It means we can trigger an interrupt when a signal changes, useful for responding instantly to events!

Teacher
Teacher

Great summary, everyone! To remember GPIO, think of it as a 'General Purpose pin: Input or Output' - GPI/O.

Student 4
Student 4

That's a neat acronym!

Timers

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Next, let’s delve into timers. Can anyone name some roles that timers play in microcontrollers?

Student 1
Student 1

They can generate delays and periodic interrupts!

Student 2
Student 2

And there are different types of timers like basic timers, watchdog timers, and RTCs!

Teacher
Teacher

Perfect! Watchdog timers are particularly interesting because they help prevent system failures. What do we need to remember when using a timer to generate a delay?

Student 3
Student 3

You need to set the timer's auto-reload value correctly based on its clock speed!

Teacher
Teacher

Exactly! If you have a 1 MHz clock and you need a 1-second delay, you set the auto-reload to 1,000,000. Let's summarize timers as 'Time-keeping with precision'.

Pulse Width Modulation (PWM)

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Now onto Pulse Width Modulation or PWM. What is the main function of PWM?

Student 4
Student 4

It generates a square wave with a variable duty cycle!

Teacher
Teacher

Right! By adjusting the duty cycle, which is the percentage of time the signal is HIGH, we can control things like motor speed and LED brightness. Can someone give me an example?

Student 1
Student 1

If we have a 50% duty cycle, the average voltage would be half of the supply voltage!

Teacher
Teacher

Correct! So, at a 3.3V supply with 50% duty cycle, the average would be 1.65V. Anyone remember how to calculate the average voltage?

Student 2
Student 2

Average Voltage = Duty Cycle times Supply Voltage!

Teacher
Teacher

Fantastic! Remember PWM as 'Power in Waves, Mercy in modulation'.

Analog-to-Digital Converter (ADC)

Unlock Audio Lesson

Signup and Enroll to the course for listening the Audio Lesson

0:00
Teacher
Teacher

Let’s discuss Analog-to-Digital Converters or ADCs. What do they do?

Student 3
Student 3

They convert a continuous analog signal into a discrete digital value!

Teacher
Teacher

Exactly! And what determines how precise the conversion is?

Student 4
Student 4

The resolution, like 8-bit or 10-bit!

Teacher
Teacher

That's right! A 10-bit ADC can yield 1024 discrete values. Can anyone give a practical application for ADCs?

Student 1
Student 1

Reading sensors like temperature or light sensors!

Teacher
Teacher

Excellent application! Remember ADC as 'A Reliable Digital converter'.

Introduction & Overview

Read a summary of the section's main ideas. Choose from Basic, Medium, or Detailed.

Quick Overview

This section discusses key peripherals associated with ARM microcontrollers, detailing how each peripheral functions and its applications.

Standard

ARM microcontrollers integrate various peripherals that enhance their functionality, including general-purpose input/output (GPIO), timers, pulse width modulation (PWM), analog-to-digital converters (ADC), digital-to-analog converters (DAC), and serial communication interfaces like SPI, I2C, and UART. Each peripheral offloads tasks from the CPU, simplifying embedded system designs.

Detailed

The section covers the fundamental peripherals embedded within ARM microcontrollers that contribute significantly to their performance and versatility. Key components include:

  1. General Purpose Input/Output (GPIO): Provides configurable pins for digital input and output, featuring options like pull-up/down resistors and interrupt capabilities. Applications range from reading button states to controlling LEDs.
  2. Timers: Essential for creating precise time delays and generating periodic interrupts. Different types include basic timers, general-purpose timers, watchdog timers, and real-time clocks (RTCs). For instance, timers can be programmed to generate 1-second delays based on clock speed.
  3. Pulse Width Modulation (PWM): Allows control over digital signals to mimic analog voltage levels. It's commonly used in applications like motor speed control and LED brightness adjustment through varying duty cycles.
  4. Analog-to-Digital Converter (ADC): Converts analog signals into digital values. Important parameters include resolution and reference voltage. For example, a 10-bit ADC translates input voltages into one of 1024 distinct digital levels.
  5. Digital-to-Analog Converter (DAC): Converts digital values back into analog signals, useful in applications like audio output.
  6. Serial Peripheral Interface (SPI), Inter-Integrated Circuit (I2C), and Universal Asynchronous Receiver/Transmitter (UART): These are critical for communication between microcontrollers and external devices, each with distinctive operational structures and ideal use cases, from sensor data acquisition to debugging.

Each peripheral is essential for various applications, allowing ARM microcontrollers to effectively manage tasks in embedded systems.

Audio Book

Dive deep into the subject with an immersive audiobook experience.

General Purpose Input/Output (GPIO)

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

General Purpose Input/Output (GPIO):

  • Function: The most fundamental peripheral. GPIO pins are configurable digital pins that can be set as either inputs or outputs.
  • Input Mode: Reads the logical state (HIGH/LOW) of an external signal. Can be configured with pull-up/pull-down resistors.
  • Output Mode: Drives the pin to a logical HIGH (e.g., 3.3V or 5V) or LOW (0V).
  • Features: Often include configurable drive strength, open-drain capabilities, and external interrupt capabilities (triggering an interrupt on a rising/falling edge or change of state).
  • Application: Reading buttons, controlling LEDs, simple digital signaling.

Detailed Explanation

General Purpose Input/Output (GPIO) pins are vital components of ARM microcontrollers. They can serve as either inputs or outputs. In input mode, GPIO pins sense the electrical state of external devices, such as buttons, allowing the microcontroller to respond to user actions. In output mode, GPIO pins can send signals to external devices, such as LEDs or relays, enabling the microcontroller to control them. Features like pull-up/pull-down resistors help stabilize input states, and the ability to generate interrupts allows immediate responses to changes.
- Chunk Title: Timers
- Chunk Text: ### Timers:

  • Function: Essential for timing events, generating delays, and creating periodic interruptions. Microcontrollers typically have multiple independent timers.
  • Types:
  • Basic Timers: Simple up/down counters, often used to generate periodic interrupts (e.g., for real-time operating system ticks).
  • General-Purpose Timers: More advanced, supporting various modes like input capture (measuring pulse widths), output compare (generating precise pulses or waveforms), and PWM generation.
  • Watchdog Timers: Critical for system reliability. A countdown timer that, if not periodically reset by the software, will reset the microcontroller to prevent the system from getting stuck in an infinite loop.
  • Real-Time Clocks (RTC): Low-power timers that keep track of calendar time (seconds, minutes, hours, date) even when the main power is off (if backed by a small battery).
  • Numerical Example: Delay Generation. To generate a 1-second delay using a timer clocked at 1 MHz (1,000,000 cycles/second) with a pre-scaler of 1 (no division): Set the timer's auto-reload value (or target count) to 1,000,000. When the counter reaches this value, it will have elapsed 1 second, and an interrupt can be generated.
  • Detailed Explanation: Timers in ARM microcontrollers allow for precise control of timing for various events. Basic timers can trigger actions at regular intervals, essential for time-sensitive tasks in embedded applications. General-purpose timers offer additional functionality like measuring the time of external events or generating specific waveforms. Watchdog timers ensure reliability by resetting the microcontroller if it becomes unresponsive. Real-time clocks maintain accurate time information even when the power is off, which is useful for applications requiring timestamps.

Examples & Analogies

Imagine a timer in a kitchen. If you set it for one minute, it alerts you when time runs out, like how microcontrollers use timers to trigger events. If you forget to check on the food, the oven timer (watchdog timer) can remind you or turn off the oven if you've neglected it for too long.

Pulse Width Modulation (PWM)

Unlock Audio Book

Signup and Enroll to the course for listening the Audio Book

Pulse Width Modulation (PWM):

  • Function: Generates a square wave whose duty cycle (the ratio of ON time to the total period) can be varied. The frequency of the PWM signal is usually fixed.
  • Principle: By rapidly switching a digital output pin ON and OFF, and varying the percentage of time it's ON, PWM effectively creates an analog-like voltage or power level. The average voltage is proportional to the duty cycle.
  • Application: Controlling DC motor speed, dimming LEDs, generating analog signals (with a low-pass filter), controlling servo motors.
  • Formula: Average Voltage = (Duty Cycle / 100%) * Supply Voltage
  • Duty Cycle = (ON Time / Total Period) * 100%
  • Numerical Example: With a 3.3V supply and a 50% duty cycle PWM signal: Average Voltage = 0.50×3.3V=1.65V. With a 10% duty cycle: Average Voltage = 0.10×3.3V=0.33V.

Detailed Explanation

Pulse Width Modulation (PWM) is a technique used to control the amount of power delivered to a device. By rapidly switching a signal on and off, the average voltage available to the device can be adjusted. For example, if a pin is turned on for half the time in a given period (50% duty cycle), the device receives half the average voltage. This method is commonly used for controlling brightness in LEDs and speed in DC motors, allowing for efficient power management in embedded systems.
- Chunk Title: Analog-to-Digital Converter (ADC)
- Chunk Text: ### Analog-to-Digital Converter (ADC):

  • Function: Converts a continuous analog voltage signal from the real world into a discrete digital value that the microcontroller can process.
  • Resolution: Determines the precision of the conversion (e.g., 8-bit, 10-bit, 12-bit). A 10-bit ADC has 210=1024 distinct digital levels.
  • Reference Voltage (VREF): The maximum analog voltage that the ADC can measure.
  • Numerical Example: For a 10-bit ADC with VREF = 3.3V: Step Size (LSB voltage) = VREF / 2Resolution = 3.3V / 1024 ≈ 0.00322V. If the ADC reads a digital value of 512, the input analog voltage is approximately 512 × 0.00322V ≈ 1.648V.
  • Application: Reading sensor values (temperature, light, pressure), battery voltage monitoring, audio input.
  • Detailed Explanation: An Analog-to-Digital Converter (ADC) allows microcontrollers to interpret real-world signals by converting them into digital data. The ADC takes a continuous voltage from sensors and translates it into numeric values that the microcontroller can understand. The resolution of the ADC specifies how precise the measurements can be, with higher resolutions providing finer distinctions between voltage levels. Understanding VREF is crucial, as it sets the maximum input voltage the ADC can handle. This capability is essential in applications where physical phenomena need to be monitored and processed.
  • Chunk Title: Digital-to-Analog Converter (DAC)
  • Chunk Text: ### Digital-to-Analog Converter (DAC):
  • Function: Converts a digital value from the microcontroller into a continuous analog voltage or current output. Less common than ADCs on MCUs, but present on many.
  • Resolution: Determines the number of distinct output voltage levels (e.g., 8-bit, 12-bit).
  • Numerical Example: For an 8-bit DAC with VREF = 3.3V: Step Size (LSB voltage) = 3.3V / 256 ≈ 0.01289V. If the microcontroller outputs a digital value of 128 to the DAC, the analog output voltage will be approximately 128 × 0.01289V ≈ 1.65V.
  • Application: Generating audio waveforms, controlling analog motor drivers, creating arbitrary voltage signals.
  • Detailed Explanation: A Digital-to-Analog Converter (DAC) performs the reverse function of an ADC, converting digital signals back into analog form. This allows ARM microcontrollers to produce analog voltages or currents from digital values, making it possible to create audio signals, control motors more smoothly, or generate other analog outputs. Resolution influences the number of distinct voltage levels available; a higher resolution DAC can create finer variations in output.
  • Chunk Title: Serial Peripheral Interface (SPI)
  • Chunk Text: ### Serial Peripheral Interface (SPI):
  • Function: A synchronous, full-duplex serial communication protocol. Operates in a master-slave configuration.
  • Wires: Typically uses 4 wires:
  • SCLK (Serial Clock): Clock signal generated by the master.
  • MOSI (Master Out, Slave In): Data from master to slave.
  • MISO (Master In, Slave Out): Data from slave to master.
  • CS/SS (Chip Select/Slave Select): Active-low signal from master to select a specific slave device.
  • Characteristics: High-speed, simple to implement in hardware, no addressing overhead (uses CS). Can have multiple slaves connected.
  • Application: Communicating with Flash memory, SD cards, LCDs, digital sensors (accelerometers, gyroscopes).
  • Detailed Explanation: SPI (Serial Peripheral Interface) is a communication protocol that allows microcontrollers to communicate with other devices like sensors and memory chips. SPI is characterized by its synchronous operation, meaning data transmission occurs in sync with a clock signal. The master device controls this clock signal, allowing for high-speed transactions. The use of separate lines for incoming and outgoing data enables full-duplex communication, allowing data to be sent and received simultaneously.
  • Chunk Title: Inter-Integrated Circuit (I2C)
  • Chunk Text: ### Inter-Integrated Circuit (I2C):
  • Function: A synchronous, half-duplex serial communication protocol. Operates in a multi-master, multi-slave configuration.
  • Wires: Uses only 2 wires (open-drain, requiring pull-up resistors):
  • SDA (Serial Data Line): Bidirectional data line.
  • SCL (Serial Clock Line): Clock signal generated by the current master.
  • Characteristics: Lower speed than SPI but very popular for its low pin count and ability to connect many devices to the same bus. Each device has a unique 7-bit or 10-bit address.
  • Application: Communicating with RTCs, EEPROMs, temperature sensors, small OLED displays, many types of I/O expanders.
  • Detailed Explanation: I2C (Inter-Integrated Circuit) is another communication protocol that is popular due to its simplicity and efficiency. Unlike SPI, I2C uses fewer wires, which helps manage connections between multiple devices. Each device on the I2C bus has a unique address, allowing the master to communicate with one or more slaves via simple commands. I2C operates in a half-duplex manner, where data can travel in one direction at a time, making it simpler but slower than SPI.
  • Chunk Title: Universal Asynchronous Receiver/Transmitter (UART)
  • Chunk Text: ### Universal Asynchronous Receiver/Transmitter (UART):
  • Function: An asynchronous, full-duplex serial communication protocol. "Asynchronous" means there is no shared clock signal between sender and receiver.
  • Wires: Typically uses 2 wires:
  • TX (Transmit): Output from sender.
  • RX (Receive): Input to receiver.
  • Characteristics: Simpler hardware than synchronous protocols. Relies on both sides agreeing on a common baud rate (bits per second) and data framing parameters (start bit, data bits, parity, stop bits) for synchronization.
  • Application: Debugging (sending data to a PC via a USB-to-UART converter), communicating with GPS modules, Bluetooth modules, GSM modems, or other microcontrollers.
  • Common Baud Rates: 9600, 19200, 115200 bps.
  • Detailed Explanation: UART (Universal Asynchronous Receiver/Transmitter) is a widely used communication protocol that allows devices to exchange data without needing a shared clock signal. Instead, it relies on a common baud rate agreed upon by both sender and receiver, which determines the speed at which data is transmitted. Due to its simplicity, UART is often found in situations where easy communication is needed, such as interfacing with a computer or other simple devices.

Examples & Analogies

No real-life example available.

Definitions & Key Concepts

Learn essential terms and foundational ideas that form the basis of the topic.

Key Concepts

  • GPIO: Configurable pins for input/output

  • Timers: Create delays and occasional interrupts

  • PWM: Control signal duty cycle for varying outputs

  • ADC: Convert analog signals to digital values

  • DAC: Convert digital values back to analog

  • SPI: Communication between devices using clock

  • I2C: Efficient multi-device communication

Examples & Real-Life Applications

See how the concepts apply in real-world scenarios to understand their practical implications.

Examples

  • In GPIO, pushing a button can set a pin HIGH, allowing the microcontroller to read it as input.

  • A timer can execute a task every 500ms by counting clock cycles to control periodic events.

  • PWM is widely used in dimming LEDs where the brightness is controlled by varying the duty cycle.

  • An ADC allows reading the temperature from a thermistor, which varies resistance and creates an analog voltage.

  • DAC can be used to generate audio signals by converting digital values from sound files into variable voltage.

Memory Aids

Use mnemonics, acronyms, or visual cues to help remember key information more easily.

🎵 Rhymes Time

  • GPIO, oh what a treat, Input or output, easy to meet!

📖 Fascinating Stories

  • Once, a tiny GPIO pin dreamed of becoming a star by reading signals and controlling lights. Everyone loved the little pin's ability to help devices communicate!

🧠 Other Memory Gems

  • To remember PWM: ‘Powerful Waves, Multiply’ to indicate adjusting the wave.

🎯 Super Acronyms

For ADC, think 'Analog to Digital Converter' – A to D to C!

Flash Cards

Review key concepts with flashcards.

Glossary of Terms

Review the Definitions for terms.

  • Term: GPIO

    Definition:

    General Purpose Input/Output; configurable digital pins in microcontrollers for input and output operations.

  • Term: PWM

    Definition:

    Pulse Width Modulation; a technique to control the amount of power delivered to loads by switching on and off rapidly.

  • Term: ADC

    Definition:

    Analog-to-Digital Converter; a device that converts an analog signal into a digital representation.

  • Term: DAC

    Definition:

    Digital-to-Analog Converter; a device that converts a digital signal back into an analog signal.

  • Term: UART

    Definition:

    Universal Asynchronous Receiver/Transmitter; a hardware communication protocol that allows asynchronous serial communication.

  • Term: I2C

    Definition:

    Inter-Integrated Circuit; a multi-master, multi-slave, packet switched, single-ended, serial communication bus.

  • Term: SPI

    Definition:

    Serial Peripheral Interface; a synchronous serial communication protocol used for short-distance communication.

  • Term: Timer

    Definition:

    A hardware component that tracks time and can trigger events based on predefined intervals.