Skip to main content
  1. Resources/
  2. Study Materials/
  3. Electronics & Communication Engineering/
  4. ECE Semester 5/

Embedded System & Microcontroller Application (4351102) - Summer 2024 Solution

20 mins· ·
Study-Material Solutions Embedded-System 4351102 2024 Summer
Milav Dabgar
Author
Milav Dabgar
Experienced lecturer in the electrical and electronic manufacturing industry. Skilled in Embedded Systems, Image Processing, Data Science, MATLAB, Python, STM32. Strong education professional with a Master’s degree in Communication Systems Engineering from L.D. College of Engineering - Ahmedabad.
Table of Contents

Question 1(a) [3 marks]
#

What is the definition of an embedded system? Provide an example of an embedded system.

Answer: An embedded system is a specialized computer system designed to perform specific tasks with dedicated functions. It combines hardware and software components that are integrated into a larger system.

Key Features:

  • Real-time operation: Responds to inputs within specified time limits
  • Dedicated function: Designed for specific applications
  • Resource constraints: Limited memory, power, and processing capabilities

Example: Washing machine controller that manages wash cycles, water temperature, and timing automatically.

Mnemonic: “SMART Embedded” - Specialized, Microprocessor-based, Application-specific, Real-time, Task-oriented


Question 1(b) [4 marks]
#

Define a Real-Time Operating System (RTOS) and list three characteristics of RTOS.

Answer: RTOS is an operating system designed to handle real-time applications where timing constraints are critical for system operation.

CharacteristicDescription
Deterministic ResponseGuaranteed response time for critical tasks
Priority-based SchedulingHigh-priority tasks execute before low-priority tasks
Multitasking SupportMultiple tasks can run concurrently

Additional Features:

  • Task management: Efficiently handles multiple concurrent processes
  • Interrupt handling: Quick response to external events
  • Memory management: Optimized for embedded applications

Mnemonic: “DPM RTOS” - Deterministic, Priority-based, Multitasking


Question 1(c) [7 marks]
#

a) Draw the general block diagram of Embedded System b) Explain the criteria for choosing a microcontroller for an embedded system.

Answer:

a) General Block Diagram:

graph TD
    A[Input Devices] --> B[Microcontroller/Processor]
    B --> C[Output Devices]
    B --> D[Memory System]
    D --> B
    B --> E[Communication Interface]
    F[Power Supply] --> B
    G[Clock/Timer] --> B

b) Microcontroller Selection Criteria:

CriteriaConsiderations
Processing SpeedClock frequency, instruction execution time
Memory RequirementsFlash, RAM, EEPROM capacity
I/O CapabilitiesNumber of pins, special functions
Power ConsumptionBattery life, sleep modes
CostBudget constraints, volume pricing
Development ToolsCompiler, debugger availability

Key Factors:

  • Performance requirements: Processing speed and real-time constraints
  • Interface needs: ADC, PWM, communication protocols
  • Environmental conditions: Operating temperature, humidity

Mnemonic: “PMPICD Selection” - Performance, Memory, Power, Interface, Cost, Development tools


Question 1(c) OR [7 marks]
#

Explain the pin configuration of the ATmega32.

Answer: ATmega32 is a 40-pin microcontroller with four 8-bit I/O ports and various special function pins.

Port Configuration:

PortPinsFunctions
Port APA0-PA7ADC channels, general I/O
Port BPB0-PB7SPI, PWM, external interrupts
Port CPC0-PC7TWI, general I/O
Port DPD0-PD7USART, external interrupts, PWM

Special Pins:

  • VCC/GND: Power supply pins
  • AVCC/AGND: Analog power supply for ADC
  • XTAL1/XTAL2: Crystal oscillator connections
  • RESET: Active low reset input
  • AREF: ADC reference voltage

Pin Functions:

  • Dual-purpose pins: Most pins have alternate functions
  • Input/Output capability: All port pins are bidirectional
  • Internal pull-up: Software configurable for input pins

Mnemonic: “ABCD Ports” - ADC, Bus interfaces, Communication, Data transfer


Question 2(a) [3 marks]
#

Explain the data memory architecture of ATMEGA32.

Answer: ATmega32 data memory consists of three sections organized in a unified address space.

Memory Organization:

