+ All Categories
Home > Documents > EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. ·...

EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. ·...

Date post: 24-Sep-2020
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
18
Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____Key_______________________________ unique name: _______________ Sign the honor code: I have neither given nor received aid on this exam nor observed anyone else doing so. Nor did I discuss this exam with anyone after it was given to the rest of the class. ___________________________________ NOTES: 1. Closed book/notes. 2. Calculators are allowed, but no PDAs, Portables, Cell phones, etc. Nothing capable of wireless communication! 3. Don’t spend too much time on any one problem. If you get stuck, move on!!! 4. You have about 120 minutes for the exam. 5. Be sure to show work and explain what you’ve done when asked to do so. Getting partial credit without showing work will be rare.
Transcript
Page 1: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 1 of 18

EECS 373 Midterm 2 Key Fall 2018

Name: _____Key_______________________________ unique name: _______________

Sign the honor code:

I have neither given nor received aid on this exam nor observed anyone else doing so. Nor did I

discuss this exam with anyone after it was given to the rest of the class.

___________________________________

NOTES: 1. Closed book/notes.

2. Calculators are allowed, but no PDAs, Portables, Cell phones, etc. Nothing capable of

wireless communication!

3. Don’t spend too much time on any one problem. If you get stuck, move on!!!

4. You have about 120 minutes for the exam.

5. Be sure to show work and explain what you’ve done when asked to do so.

Getting partial credit without showing work will be rare.

Page 2: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 2 of 18

1. Multiple choice/fill-in-the-blank. Pick the best answer.

[12 points, 2 each]

a. In Verilog an always@* block is generally used to create combinational logic /

glitch-free logic / sequential logic / a flip-flop.

b. You know a given DAC is monotonic. Which of the following can you then be certain of?

the output voltage may go down when the digital input increases.

the INL of the converter must be less than 1 LSB.

the DNL of the converter must be less than 1 LSB.

the output voltage will go down or stay the same when the digital input

decreases.

none of the above.

c. A significant difference between standard UART and I2C transactions is that:

I2C allows for full duplex while UART does not.

UART has a shared clock wire while I2C does not.

I2C requires addresses while UART does not.

UART generally requires a pullup resistor while I2C generally does not.

d. A significant difference between standard UART and SPI is that:

the UART protocol is a standardized and well documented while the SPI protocol is

not.

UART has a shared clock wire while SPI does not.

SPI requires addresses while UART does not.

UART generally requires a pullup resistor while I2C generally does not.

e. It is useful to have a “reference” register on a timer because:

it allows us to generate interrupts when an event occurs

it allows us to generate an interrupt when a certain value is reached

it can provide a more precise time of an event than reading the timer in software

it provides a way to count the number of events which have occurred in a given

amount of time.

f. When must data be stable for a correct I²C bus transaction?

when the clock is low

when the clock is in a high-impedance state

when the clock transitions high to low

when the clock is high

Either of these are acceptable. The

transitions one is better…

Page 3: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 3 of 18

2. Short answer. Each question must be answered in 15 words or less. [10 points, 2 points each]

a. Why do we use virtual timers? Because we don’t have enough physicals ones. (Other reasonable answers: Because we can accept the response time latency; because it frees up hardware timers, etc.)

b. What is the main reason to prefer to use an R/2R ladder DAC rather than a flash DAC? Needs less devices. (Other reasonable answers: smaller. We’ll also take: Because we want analog current, not voltage).

c. What is the main reason to prefer to use a flash DAC rather than an R/2R ladder DAC? More accurate.

d. If we say that we allow preemption, what does that mean in the context of interrupts? One interrupt can interrupt another one, i.e. nested interrupts.

e. In the context of a complier, what does a linker do? Links together separately compiled object files (and libraries).

Page 4: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 4 of 18

3. Consider the following C function.

int whatfun(int a, float *b, int *c)

{

int x;

x=bob(*b, c);

if(x>0)

return(x+a+*c);

return(9);

}

Rewrite the above code in Thumb2 assembly for our SmartFusion while following the ABI. You are to assume the “bob()” function is ABI-compliant and has a prototype of int bob(float, int*). [11 points]

whatfun: push{r4,r5,pc}

mov r4, r0 // back up a

mov r5, r2 // back up c

ldr r0, [r1] // *b in the first argument slot

mov r1, r2 // c into the second argument slot.

bl bob

cmpi r0, #0

ble nine

add r0, r4 // r0=x+a

ldr r1, [r5] // r1=c*

