KEMBAR78
Past Paper 2020 | PDF | Computer Architecture | Computer Science
0% found this document useful (0 votes)
19 views4 pages

Past Paper 2020

Uploaded by

mb7527865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Past Paper 2020

Uploaded by

mb7527865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Question #1: (5 marks, CLO1)

Problem:
Using PORT F pins for output with base address 0x4002 5000 and an offset for the DATA register
as 0x030. The PORT F DATA register is provided with the value 0xFF, and the previous value of
the DATA register is zero. Determine the value stored in the GPIO PORTF DATA register and
identify the glowing LED.

Solution:

1. Base Address of the GPIO Port F DATA Register:


0x4002 5030 = Base Address + Offset
2. Register Value Update:
o Writing 0xFF to the DATA register sets all pins in PORT F to HIGH (1).
o This implies all connected LEDs (if active low) will glow.
3. Output:
o The value stored in the PORTF DATA register will be 0xFF.
o If LEDs are connected to pins PF0 to PF7, all LEDs will glow.

Question #2: (5 marks, CLO2)

Problem:
Write the configuration function to initialize the SysTick timer for periodic ticks every 0.1 ms
when the system clock is running. Assume addresses of the registers are already provided.

Solution:
Here is the pseudocode for the SysTick timer initialization:

c
Copy code
void SysTick_Init(void) {
SysTick->CTRL = 0; // Disable SysTick during setup
SysTick->LOAD = (SystemClock / 10000) - 1; // Load value for 0.1 ms
interval
SysTick->VAL = 0; // Clear current value register
SysTick->CTRL = 0x07; // Enable SysTick with interrupt and
system clock
}

 SystemClock is the frequency of the system clock (e.g., 16 MHz).


 LOAD value = SystemClock × DesiredTime - 1.

Question #3: (5 marks, CLO1)


Problem:
Design an up-counter for overflow at 1 ms for a 16 MHz clock. Calculate the initial load value
for the counter.

Solution:

1. Timer Calculation:
Timer Period = Load Value+1Clock Frequency\frac{\text{Load Value} + 1}{\text{Clock
Frequency}}Clock FrequencyLoad Value+1
For T=1msT = 1 f=16MHz:

1×10−3=Load Value+1/16×10^6

Load Value=(16×10^3−1)=15999

2. Output:
Initial Load Value = 15999.

Question #4: (10 marks, CLO3)

Problem:
Write C code to initialize GPIO PB0 interrupt to measure the pulse duration of a signal. Also
write a handler to determine the duration.

Solution:

1. Initialization Code:

c
Copy code
void GPIO_Init(void) {
SYSCTL->RCGCGPIO |= (1 << 1); // Enable clock for Port B
GPIOB->DIR &= ~(1 << 0); // Set PB0 as input
GPIOB->IS &= ~(1 << 0); // Edge-sensitive interrupt
GPIOB->IBE &= ~(1 << 0); // Single edge interrupt
GPIOB->IEV |= (1 << 0); // Rising edge interrupt
GPIOB->ICR |= (1 << 0); // Clear interrupt flag
GPIOB->IM |= (1 << 0); // Enable interrupt
NVIC_EnableIRQ(GPIOB_IRQn); // Enable interrupt in NVIC
}

2. Interrupt Handler:

c
Copy code
volatile uint32_t startTime = 0, endTime = 0, pulseDuration = 0;
void GPIOPortB_Handler(void) {
if (GPIOB->MIS & (1 << 0)) { // Check if PB0 caused interrupt
if (startTime == 0) { // Rising edge detected
startTime = SysTick->VAL;
} else {
endTime = SysTick->VAL; // Falling edge detected
pulseDuration = startTime - endTime;
startTime = 0; // Reset for next pulse
}
GPIOB->ICR |= (1 << 0); // Clear interrupt flag
}
}

Question #5: (5 marks, CLO2)

Problem:
Configure UART for 8-bit data, 2 stop bits, even parity, high-speed mode with a baud rate of
115200.

Solution:

c
Copy code
void UART_Init(void) {
SYSCTL->RCGCUART |= (1 << 0); // Enable clock for UART0
SYSCTL->RCGCGPIO |= (1 << 0); // Enable clock for Port A
UART0->CTL &= ~(1 << 0); // Disable UART0 during setup
UART0->IBRD = 8; // Integer part of baud rate
UART0->FBRD = 44; // Fractional part of baud rate
UART0->LCRH = (3 << 5) | (1 << 3); // 8-bit, 2 stop bits, even parity
UART0->CC = 0; // Use system clock
UART0->CTL |= (1 << 0) | (1 << 8) | (1 << 9); // Enable UART, TX, RX
GPIOA->AFSEL |= (1 << 1) | (1 << 0); // Enable alternate functions
GPIOA->PCTL = (1 << 0) | (1 << 4); // Configure PA0, PA1 for UART
GPIOA->DEN |= (1 << 1) | (1 << 0); // Enable digital on PA0, PA1
}

Question #6: (10 marks, CLO3)

Problem:
Configure ADC for temperature sensor attached to PE4 (AIN9) for sampling at 125 ksps in
software trigger mode.

Solution:

c
Copy code
void ADC_Init(void) {
SYSCTL->RCGCADC |= (1 << 0); // Enable clock for ADC0
SYSCTL->RCGCGPIO |= (1 << 4); // Enable clock for Port E
GPIOE->AFSEL |= (1 << 4); // Enable alternate function for PE4
GPIOE->DEN &= ~(1 << 4); // Disable digital on PE4
GPIOE->AMSEL |= (1 << 4); // Enable analog function on PE4

ADC0->ACTSS &= ~(1 << 3); // Disable SS3 during setup


ADC0->EMUX = (0 << 12); // Software trigger conversion
ADC0->SSMUX3 = 9; // Set channel AIN9 (PE4)
ADC0->SSCTL3 = 0x6; // Enable interrupt and end of
sequence
ADC0->ACTSS |= (1 << 3); // Enable SS3
}

uint16_t ADC_Read(void) {
ADC0->PSSI |= (1 << 3); // Start SS3
while ((ADC0->RIS & (1 << 3)) == 0); // Wait for conversion
uint16_t result = ADC0->SSFIFO3 & 0xFFF; // Read 12-bit result
ADC0->ISC = (1 << 3); // Clear interrupt flag
return result;
}

Let me know if you'd like further clarifications!

You might also like