SectionAddress RangeSizePurpose
General Registers0x00-0x1F32 bytesWorking registers R0-R31
I/O Registers0x20-0x5F64 bytesControl and status registers
Internal SRAM0x60-0x45F2048 bytesData storage and stack

Key Features:

  • Unified addressing: All memory accessible through single address space
  • Register file: R0-R31 for arithmetic and logic operations
  • Stack pointer: Points to top of stack in SRAM

Mnemonic: “GIS Memory” - General registers, IO registers, SRAM


Question 2(b) [4 marks]
#

Explain the Program Status Word.

Answer: SREG (Status Register) contains flags that reflect the result of arithmetic and logic operations.

SREG Bit Configuration:

BitFlagDescription
Bit 7IGlobal Interrupt Enable
Bit 6TBit Copy Storage
Bit 5HHalf Carry Flag
Bit 4SSign Flag
Bit 3VOverflow Flag
Bit 2NNegative Flag
Bit 1ZZero Flag
Bit 0CCarry Flag

Flag Functions:

  • Arithmetic operations: C, Z, N, V, H flags updated automatically
  • Conditional branching: Flags used for decision making
  • Interrupt control: I flag enables/disables global interrupts

Mnemonic: “I THSVNZC” - Interrupt, Transfer, Half-carry, Sign, oVerflow, Negative, Zero, Carry


Question 2(c) [7 marks]
#

Draw and explain the architecture of ATMEGA32.

Answer:

ATmega32 Architecture:

graph TD
    A[Program Memory 32KB] --> B[Instruction Decoder]
    B --> C[ALU]
    C --> D[Register File R0-R31]
    D --> E[I/O Registers]
    E --> F[Data Memory 2KB SRAM]
    G[EEPROM 1KB] --> E
    H[Timers/Counters] --> E
    I[ADC] --> E
    J[USART] --> E
    K[SPI] --> E
    L[TWI] --> E
    M[Interrupt Unit] --> B

Architecture Components:

ComponentDescription
Harvard ArchitectureSeparate program and data memory buses
RISC Core131 instructions, mostly single-cycle execution
ALU8-bit arithmetic and logic operations
Register File32 × 8-bit working registers

Memory System:

  • Program memory: 32KB Flash for storing instructions
  • Data memory: 2KB SRAM for variables and stack
  • EEPROM: 1KB non-volatile data storage

Peripheral Features:

  • Three timer/counters: 8-bit and 16-bit timers
  • 8-channel ADC: 10-bit resolution
  • Communication interfaces: USART, SPI, TWI

Mnemonic: “HRAM Micro” - Harvard architecture, RISC core, ALU, Memory system


Question 2 OR(a) [3 marks]
#

Explain Program Counter of ATMEGA32.

Answer: Program Counter (PC) is a 16-bit register that holds the address of the next instruction to be executed.

PC Characteristics:

FeatureDescription
Size16-bit (can address 64KB program memory)
Reset Value0x0000 (starts execution from beginning)
IncrementAutomatically incremented after instruction fetch
Jump/BranchModified by jump, branch, and call instructions

PC Operations:

  • Sequential execution: PC increments by 1 for most instructions
  • Branch instructions: PC loaded with target address
  • Interrupt handling: PC saved on stack, loaded with interrupt vector

Mnemonic: “SRIB PC” - Sequential, Reset, Increment, Branch


Question 2 OR(b) [4 marks]
#

Explain the role of clock and reset circuits in an AVR microcontroller.

Answer:

Clock System:

Clock SourceDescription
External CrystalHigh accuracy, 1-16 MHz typical
Internal RCBuilt-in 8 MHz oscillator
External ClockExternal clock signal input
Low-frequency Crystal32.768 kHz for RTC applications

Reset Circuit Functions:

  • Power-on Reset: Automatic reset when power is applied
  • Brown-out Reset: Reset when supply voltage drops
  • External Reset: Manual reset through RESET pin
  • Watchdog Reset: Reset from watchdog timer timeout

Key Features:

  • Clock distribution: System clock drives CPU and peripherals
  • Reset sequence: Initializes all registers to default values
  • Fuse bits: Configure clock source and reset options

Mnemonic: “CEIL Clock” - Crystal, External, Internal, Low-frequency