add r0, r1 // r0=x+a+*c

b done

nine: movi r0, #9

done: pop{r4,r5,lr}

Page 5: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 5 of 18

4. Consider the following circuit. [6 points]

a) Assuming Vref is 4.0V, and there is an INL of ±1/4 LSB, what range of input voltages might cause a value of 1002 to come out of the encoder? Show your work. [3] LSB is 1/2V. So Ideal range is 2V to 2.5V. INL is ±1/8 V. So 100 might get generated by values between 1.875V to 2.625V. (Another way to read the question is that it is asking what values may, but may not, generate a 1002. That would be 1.875V to 2.125V and 2.375V-2.625V as the values in between those two numbers *will* generate a 1002.

b) Given the same assumptions as above, what range of input values are certain to cause a value of 1002 to come out of the encoder? Show your work. [3] 2.125V to 2.375V as described above.

Page 6: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 6 of 18

5. Consider the following circuit:

Assuming there is no error beyond quantization error, indicate what the value of Vout would be given

each of the following values of Vin. Vref is 4V. [6 points, 2 points each]

a) Vin=2.2 Volts _____2V________

b) Vin=3.3 Volts ____3V________

c) Vin=1.1 Volts ____1V_________

Page 7: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 7 of 18

6. Timers [7 points] You are given a device which contains an 8-bit timer. That timer consists of three 8-bit registers: a count register (CNT) which holds the count value of the timer, a reference register (REF), and a control register (CTL). It also contains a single output “EQ” that goes high when the counter is enabled and CNT==REF. The CTL register consists of the following fields (0 is the most significant bit):

EN (bit 0): Must be set to 1 for the timer to be enabled.

RST (bit 1): If this bit is set to 1, CNT will reset to 0 every time the count value reaches the reference value. Otherwise, the timer will continue to increment when the reference value is reached.

DIV (bit 2): Setting this bit to 1 divides the system clock by 16 to produce the input clock frequency. If DIV = 0, then the input clock frequency equals the system clock frequency.

PRE (bits 3-7, 3 is MSB): A 5-bit prescaler which divides the clock by PRE+1. This division is in addition to the divide by 16 provided by the DIV bit.

The system clock runs at 1 MHz.

a) What is the maximum range of this timer (how long until it overflows)? What is the

resolution (gap between numbers) in that case? [3]

Max range: _.131072s______________ Resolution: _______.512ms_______

b) Say you want EQ to go high every 64ms. Find values of the CTL register and the REF register that will cause that to happen. [4]

CTL register (in binary): ____11111111 or 11101111 or 11111000____________

