聯系方式

您當前位置:首頁 >> Java編程Java編程

日期:2019-11-14 11:19

CPEG 222 Fall 2019

Homework 4

This homework is to be completed individually.

Due: Nov 13th at midnight (through canvas)

Note: To receive full credit, please show your steps and put comments for your code.

1. Assume that a sensor outputs an analog signal with a range of 0V and 3.3V (i.e., reference voltage =

3.3V). A linear A/D converter then converts the analog signal into a digital signal. The transfer function

is shifted to the left ? LSB to reduce quantization error.

(a) Identify the smallest detectable change in voltage (that is, no matter what the original voltage is,

the change can always be detected) if the ADC uses (1) 5-bits of resolution; (2) 8-bits of

resolution.

(b) For an input voltage of 3.14V, identify the quantization error if the ADC uses (1) 5-bits of

resolution; (2) 8-bits of resolution.

2. An analog temperature sensor is connected to analog port AN0 of a PIC32MX370F512L

Microcontroller. The sensor provides an analog output voltage proportionally to the temperature, i.e

V0 = 10mV/o

C.

(c) Write a c code to declare pin AN0 as analog input.

(d) Write a c code to configure the ADC module and read the temperature sensor manually.

3. Assume a student configures his timer and ADC to sample at 11KHz. When a sample arrives, an

interrupt handler will be invoked to process the sample. When 1024 samples are collected, an FFT

procedure is invoked to process them and convert the signal from time domain to frequency domain.

Assume the processor takes 200 cycles to switch from a procedure to ISR and from the ISR to the

procedure. The ISR takes 500 cycles to process each sample, and FFT takes 80,000 cycles to process

1024 sample points at once. The processor speed is 80MHz and executes one instruction per cycle.

(a) How many application instructions can be executed between two consecutive interrupts?

(b) If timer interrupts are allowed to interrupt FFT, in one single FFT process, how many times will

FFT be interrupted?

4. Consider the following program that monitors two sensors. Here sensor1 and sensor2 denote the

variables storing the readouts from two sensors. The actual read is performed by the functions

readSensor1() and readSensor2(), respectively, which are called in the interrupt service routine ISR.

char flag = 0;

char* display;

short sensor1, sensor2;

void ISR() {

if (flag) {

sensor1 = readSensor1();

} else {

sensor2 = readSensor2();

}

}

int main() {

// ... set up interrupts ...

// ... enable interrupts ...

while(1) {

if (flag) {

if isFaulty2(sensor2) {

display = "Sensor2 Faulty";

}

} else {

if isFaulty1(sensor1) {

display = "Sensor1 Faulty";

}

}

flag = !flag;

}

}

Functions isFaulty1() and isFaulty2() check the sensor readings for any discrepancies, returning 1 if

there is a fault and 0 otherwise. Assume that the variable display defines what is shown on the monitor

to alert a human operator about faults. Also, you may assume that flag is modified only in the body of

main. Answer the following questions:

a) Is it possible for the ISR to update the value of sensor1 while the main function is checking whether

sensor1 is faulty? Why or why not?

b) Is it possible for the ISR to update the value of sensor2 while the main function is checking whether

sensor2 is faulty? Why or why not?

c) Suppose a spurious error occurs that causes sensor1 or sensor2 to be faulty for one measurement.

Is it possible that this code would not report “Sensor1 faulty” or “Sensor2 faulty”? Please explain

your answer.

d) Assuming the interrupt source for ISR() is timer-driven, what conditions would cause this code to

never check whether the sensors are faulty?


版權所有:編程輔導網 2018 All Rights Reserved 聯系方式:QQ:99515681 電子信箱:[email protected]
免責聲明:本站部分內容從網絡整理而來,只供參考!如有版權問題可聯系本站刪除。

黑龙江体彩22选5