Question 2 OR(c) [7 marks]
#

Explain TCCRn and TIFR Timer Register

Answer:

TCCRn (Timer/Counter Control Register):

RegisterFunction
TCCR0Controls Timer0 operation mode
TCCR1A/BControls Timer1 (16-bit) operation
TCCR2Controls Timer2 operation mode

TCCR Bit Functions:

  • Clock Select (CS): Selects clock source and prescaler
  • Waveform Generation (WGM): Sets timer mode (Normal, CTC, PWM)
  • Compare Output Mode (COM): Controls output pin behavior

TIFR (Timer Interrupt Flag Register):

BitFlagDescription
TOVTimer OverflowSet when timer overflows
OCFOutput CompareSet when compare match occurs
ICFInput CaptureSet when input capture event occurs

Timer Operations:

  • Mode selection: Normal, CTC, Fast PWM, Phase Correct PWM
  • Interrupt generation: Flags trigger interrupts when enabled
  • Output generation: PWM signals for motor control, LED dimming

Mnemonic: “TCCR WGM” - Timer Control, Clock, Register, Waveform Generation Mode


Question 3(a) [3 marks]
#

Distinguish different data types for programming AVR in C.

Answer:

AVR C Data Types:

Data TypeSizeRangeUsage
char8-bit-128 to 127Characters, small integers
unsigned char8-bit0 to 255Port values, flags
int16-bit-32768 to 32767General integers
unsigned int16-bit0 to 65535Counters, addresses
long32-bit-2³¹ to 2³¹-1Large calculations
float32-bit±3.4×10³⁸Decimal calculations

Special Considerations:

  • Memory efficient: Use smallest suitable data type
  • Port operations: unsigned char for 8-bit ports
  • Timing calculations: unsigned int for timer values

Mnemonic: “CUIL Float” - Char, Unsigned, Int, Long, Float


Question 3(b) [4 marks]
#

Write a C program to toggle all the bits of Port C 200 times.

Answer:

#include <avr/io.h>
#include <util/delay.h>

int main() {
    DDRC = 0xFF;        // Set Port C as output
    unsigned int count = 0;
    
    while(count < 200) {
        PORTC = 0xFF;   // Set all bits high
        _delay_ms(100); // Delay
        PORTC = 0x00;   // Set all bits low  
        _delay_ms(100); // Delay
        count++;        // Increment counter
    }
    return 0;
}

Program Explanation:

  • DDRC = 0xFF: Configures all Port C pins as outputs
  • Toggle operation: Alternates between 0xFF and 0x00
  • Counter: Tracks number of toggle cycles
  • Delay: Provides visible timing for toggle operation

Mnemonic: “DTC Loop” - DDR setup, Toggle bits, Count iterations, Loop control


Question 3(c) [7 marks]
#

a) LED are connected to Pins of PORTB. Write an AVR programs to show the count from 0 to FFh on the LED b) Write an AVR C program to get a byte of data from Port C. If it is less than 100 send it to Port B; otherwise, send it to Port D.

Answer:

a) Binary Counter Display:

#include <avr/io.h>
#include <util/delay.h>

int main() {
    DDRB = 0xFF;           // Port B as output
    unsigned char count = 0;
    
    while(1) {
        PORTB = count;     // Display count on LEDs
        _delay_ms(500);    // Delay for visibility
        count++;           // Increment counter
        if(count > 0xFF)   // Reset after 255
            count = 0;
    }
    return 0;
}

b) Conditional Data Transfer:

#include <avr/io.h>

int main() {
    DDRC = 0x00;    // Port C as input
    DDRB = 0xFF;    // Port B as output  
    DDRD = 0xFF;    // Port D as output
    
    while(1) {
        unsigned char data = PINC;  // Read from Port C
        
        if(data < 100) {
            PORTB = data;           // Send to Port B
            PORTD = 0x00;          // Clear Port D
        } else {
            PORTD = data;           // Send to Port D
            PORTB = 0x00;          // Clear Port B
        }
    }
    return 0;
}

Key Programming Concepts:

  • Port direction: DDR registers configure input/output
  • Data reading: PIN registers read input values
  • Conditional logic: if-else statements for decision making