REF register (in decimal): ___125 or 250 or 160 (needs to pair with above CTL__

This is a bit tricky and is almost a 203 question. We want to count to 64,000 and only have 8 bits in

the REF register. 64,000 is 2^9*5^3. We can get the 9 twos with the divide by 16 (4 twos) and the

prescalar (32, which has 5 twos). That means the reference would be 125 (3 fives). Could also do it

with a prescalar of 16 and a reference value of 250. Or with a prescalar of 25 and a REF of 160. I

think that’s all of them.

7. What is the purpose of the LSB of the PC on the processor we use in lab? Be specific. [3 points]

It is used to select between the ARM and Thumb2 ISAs.

Page 8: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 8 of 18

Design Problem: Light Follower Your task is to design a simple light follower using the SmartFusion kit. Two light sensors are mounted on the tips of a T shaft connected to a motor. The device follows a light source by keeping the light reading from the two sensors approximately the same. The system will also keep track of the motors’ angular position.

Figure 1: Two sensors on a T-shaft connected to a motor

Read the entire problem before beginning!

Motor Control The motor turns at a constant speed when activated and can turn in either direction. A hardware controller is provided for you with the following control features.

CCW CW Motor Action

0 0 Stop

0 1 Clockwise

1 0 Counter Clockwise

1 1 undefined

Page 9: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 9 of 18

Reading the Light Sensors The light sensors produce a voltage proportional to the light level. The voltages will be read with the

ADC described below.

The ADC converts an analog voltage into an 8-bit unsigned integer. You can assume that its conversion

voltage range is matched to the light sensor’s output range.

Ain 0 and Ain 1: Analog input channel 0 and 1.

SEL: Logical 0 selects analog channel 0 and logical 1 selects channel 1.

Start: Start is a one clock cycle pulse that starts the conversion.

CLK: The ADC clock input.

EOC: A one clock cycle pulse that indicates end of conversion.

DATA[7:0]: Data is available on this port after the conversion.

A conversion is started by issuing a 1 clock cycle pulse to the Start pin. After

the converter finishes, a one clock cycle pulse occurs on the EOC pin. Data is

then present on the data port and stable until the next start is issued. Light

sensor 1 has been connected to Ain 0 and Light sensor 2 has been connected to Ain 1.

Rotational Sensor A rotational sensor provides a pulse every 10 degrees the motor

is rotated. We will count the pulses from a known starting

position to determine the relative position for motor. The pulses

can vary in width depending on the speed of rotation, but will

always be greater than the system clock. We will use the pulse to

generate an interrupt to count the pulses. You may assume a

turn is in the direction the motor is currently turning and that no

turn will be registered if the motor is not turning.

Page 10: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 10 of 18

Desired Memory Map There are three devices, each with their own PSEL line:

The motor controller, located in the address range 0x40050000-0x400500FF. This is used to

control the motor. The hardware has been done for you.

The ADC/light sensor, located in the address range 0x40050100-0x400501FF. These locations

can be used to select an analog input and start a conversion among other things. When a

conversion is completed, it will assert FABINT for one clock.

The rotary sensor, located in the address range 0x40050200-0x400502FF. It will assert FABINT

for one clock when a new pulse is first detected.

Notice that the ADC and rotary sensor both use FABINT. This is handled in two ways:

The ADC will actually generate something called FABINT1 and the rotary sensor something

called FABINT2. Those two signals will be ORed together into a single FABINT signal sent to the

processor. The hardware for this (an OR gate) has been done for you.

The other problem is figuring out which device generated the interrupt. The ADC and rotary

sensor each have a memory-mapped register which will be asserted when their event occurs

and can be cleared from software.

Address Usage Register Description

0x40050000 Read/Write Bit 0 is mapped to “CW” of the motor controller. Bit 1 is mapped to “CCW” of the motor controller. All other bits are zeros when read and have no effect when written. The motor will turn in the direction specified until the next time this address is written. The hardware for this is done for you.

0x40050100 Read/Write If bit 0 was last written as a “0”, “Ain 0” will be used as the analog input. If a “1” was last written to bit 0, “Ain 1” will be used as the analog input.

0x40050104 Write only When this register is written (with any value), a new ADC conversion is started. When it finishes, FABINT will be asserted.

0x40050108 Read only The lower 8 bits of this register are to hold the results of the last ADC conversion done.

0x4005010C Read/Write This register will be set to a “1” once an analog to digital conversion has finished and will stay so until a write is done to this register (which will clear the bit).

0x40050200 Read/Write This register will be set to a “1” if the rotary sensor has the start of a pulse and will stay so until a write is done to this register (which will clear the bit).

Table 1: Memory Mapped Registers for the Three Devices

Page 11: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 11 of 18

Desired System Behavior A timer has been configured to generate an interrupt every 100ms. That interrupt will cause the ISR

Timer_IRQHandler to run. That ISR is to start a new ADC conversion of one of the light sensors.

Each time it should change which sensor is being sampled. We do not want to wait in any ISR for the

ADC to complete its conversion. We want the main program to be able to run during that conversion.

Finally, you should design the system so that the following things happen:

If sensor 1 has the higher value (is brighter), the motor should turn clockwise. If sensor 2 has

the higher value, the motor should turn counter clockwise. Otherwise it should stay still.

Every time the rotary sensor detects a pulse, a global variable named FACING should be

incremented (if we are currently turning clockwise) or decremented (if currently turning counter

clockwise). Assume the variable is a signed integer that has already been declared.

You may freely declare other global variables as needed.

Page 12: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 12 of 18

Part 1: ADC Hardware Design [17 points] Complete the hardware design implementing the ADC interface and interrupt generation for the ADC.

There is additional space on the next page for your answer.

module control(

/*** APB3 BUS INTERFACE ***/

input PCLK, // clock

input PRESERN, // system reset

input PSEL, // peripheral select

input PENABLE, // distinguishes access phase

output wire PREADY, // peripheral ready signal

output wire PSLVERR, // error signal

input PWRITE, // distinguishes read and write cycles

input [31:0] PADDR, // I/O address

input wire [31:0] PWDATA, // data from processor to I/O device (32 bits)

output reg [31:0] PRDATA, // data to processor from I/O device (32-bits)

/*** I/O PORTS DECLARATION ***/

output wire FABINT,

//ADC:

output wire ADC_SEL,

output wire ADC_CLK,

output wire ADC_Start,

input EOC,

input [7:0] ADC_Data

);

assign ADC_CLK=PCLK;

assign PREADY=1'b1;

assign PSLVERR=1'b0;

reg sel, start, int_status;

wire wr, rd;

assign wr = PSEL && PENABLE && PWRITE;

assign rd = PSEL && !PWRITE;

always@(posedge PCLK)

if(~PRESERN)

int_status <=0;

else if (EOC)

int_status <=1;

//sel read/write reg

else if(wr&&(PADDR[7:0]==8'h00))

sel<=PWDATA[0];

else if(rd&&(PADDR[7:0]==8'h00))begin

PRDATA[0] <=sel;

PRDATA[31:1] <= 0;end

/*start write reg*/

else if(wr &&(PADDR[7:0]==8'h04))

start<=PWDATA[0];

/*adc data read reg*/

else if(rd&&(PADDR[7:0]=='h08))begin

PRDATA[7:0] <= ADC_Data[7:0];

Page 13: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 13 of 18

PRDATA[31:8]<=0; end

/*interrupt status read/write reg*/

else if (wr&&( PADDR[7:0]==8'h0c))

int_status <= 0;

else if(rd&&(PADDR[7:0]==8'h0c))begin

PRDATA[0] <= int_status;

PRDATA[31:1] <= 0; end

assign FABINT1 = EOC;/*EOC is one PCLK cycle*/

assign ADC_SEL = sel;/*connect reg to wire*/

assign ADC_Start = start; /*connect reg to wire*/

endmodule

Some comments:

Don’t need to synchronize EOC as the converter is using PCLK.

Don’t want to use PENABLE on reads. Be sure you understand why.

Page 14: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 14 of 18

Part 2: Rotary Interrupt Hardware Design [8 points] Complete the hardware design below in schematic form that implements the rotary sensor. You may use:

D flip-flops with CE (clock enable) and/or reset.

Standard gates (AND, OR, XOR with any number of inputs) as well as inversion bubbles as a shorthand for NOT gates.

Tri-state buffers with multiple inputs and outputs. You may use signal labels to show signal connections rather than drawing lines. For example, you can

use the name PCLK for all the clock names instead of drawing wires. Input signals are on the left, output

signals are on the right.

Page 15: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 15 of 18

Part 3: System Control (Timer Interrupt) [7 points] Provide the code in C for the timer IRQ handler. Declare any global variables used above this function. //global declarations

int sensor1 =0;

int sensor2 =0;

_attribute_((interrupt)) void Timer_IRQHandler( void ) {

volatile int* motor = (int*)0x40050000;

volatile int* sel = (int*)0x40050100;

volatile int* start = (int*)0x40050104;

#define CW=1;

#define CCW=2;

#define STOP=0;

//switch sensor select

if (!*sel)

*sel = 1;

else

*sel = 0;

//start conversion

*start = 0;//start conversion

//turn motor toward brightest sensor

if (sensor1 > sensor2)

*motor = CW;

else if (sensor2 > sensor1)

*motor = CCW;

else

*motor =STOP;

}

Page 16: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 16 of 18

Part 4: Fabric Interrupt [13 points] Complete the design by writing the function below in C. You may declare any needed global variables that you didn’t declare in part 3 above the function.

//global declarations

//sensors declared in part3

#define CW=1;

#define CCW=2;

#define STOP=0;

_attribute_((interrupt)) void Fabric_IRQHandler( void ) {

volatile int* motor = (int*)0x40050000;

volatile int* sel = (int*)0x40050100;

volatile int* adc_int_status = (int*)0x4005010c;

volatile int* rotary_int_status = (int*)0x40050200;

/* if EOC interrupt occurs, get sensor value

if (*adc_int_status)

*adc_int_status=0; //clear interrupt

if (!*sel)

sensor1=*adcdata;

else {

sensor2=*adcdata;

}

/* if rotor interrupt occurs, increment or decrement count accordingly

if (*rotary_int_status){

*rotary_int_status = 0; //clear interrupt

if (*motor == CW)

FACING++;

else if(*motor == CCW)

FACING--;

}

Page 17: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 17 of 18

Extra Page for Part 4

Page 18: EECS 373 Midterm 2 Keyeecs.umich.edu/courses/eecs373/Exams/373EX2F18ans.pdf · 2018. 10. 30. · Page 1 of 18 EECS 373 Midterm 2 Key Fall 2018 Name: _____ Key _____ unique name: _____

Page 18 of 18

References


Recommended