Signal Conditioning and Data Acquisition System
117603Module 3: Embedded Microcontrollers – PIC18F / Others
Q1(e). Which of the following is NOT part of a typical microcontroller? (i) CPU (ii) RAM (iii) I/O Ports (iv) Hard Disk2025?m
Module 3: Embedded Microcontrollers – PIC18F / Others
View this question on its own page →Which of the following is NOT part of a typical microcontroller?
(i) CPU
(ii) RAM
(iii) I/O Ports
(iv) Hard DiskWorked SolutionAnswer
Correct option: (iv) Hard Disk
Explanation
A typical microcontroller integrates essential computing and control resources on a single chip, such as:
- CPU: Executes program instructions.
- RAM: Temporarily stores variables and runtime data.
- I/O ports: Interface with sensors, actuators and external devices.
- Timers/counters: Generate timing functions and count events.
- Peripherals: May include ADC, communication interfaces, PWM and other modules.
A hard disk is a separate mass-storage device and is not normally an integrated component of a microcontroller.
Therefore, the correct answer is (iv).
Q1(f). A timer in a microcontroller counts: (i) External pulses only (ii) Internal clock pulses (iii) Code instructions (iv) Data bytes2025?m
Module 3: Embedded Microcontrollers – PIC18F / Others
View this question on its own page →A timer in a microcontroller counts:
(i) External pulses only
(ii) Internal clock pulses
(iii) Code instructions
(iv) Data bytesWorked SolutionAnswer
Correct option: (ii) Internal clock pulses
Explanation
A timer in a microcontroller is generally driven by the internal system clock or a clock derived from it. It increments its count at regular intervals and is used for generating delays, measuring time intervals, scheduling tasks and producing periodic events.
A counter can instead be configured to count external events or pulses.
Example
If a timer receives a 1 MHz clock, one clock period is:
The timer can therefore measure time by counting these clock periods.
Therefore, the correct answer is (ii).
Q1(f). Which interface generally uses two signal lines, SDA and SCL? (i) UART (ii) USB (iii) I2C (iv) SPI20262m
Module 3: Embedded Microcontrollers – PIC18F / Others
View this question on its own page →Which interface generally uses two signal lines, SDA and SCL?
(i) UART
(ii) USB
(iii) I2C
(iv) SPIWorked SolutionAnswer: (iii) I2C
I2C uses only two lines: SDA (serial data) and SCL (serial clock), with addressing for multiple devices. SPI needs 4 lines and UART uses TX/RX.
Q1(g). RISC microcontrollers are characterized by: (i) Many complex instructions (ii) Simple and fast instructions (iii) No registers (iv) Only analog operations2025?m
Module 3: Embedded Microcontrollers – PIC18F / Others
View this question on its own page →RISC microcontrollers are characterized by:
(i) Many complex instructions
(ii) Simple and fast instructions
(iii) No registers
(iv) Only analog operationsWorked SolutionAnswer
Correct option: (ii) Simple and fast instructions
Explanation
RISC (Reduced Instruction Set Computer) microcontrollers use a relatively small and simple instruction set. Instructions are designed to execute efficiently, often in a small number of clock cycles.
Main characteristics of RISC
- Small and simple instruction set.
- Fast instruction execution.
- Large or efficient register usage.
- Simple instruction formats.
- Efficient pipelining in many architectures.
- Suitable for embedded real-time applications.
This approach makes the processor easier to implement and can provide high performance for a given clock frequency.
Therefore, the correct answer is (ii).
Q1(g). In SPI, the line used to select a slave is: (i) SDA (ii) TX (iii) Chip Select (iv) SCL20262m
Module 3: Embedded Microcontrollers – PIC18F / Others
View this question on its own page →In SPI, the line used to select a slave is:
(i) SDA
(ii) TX
(iii) Chip Select
(iv) SCLWorked SolutionAnswer: (iii) Chip Select
SPI has MOSI, MISO, SCK and a Chip Select (CS/SS) line per slave. Pulling CS low selects that slave. SDA and SCL belong to I2C.
Q4(b). Explain the architecture of a microcontroller with neat block diagram. Describe the basics of assembly language and C-language programming used for microcontrollers.20257m
Module 3: Embedded Microcontrollers – PIC18F / Others
View this question on its own page →Explain the architecture of a microcontroller with neat block diagram. Describe the basics of assembly language and C-language programming used for microcontrollers.
Worked SolutionSolution: Microcontroller Architecture, Assembly and C Programming
Microcontroller Architecture
A microcontroller is a compact integrated circuit containing a processor, memory, I/O and peripherals for embedded control applications.
┌─────────────────────┐ │ CPU │ │ ALU + Control Unit │ │ Registers │ └──────────┬──────────┘ │ System Bus ┌────────────────┼────────────────┐ ↓ ↓ ↓ Program Memory Data Memory I/O Ports Flash/ROM RAM/EEPROM GPIO │ │ │ └────────────────┼────────────────┘ ↓ Timers / Counters ADC / PWM / DAC SPI / I²C / UARTMajor blocks
- CPU: Executes instructions.
- ALU: Performs arithmetic and logical operations.
- Registers: High-speed temporary storage.
- Program memory: Stores firmware.
- RAM: Stores temporary variables and stack data.
- EEPROM/Flash: Stores non-volatile data or program code.
- GPIO: Interfaces with external sensors and actuators.
- Timers/Counters: Generate delays and measure/count events.
- ADC/DAC/PWM: Interface between digital electronics and analog systems.
- Communication peripherals: SPI, I²C, UART/USART and others.
Assembly Language Programming
Assembly language uses processor-specific mnemonics representing machine instructions.
Example:
MOVLW 05H MOVWF COUNT INCF COUNT, FThe exact instructions depend on the microcontroller architecture.
Advantages
- Precise hardware control.
- Efficient execution.
- Small and predictable code.
Limitations
- Difficult to write and maintain for large applications.
- Processor-specific.
C Language Programming
C provides structured, readable programming while still allowing direct hardware control through registers, pointers and bit operations.
Example:
#include <stdint.h> int main(void) { uint8_t count = 0; while (1) { count++; } }In practical firmware, initialization functions configure clocks, GPIO, ADC, timers and communication peripherals before the main loop executes.
Assembly vs C
Feature Assembly C Readability Low High Hardware control Very direct Direct through registers/APIs Portability Low Higher Development time Longer Shorter Optimization Can be highly optimized Compiler-dependent Conclusion
A microcontroller combines processing, memory and peripherals in one device. Assembly provides low-level control, while C provides a practical balance of performance, readability and portability for embedded DAQ applications.
Q5(a). Describe the working of ADC and DAC in a microcontroller system with examples.20257m
Module 3: Embedded Microcontrollers – PIC18F / Others
View this question on its own page →Describe the working of ADC and DAC in a microcontroller system with examples.
Worked SolutionSolution: ADC and DAC in a Microcontroller System
ADC: Analog-to-Digital Converter
An ADC converts an analog voltage into a digital code that a microcontroller can process.
Working
Analog Sensor → Signal Conditioning → ADC → Digital Code → CPU- The analog signal is applied to the ADC input.
- The ADC samples the signal.
- The input range is divided into discrete levels.
- The nearest digital code is generated.
- The microcontroller reads the code and converts it into engineering units.
For an ideal -bit ADC with input range :
Approximately, the ADC code is:
Example
For a 10-bit ADC with 0–5 V input:
DAC: Digital-to-Analog Converter
A DAC converts a digital number generated by the microcontroller into an analog voltage or current.
CPU → Digital Code → DAC → Analog Voltage → ActuatorFor an ideal -bit voltage DAC with reference :
The exact transfer equation depends on the DAC architecture and datasheet conventions.
Applications
- ADC: temperature, pressure, light and biomedical sensors.
- DAC: waveform generation, motor control references, audio and analog actuator control.
ADC vs DAC
Feature ADC DAC Conversion Analog → Digital Digital → Analog Input Voltage/current Digital code Output Digital code Analog voltage/current Use Measurement Control/output generation Conclusion
ADC enables the microcontroller to measure the physical world, while DAC enables it to generate controlled analog outputs.
Q5(a). Describe the architecture of a PIC18F microcontroller and discuss the role of timers and counters.20267m
Module 3: Embedded Microcontrollers – PIC18F / Others
View this question on its own page →Describe the architecture of a PIC18F microcontroller and discuss the role of timers and counters.
Worked SolutionPIC18F Architecture
The PIC18F family is an 8-bit RISC microcontroller from Microchip with Harvard architecture (separate program and data buses), so instructions and data are fetched at the same time.
MermaidDiagramRendering diagram…Main features
Block Description CPU 8-bit, 16-bit instruction width, about 75 instructions, hardware multiplier 8x8 Program memory Flash, 16 KB to 128 KB Data memory SRAM up to 4 KB, banked, plus special function registers EEPROM Non-volatile storage for settings I/O ports PORTA to PORTE with TRIS direction registers Peripherals 10-bit ADC, comparators, CCP/PWM, UART, SPI, I2C Interrupts Priority-based, high and low levels Clock Internal or external oscillator with PLL Timers and counters
A timer counts internal clock pulses (), so it measures time. A counter counts external pulses on a pin, so it counts events.
Timer Size Typical use Timer0 8 or 16 bit Delays, event counting Timer1 16 bit Real-time clock, capture Timer2 8 bit PWM time base Timer3 16 bit Capture/compare Delay: .
Applications: periodic ADC sampling, PWM motor control, pulse width and frequency measurement, timeouts.
Exam tip
Draw the block diagram, name Harvard architecture and give the timer vs counter difference.
Q5(b). Describe ADC and DAC interfacing with a microcontroller. Compare SPI and I2C communication.20267m
Module 3: Embedded Microcontrollers – PIC18F / Others
View this question on its own page →Describe ADC and DAC interfacing with a microcontroller. Compare SPI and I2C communication.
Worked SolutionADC and DAC Interfacing with a Microcontroller
ADC interfacing
MermaidDiagramRendering diagram…- On-chip ADC (PIC18F): 10-bit, multiplexed analog pins. Steps: set pin as analog, select channel, set Vref and acquisition time, start conversion (GO/DONE), wait for completion, read ADRESH:ADRESL.
- External ADC: (e.g. MCP3208 over SPI) used when higher resolution or more channels are needed.
- Digital value: .
DAC interfacing
MermaidDiagramRendering diagram…- Parallel DAC (DAC0808) connected to a port, or serial DAC (MCP4921 on SPI, MCP4725 on I2C).
- Microcontroller writes the code; output ; an op-amp buffers it.
- Uses: waveform generation, motor speed, calibration.
SPI vs I2C
Point SPI I2C Lines 4 (MOSI, MISO, SCK, CS) 2 (SDA, SCL) Speed Faster (10 MHz or more) 100 kHz, 400 kHz, 3.4 MHz Addressing Chip select per slave 7-bit address in protocol Duplex Full duplex Half duplex Devices Few (more CS lines) Many on one bus Complexity Simple hardware Protocol overhead, ACK Use ADC, SD card, display EEPROM, RTC, sensors Exam tip
Explain the ADC steps on PIC18F and finish with the SPI vs I2C table.