Mnemonic: “RCC Data” - Read input, Compare value, Conditional output


Question 3 OR(a) [3 marks]
#

Write AVR C program to send values of -3 to +3 Port B

Answer:

#include <avr/io.h>
#include <util/delay.h>

int main() {
    DDRB = 0xFF;              // Port B as output
    signed char values[] = {-3, -2, -1, 0, 1, 2, 3};
    unsigned char i = 0;
    
    while(1) {
        PORTB = values[i];    // Send value to Port B
        _delay_ms(1000);      // 1 second delay
        i++;                  // Next value
        if(i > 6) i = 0;      // Reset index
    }
    return 0;
}

Program Features:

  • Signed data: Uses signed char for negative values
  • Array storage: Values stored in array for easy access
  • Cyclic operation: Continuously cycles through all values

Mnemonic: “SAC Values” - Signed char, Array storage, Cyclic operation


Question 3 OR(b) [4 marks]
#

Write AVR C program to send hex values for ASCII characters 0,1,2,3,4,5,A,B,C and D to port B.

Answer:

#include <avr/io.h>
#include <util/delay.h>

int main() {
    DDRB = 0xFF;    // Port B as output
    
    // ASCII hex values array
    unsigned char ascii_values[] = {
        0x30,  // '0'
        0x31,  // '1' 
        0x32,  // '2'
        0x33,  // '3'
        0x34,  // '4'
        0x35,  // '5'
        0x41,  // 'A'
        0x42,  // 'B'
        0x43,  // 'C'
        0x44   // 'D'
    };
    
    unsigned char i = 0;
    
    while(1) {
        PORTB = ascii_values[i];  // Send ASCII value
        _delay_ms(500);           // Delay
        i++;                      // Next character
        if(i > 9) i = 0;          // Reset index
    }
    return 0;
}

ASCII Values Table:

CharacterHex ValueBinary
‘0’0x3000110000
‘1’0x3100110001
‘A’0x4101000001
‘B’0x4201000010

Mnemonic: “HAC ASCII” - Hex values, Array storage, Cyclic transmission


Question 3 OR(c) [7 marks]
#

A door sensor is connected to bit 1 of Port B, and an LED is connected to bit 7 of Port C. Write an AVR C program to monitor the door sensor and, when it opens (PIN is HIGH), turn on the LED. Also draw Flow chart.

Answer:

C Program:

#include <avr/io.h>

int main() {
    DDRB = 0xFD;    // Port B bit 1 as input (0), others output (1)
    DDRC = 0xFF;    // Port C as output
    PORTB = 0x02;   // Enable pull-up for bit 1
    
    while(1) {
        if(PINB & 0x02) {      // Check if door sensor is HIGH
            PORTC |= 0x80;     // Turn ON LED (bit 7)
        } else {
            PORTC &= 0x7F;     // Turn OFF LED (bit 7)
        }
    }
    return 0;
}

Flow Chart:

flowchart TD
    A[Start] --> B[Initialize Ports]
    B --> C[Configure Port B bit 1 as input]
    C --> D[Configure Port C bit 7 as output]
    D --> E{Read Door Sensor}
    E -->|HIGH| F[Turn ON LED]
    E -->|LOW| G[Turn OFF LED]
    F --> H[Continue Monitoring]
    G --> H
    H --> E

Bit Operations:

  • Input reading: PINB & 0x02 checks bit 1
  • LED control: PORTC |= 0x80 sets bit 7
  • LED off: PORTC &= 0x7F clears bit 7

Mnemonic: “BIC Door” - Bit manipulation, Input monitoring, Conditional LED control


Question 4(a) [3 marks]
#

Explain ADMUX ADC Register

Answer:

ADMUX (ADC Multiplexer Selection Register):

BitNameDescription
Bit 7-6REFS1:0Reference Selection
Bit 5ADLARADC Left Adjust Result
Bit 4-0MUX4:0Analog Channel Selection

Reference Selection (REFS1:0):

  • 00: AREF, Internal Vref turned off
  • 01: AVCC with external capacitor at AREF pin
  • 10: Reserved
  • 11: Internal 2.56V reference

Channel Selection (MUX4:0):

  • 00000-00111: ADC0-ADC7 (single-ended inputs)
  • Other combinations: Differential inputs with gain

