Complete RGPV exam-oriented notes on timers, counters, watchdog timer, interrupt controller, PWM, keyboard controller, ADC, RTC and important serial, parallel and wireless communication protocols.
1. Introduction to I/O and Peripheral Devices 7 Marks
Input-output devices connect an embedded processor with the external world. Peripheral devices provide additional functions such as timing, conversion, communication, storage and control.
Sensors / Keys
|
v
+-------------------+
| Input Interface |
+---------+---------+
|
v
+-------------------+
| Processor / MCU |
+----+---------+----+
| |
v v
+---------+ +-----------+
| Memory | |Peripherals|
+---------+ +-----------+
|
v
Outputs / Actuators
Examples of Embedded Peripherals
Timers and counters
Interrupt controller
ADC and DAC
PWM controller
Serial communication interface
Real-time clock
Keyboard and display controller
2. Need for Peripheral Devices
To read physical input through sensors
To control motors, displays and actuators
To generate accurate delays
To count external events
To convert analog signals into digital form
To communicate with other devices
To maintain time and date
To protect the system from software failure
3. Timers 14 Marks
A timer is a hardware peripheral that counts internal clock pulses to measure time intervals or generate accurate delays.
System Clock
|
v
+-----------+ Control Register
| Prescaler |<-------------------
+-----+-----+
|
v
+-----------+
| Timer |
| Register |
+-----+-----+
|
Overflow / Compare Match
|
v
Interrupt or Output Event
Working
The system clock is supplied to the timer.
A prescaler may reduce the clock frequency.
The timer register increments or decrements.
Overflow or compare match generates an event.
The event can set a flag, generate an interrupt or change an output pin.
Applications
Generating delays
Periodic task scheduling
Measuring pulse width
Generating baud rate
Producing PWM signals
Time measurement
Timer Period = Number of Counts ร Clock Period ร Prescaler
4. Counters 7 Marks
A counter counts external events or pulses received through an input pin.
Timer vs Counter
Feature
Timer
Counter
Input source
Internal clock
External pulses
Main purpose
Measure time
Count events
Example
Delay generation
Counting products on conveyor
Applications
Object counting
Frequency measurement
Speed measurement
Event monitoring
Digital tachometer
5. Watchdog Timer 14 Marks
A watchdog timer is a safety timer that automatically resets an embedded system if the software stops operating correctly.
Program Running Normally
|
v
Reset / Refresh Watchdog
|
v
+----------------------+
| Watchdog Countdown |
+----------+-----------+
|
Timeout Occurs?
/ \
No Yes
| |
Continue System Reset
Working
The watchdog starts a countdown.
Correct software periodically refreshes it.
If the program hangs, refresh does not occur.
The watchdog reaches timeout.
It generates a reset or interrupt.
Advantages
Improves system reliability
Recovers from software lock-up
Useful in unattended systems
Provides fault tolerance
Used in automotive controllers, routers, industrial machines and medical devices.
6. Interrupt Controller 14 Marks
An interrupt is a signal that temporarily stops normal program execution and transfers processor control to an Interrupt Service Routine.
Interrupt Sources
Timer ADC UART External Pin
\ | | /
+----+-----+------+
|
v
+-------------------+
| Interrupt |
| Controller |
+---------+---------+
|
v
Processor
|
v
Interrupt Service Routine
Interrupt Sequence
A peripheral generates an interrupt request.
The interrupt controller checks enable and priority.
The CPU completes the current instruction.
Current processor state is saved.
The ISR address is loaded.
The ISR services the event.
The saved state is restored.
Types
Hardware and software interrupts
Maskable and non-maskable interrupts
Vectored and non-vectored interrupts
Edge-triggered and level-triggered interrupts
Polling vs Interrupt
Polling
Interrupt
CPU repeatedly checks device status.
Device informs CPU only when service is needed.
Wastes CPU time.
Better CPU utilization.
Simple implementation.
Requires interrupt hardware and ISR.
7. Pulse Width Modulation 14 Marks
PWM is a technique in which the width of digital pulses is varied to control the average power delivered to a load.
High โโโโโโโโ โโโโโโโโ
โ โ โ โ
Low โโโ โโโโโโโโ โโโโโ
<--- Period --------->
Duty Cycle = On Time / Period
Duty Cycle (%) = (ON Time รท Total Period) ร 100
Working
The signal switches between high and low states.
Frequency may remain constant.
Changing ON time changes the duty cycle.
Higher duty cycle provides higher average output.
Applications
Motor speed control
LED brightness control
Power converters
Audio generation
Servo motor control
Heating control
8. Keyboard Controller 7 Marks
A keyboard controller detects pressed keys, performs scanning and provides the corresponding key code to the processor.
Rows R0 R1 R2 R3
| | | |
+-------------+
C0-| o o o o |
C1-| o o o o | Matrix Keyboard
C2-| o o o o |
C3-| o o o o |
+-------------+
Keyboard Scanner
Matrix Keyboard Scanning
Keys are arranged in rows and columns.
The controller activates one row at a time.
Column inputs are read.
The row-column combination identifies the key.
Debouncing removes false transitions.
Key Debouncing
Mechanical keys produce multiple rapid transitions when pressed. Hardware or software delay is used to recognize only one valid press.
9. Analog-to-Digital Converter 14 Marks
An ADC converts a continuous analog input voltage into a digital binary value that can be processed by an embedded processor.
Analog Sensor
|
v
+----------------+
| Sample & Hold |
+-------+--------+
|
v
+----------------+
| Quantizer |
+-------+--------+
|
v
+----------------+
| Encoder |
+-------+--------+
|
v
Digital Output
ADC Process
Sampling: Measure the analog signal at intervals.
Quantization: Map each sample to a discrete level.
Encoding: Represent the level as binary data.
Number of Quantization Levels = 2โฟ, where n is ADC resolution
Approximate Step Size = Reference Voltage รท 2โฟ
Important Parameters
Resolution
Conversion time
Sampling rate
Reference voltage
Accuracy
Quantization error
Types of ADC
Flash ADC
Successive Approximation ADC
Dual-slope ADC
Sigma-delta ADC
ADC is used with temperature, pressure, light and sound sensors.
10. Real-Time Clock 7 Marks
A real-time clock is a low-power peripheral that maintains calendar time and date even when the main system is turned off.
Main Components
Low-frequency crystal oscillator
Time and date registers
Backup battery
Alarm and interrupt circuit
Serial interface
Applications
Digital clocks
Data loggers
Attendance systems
Alarm systems
Timestamp generation
11. Communication Protocol Terminology 7 Marks
Protocol: Rules for exchanging data.
Node: Device connected to a network.
Master: Device that initiates communication.
Slave: Device that responds to a master.
Host: Main controlling system.
Bus: Shared communication path.
Bandwidth: Data-carrying capacity.
Baud rate: Number of signal symbols per second.
Bit rate: Number of data bits transferred per second.
Simplex: One-way communication.
Half duplex: Both directions, one at a time.
Full duplex: Both directions simultaneously.
Synchronous: Communication uses a shared clock.
Asynchronous: No continuous shared clock.
12. Serial Communication Protocols
Serial communication transfers data one bit at a time through one or a small number of signal lines.
Advantages
Requires fewer wires
Lower cost
Suitable for longer distances
Simple connectors
Reduced electromagnetic interference
Protocols in the Syllabus
I2C
CAN
FireWire
USB
13. I2C Protocol 14 Marks
I2C, or Inter-Integrated Circuit, is a synchronous serial bus that uses two shared signal lines for communication between integrated circuits.