Key Functions:

  • Voltage reference: Determines ADC measurement range
  • Channel multiplexing: Selects which analog input to convert
  • Result alignment: Left or right justified ADC result

Mnemonic: “RAM ADMUX” - Reference, Alignment, Multiplexer


Question 4(b) [4 marks]
#

Explain Different LCD Pins.

Answer:

16x2 LCD Pin Configuration:

PinSymbolFunction
1VSSGround (0V)
2VDDPower supply (+5V)
3V0Contrast adjustment
4RSRegister Select (Data/Command)
5R/WRead/Write select
6EEnable signal
7-14D0-D7Data bus (8-bit)
15ABacklight anode (+)
16KBacklight cathode (-)

Control Pin Functions:

  • RS = 0: Command register selected
  • RS = 1: Data register selected
  • R/W = 0: Write operation
  • R/W = 1: Read operation
  • E: Enable pulse triggers operation

Connection Modes:

  • 8-bit mode: All data pins D0-D7 connected
  • 4-bit mode: Only D4-D7 used (saves microcontroller pins)

Mnemonic: “VCR EDB LCD” - Vpower, Contrast, Register select, Enable, Data Bus


Question 4(c) [7 marks]
#

Write a Program to toggle all the bits of PORTB continually with 20µs delay. Use Timer0, normal mode and no Prescaler to generate delay

Answer:

#include <avr/io.h>

void delay_20us() {
    TCNT0 = 0;          // Clear timer counter
    TCCR0 = 0x01;       // No prescaler, normal mode
    while(TCNT0 < 160); // Wait for 20µs (8MHz/1 * 20µs = 160)
    TCCR0 = 0;          // Stop timer
}

int main() {
    DDRB = 0xFF;        // Port B as output
    
    while(1) {
        PORTB = 0xFF;   // Set all bits high
        delay_20us();   // 20µs delay
        PORTB = 0x00;   // Set all bits low
        delay_20us();   // 20µs delay
    }
    return 0;
}

Timer Calculation:

  • Clock frequency: 8 MHz (assumption)
  • Timer resolution: 1/8MHz = 0.125µs per count
  • Required counts: 20µs / 0.125µs = 160 counts

Timer0 Configuration:

SettingValueDescription
ModeNormalCounts from 0 to 255
Prescaler1No prescaling
Clock sourceSystem clock8 MHz

Program Flow:

  • Initialize: Set Port B as output
  • Toggle high: PORTB = 0xFF, wait 20µs
  • Toggle low: PORTB = 0x00, wait 20µs
  • Repeat: Continuous operation

Mnemonic: “TNP Timer” - Timer0, Normal mode, Prescaler none


Question 4 OR(a) [3 marks]
#

Short note Two wire Interface (TWI)

Answer:

TWI (Two Wire Interface) - I2C Protocol:

Key Features:

FeatureDescription
Two wiresSDA (data) and SCL (clock)
Multi-masterMultiple masters can control bus
Multi-slaveUp to 127 slave devices
Address-based7-bit or 10-bit device addressing
BidirectionalData flows in both directions

Bus Characteristics:

  • Open-drain: Requires pull-up resistors (4.7kΩ typical)
  • Synchronous: Clock provided by master
  • Start/Stop conditions: Special sequences for communication

Common Applications:

  • EEPROMs: Non-volatile memory storage
  • RTC modules: Real-time clock devices
  • Sensors: Temperature, pressure, accelerometer
  • Display controllers: OLED, LCD controllers

Mnemonic: “SDA SCL TWI” - Serial Data, Serial CLock, Two Wire Interface


Question 4 OR(b) [4 marks]
#

Explain ADCSRA ADC Register

Answer:

ADCSRA (ADC Control and Status Register A):

BitNameFunction
Bit 7ADENADC Enable
Bit 6ADSCADC Start Conversion
Bit 5ADATEADC Auto Trigger Enable
Bit 4ADIFADC Interrupt Flag
Bit 3ADIEADC Interrupt Enable
Bit 2-0ADPS2:0ADC Prescaler Select

Prescaler Settings (ADPS2:0):

BinaryDivision FactorADC Clock (8MHz)
00024 MHz
00124 MHz
01042 MHz
01181 MHz
10016500 kHz
10132250 kHz
11064125 kHz
11112862.5 kHz

Control Functions:

  • ADEN: Must be set to enable ADC operation
  • ADSC: Set to start conversion, cleared when complete
  • ADIF: Set when conversion completes
  • Prescaler: ADC clock should be 50-200 kHz for optimal accuracy

Mnemonic: “EASCID ADC” - Enable, Auto-trigger, Start, Conversion, Interrupt, Divider


Question 4 OR(c) [7 marks]
#

Write a Program to generate a square wave of 16 Khz frequency on pin PORTC.3. Assume Crystal Frequency 8 Mhz

Answer:

#include <avr/io.h>
#include <avr/interrupt.h>

int main() {
    // Configure PC3 as output
    DDRC |= (1 << PC3);
    
    // Timer1 CTC mode configuration
    TCCR1A = 0x00;                    // Normal port operation
    TCCR1B = (1 << WGM12) | (1 << CS10); // CTC mode, no prescaler
    
    // Calculate OCR1A value for 16 kHz
    // Period = 1/16000 = 62.5µs
    // Half period = 31.25µs  
    // OCR1A = (8MHz * 31.25µs) - 1 = 249
    OCR1A = 249;
    
    // Enable Timer1 Compare A interrupt
    TIMSK |= (1 << OCIE1A);
    
    // Enable global interrupts
    sei();
    
    while(1) {
        // Main loop - square wave generated by interrupt
    }
    return 0;
}

// Timer1 Compare A interrupt service routine
ISR(TIMER1_COMPA_vect) {
    PORTC ^= (1 << PC3);    // Toggle PC3
}

Frequency Calculation:

ParameterValueFormula
Target frequency16 kHzGiven
Period62.5 µs1/16000
Half period31.25 µsPeriod/2
Timer counts2508MHz × 31.25µs
OCR1A value249Counts - 1

Timer Configuration:

  • Mode: CTC (Clear Timer on Compare)
  • Prescaler: 1 (no prescaling)
  • Interrupt: Compare match toggles output pin

Mnemonic: “CTC Square” - CTC mode, Timer interrupt, Compare match


Question 5(a) [3 marks]
#

Difference between Polling and Interrupt

Answer:

Polling vs Interrupt Comparison:

AspectPollingInterrupt
CPU UsageContinuously checks statusCPU free until event occurs
Response TimeVariable, depends on polling frequencyFast, immediate response
Power ConsumptionHigher due to continuous checkingLower, CPU can sleep
ProgrammingSimple, sequential codeComplex, requires ISR
Real-timeNot suitable for critical timingExcellent for real-time systems

Key Differences:

  • Efficiency: Interrupts are more CPU efficient
  • Timing: Interrupts provide deterministic response
  • Complexity: Polling is easier to implement and debug

Mnemonic: “PIE Method” - Polling inefficient, Interrupt efficient, Event-driven


Question 5(b) [4 marks]
#

Explain LM35 Interface with AVR ATmega32.

Answer:

LM35 Temperature Sensor Interface:

+5VLM35ToADCPin(PA0)

LM35 Characteristics:

ParameterValueDescription
Output10mV/°CLinear temperature coefficient
Range0°C to 100°COperating temperature range
Supply4V to 30VPower supply range
Accuracy±0.5°CTemperature accuracy

Interface Code:

#include <avr/io.h>

void ADC_init() {
    ADMUX = 0x40;   // AVCC reference, ADC0 channel
    ADCSRA = 0x87;  // Enable ADC, prescaler 128
}

unsigned int read_temperature() {
    ADCSRA |= (1 << ADSC);      // Start conversion
    while(ADCSRA & (1 << ADSC)); // Wait for completion
    
    // Convert ADC value to temperature
    // Temperature = (ADC * 5000) / (1024 * 10)
    unsigned int temp = (ADC * 5000) / 10240;
    return temp;
}

Calculation:

  • ADC Resolution: 10-bit (0-1023)
  • Reference Voltage: 5V
  • LM35 Scale: 10mV/°C
  • Formula: Temperature = (ADC_Value × 5000mV) / (1024 × 10mV/°C)

Mnemonic: “LAC Temperature” - LM35 sensor, ADC conversion, Calculation formula


Question 5(c) [7 marks]
#

Write a program to interface DC Motor with AVR ATmega32.

Answer:

DC Motor Interface Circuit:

ATmePPPgDDDa56432+5VLIIE2NNN91213DMotorDOOr12iGvNeDrDCMotor

Motor Control Program:

#include <avr/io.h>
#include <util/delay.h>

void motor_init() {
    DDRD |= (1 << PD4) | (1 << PD5) | (1 << PD6); // Set as output
}

void motor_forward() {
    PORTD |= (1 << PD4);   // Enable motor
    PORTD |= (1 << PD5);   // IN1 = 1
    PORTD &= ~(1 << PD6);  // IN2 = 0
}

void motor_reverse() {
    PORTD |= (1 << PD4);   // Enable motor
    PORTD &= ~(1 << PD5);  // IN1 = 0
    PORTD |= (1 << PD6);   // IN2 = 1
}

void motor_stop() {
    PORTD &= ~(1 << PD4);  // Disable motor
}

int main() {
    motor_init();
    
    while(1) {
        motor_forward();    // Forward for 2 seconds
        _delay_ms(2000);
        
        motor_stop();       // Stop for 1 second
        _delay_ms(1000);
        
        motor_reverse();    // Reverse for 2 seconds
        _delay_ms(2000);
        
        motor_stop();       // Stop for 1 second
        _delay_ms(1000);
    }
    return 0;
}

L293D Truth Table:

ENIN1IN2Motor Action
0XXStop
100Stop
101Reverse
110Forward
111Stop

Key Components:

  • L293D: Dual H-bridge motor driver IC
  • Enable pin: Controls motor power
  • Direction pins: IN1, IN2 control rotation direction
  • Protection: Built-in diodes for back EMF protection

Mnemonic: “LED Motor” - L293D driver, Enable control, Direction pins


Question 5 OR(a) [3 marks]
#

Explain basic block diagram of GSM based security system.

Answer:

GSM Security System Block Diagram:

graph TD
    A[Sensors] --> B[ATmega32 Microcontroller]
    B --> C[GSM Module]
    C --> D[Mobile Network]
    D --> E[User Mobile Phone]
    B --> F[Alarm/Buzzer]
    B --> G[LCD Display]
    H[Power Supply] --> B
    H --> C

System Components:

ComponentFunction
SensorsPIR, door/window sensors, smoke detector
MicrocontrollerProcess sensor data, control system
GSM ModuleSend SMS alerts, make calls
DisplayShow system status
AlarmLocal audio/visual alert

Working Principle:

  • Sensor monitoring: Continuous surveillance of security zones
  • Event detection: Triggered when unauthorized access detected
  • Alert generation: SMS sent to predefined numbers
  • Local alarm: Immediate audio/visual warning

Key Features:

  • Remote monitoring: Real-time alerts via SMS
  • Multiple sensors: Various intrusion detection methods
  • Backup power: Battery backup for power failures

Mnemonic: “SGMA Security” - Sensors, GSM module, Microcontroller, Alerts


Question 5 OR(b) [4 marks]
#

Explain Relay Interface with AVR ATmega32.

Answer:

Relay Interface Circuit:

ATmegPPaBB3012GNUDLIINNN21280OO312+12VReCNlOOaMyLALoCoaadd

Relay Interface Code:

#include <avr/io.h>
#include <util/delay.h>

void relay_init() {
    DDRB |= (1 << PB0) | (1 << PB1); // Set as output pins
}

void relay1_on() {
    PORTB |= (1 << PB0);  // Activate relay 1
}

void relay1_off() {
    PORTB &= ~(1 << PB0); // Deactivate relay 1
}

void relay2_on() {
    PORTB |= (1 << PB1);  // Activate relay 2
}

void relay2_off() {
    PORTB &= ~(1 << PB1); // Deactivate relay 2
}

int main() {
    relay_init();
    
    while(1) {
        relay1_on();        // Turn on relay 1
        _delay_ms(2000);
        relay1_off();       // Turn off relay 1
        
        relay2_on();        // Turn on relay 2
        _delay_ms(2000);
        relay2_off();       // Turn off relay 2
        
        _delay_ms(1000);
    }
    return 0;
}

ULN2803 Features:

FeatureDescription
8 ChannelsEight Darlington pair drivers
High CurrentUp to 500mA per channel
ProtectionBuilt-in flyback diodes
Input Voltage5V TTL compatible
Output VoltageUp to 50V

Applications:

  • Home automation: Light, fan control
  • Industrial control: Motor, valve operation
  • Security systems: Door locks, alarms

Mnemonic: “ULN Relay” - ULN2803 driver, Load control, Non-contact switching


Question 5 OR(c) [7 marks]
#

Draw and Explain Automatic Juice vending machine

Answer:

Automatic Juice Vending Machine Block Diagram:

graph TD
    A[Coin Sensor] --> B[ATmega32 Controller]
    C[Keypad] --> B
    D[LCD Display] --> B
    B --> E[Pump Motors]
    B --> F[Solenoid Valves]
    B --> G[Coin Return Mechanism]
    H[Level Sensors] --> B
    I[Power Supply] --> B
    J[Juice Containers] --> E
    E --> K[Dispensing Unit]

System Components:

ComponentFunction
Coin SensorDetects and validates inserted coins
KeypadUser selection interface (4x4 matrix)
LCD DisplayShows menu, price, status messages
Pump MotorsDispense selected juice
Solenoid ValvesControl juice flow
Level SensorsMonitor juice container levels
Coin ReturnReturns excess money

System Operation:

  1. Initialization: Display welcome message and juice menu
  2. Coin Input: User inserts coins, system validates amount
  3. Selection: User presses keypad to select juice type
  4. Validation: Check if enough money and juice available
  5. Dispensing: Activate pump and valve for selected juice
  6. Completion: Return change if any, display thank you message

Control Logic:

// Pseudo code for vending machine operation
void vending_machine() {
    display_menu();
    
    while(1) {
        if(coin_inserted()) {
            total_amount += validate_coin();
            update_display();
        }
        
        if(selection_made()) {
            juice_type = get_selection();
            if(total_amount >= juice_price[juice_type]) {
                if(juice_available[juice_type]) {
                    dispense_juice(juice_type);
                    return_change();
                    reset_system();
                } else {
                    display_error("Out of Stock");
                }
            } else {
                display_error("Insufficient Amount");
            }
        }
    }
}

Key Features:

  • Multiple juice types: 4-6 different flavors
  • Automatic dispensing: Precise volume control
  • Change return: Calculates and returns exact change
  • Inventory tracking: Monitors juice levels
  • Error handling: Handles various fault conditions

Safety Features:

  • Over-dispensing protection: Timer-based pump control
  • Coin validation: Prevents fake coin acceptance
  • Level monitoring: Prevents dry running of pumps
  • Emergency stop: Manual override capability

Mnemonic: “CLPDV Juice” - Coin sensor, LCD display, Pump motors, Dispensing unit, Valve control


End of Paper Solution
#

Total Questions Covered: 5 main questions with all OR alternatives Total Marks: 70 marks Format: Complete solutions with diagrams, tables, code examples, and mnemonics Special Features:

  • Detailed explanations for weak students
  • Memory aids (mnemonics) for each topic
  • Practical code examples
  • Circuit diagrams using appropriate formats
  • Structured tables for easy understanding

Related

Embedded System & Microcontroller Application (4351102) - Winter 2023 Solution
14 mins
Study-Material Solutions Embedded-System 4351102 2023 Winter
Linear Integrated Circuit (4341105) - Winter 2024 Solution
28 mins
Study-Material Solutions Linear-Integrated-Circuit 4341105 2024 Winter
Consumer Electronics & Maintenance (4341107) - Winter 2024 Solution
21 mins
Study-Material Solutions Consumer-Electronics 4341107 2024 Winter
Antenna & Wave Propagation (4341106) - Winter 2024 Solution
21 mins
Study-Material Solutions Antenna Wave-Propagation 4341106 2024 Winter
Electronics Devices & Circuits (1323202) - Winter 2024 Solution
14 mins
Study-Material Solutions Electronics 1323202 2024 Winter
Elements of Electrical & Electronics Engineering (1313202) - Winter 2024 Solution
13 mins
Study-Material Solutions Electrical-Electronics 1313202 2024 Winter