Docsity

6 Solved Problems on the Standard Programming - Midterm Exam | ECGR 4101, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECGR 4101/5101 - Midterm Exam Page 1 of 3
Batteries
To LED
UNC Charlotte–ECGR4101/5101-Midterm Exam –10/10/07
Name: ___SOLUTION_______ Mosaic User ID _________SOLUTION_______
1. According the ECGR4101 programming standards, which of the following should be included in the header of a
subroutine? (5 points – all or nothing)
a. Subroutine name d. Interfaces
b. Assumptions e. All of the above
c. Inputs/Outputs
2. You have several 400mAh 1.5V batteries and a LED that has an
average drain of 3.5mA at 4.5V. If you had the following battery
configuration how long would the LED stay lit? (5 points)
a. 557.1 hours
b. 228.6 hours (5 points – all or nothing)
c. 371.4 hours
d. 209.3 hours
e. None of the above Batteries = 4.5v, 800mAhr/3.5 mA = 228.6 hr
3. Vref+ = 3V, vref- = 0V, step size = 3v/1024 = 2.93mV = 4 points, all or nothing
1100110010 = 0x332 = 818, 818 * 2.93mV = 2.40V = 3pts formula, 3 points correct answer (note: the
formula from the notes in class is also valid)
4. Algorithm Solution:
// Name: James Conrad – 10/10/07
// Function: when sw1 is pressed, turn the green LEDs on
// If the thermister value is above 511 light the yellow LED
// If the light sensor value is above 511 light the red LED
// Inputs: sw1, 2 ADC; Outputs: LEDs
Setup a switch (input)
Setup LEDs (output, turn off)
Setup thermister and light sensor ADC (sweep)
Start continually reading thermister, light sensor
While (1) {
If (sw1 pressed) Turn on the green LED
Else turn off green LED;
If (thermister>511) Turn on the yellow LED;
Else turn off yellow LED;
If (light sensor>511) Turn on the red LED
Else turn off red LED;
}
Points:
5 points: header comments
5 points: set up switch and LEDs
5 points: set up ADCs
5 points: While loop with testing values inside (continuously)
5 points: Handle green LED on
5 points: Handle green LED off
5 points: Handle yellow LED on with condition
5 points: Handle yellow LED off with condition
5 points: Handle red LED on with condition
5 points: Handle red LED of with condition
No extra points for writing the entire code package. I only asked for the algorithm.
pf3

Partial preview of the text

Download 6 Solved Problems on the Standard Programming - Midterm Exam | ECGR 4101 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

Batteries

To LED

UNC Charlotte–ECGR4101/5101-Midterm Exam –10/10/

Name: ___ SOLUTION _______ Mosaic User ID _________ SOLUTION _______

1. According the ECGR4101 programming standards, which of the following should be included in the header of a

subroutine? (5 points – all or nothing)

a. Subroutine name d. Interfaces

b. Assumptions e. All of the above

c. Inputs/Outputs

2. You have several 400mAh 1.5V batteries and a LED that has an

average drain of 3.5mA at 4.5V. If you had the following battery

configuration how long would the LED stay lit? (5 points)

a. 557.1 hours

b. 228.6 hours (5 points – all or nothing)

c. 371.4 hours

d. 209.3 hours

e. None of the above Batteries = 4.5v, 800mAhr/3.5 mA = 228.6 hr

3. Vref+ = 3V, vref- = 0V, step size = 3v/1024 = 2.93mV = 4 points, all or nothing

1100110010 = 0x332 = 818, 818 * 2.93mV = 2.40V = 3pts formula, 3 points correct answer (note: the

formula from the notes in class is also valid)

4. Algorithm Solution:

// Name: James Conrad – 10/10/ // Function: when sw1 is pressed, turn the green LEDs on // If the thermister value is above 511 light the yellow LED // If the light sensor value is above 511 light the red LED // Inputs: sw1, 2 ADC; Outputs: LEDs Setup a switch (input) Setup LEDs (output, turn off) Setup thermister and light sensor ADC (sweep) Start continually reading thermister, light sensor While (1) { If (sw1 pressed) Turn on the green LED Else turn off green LED; If (thermister>511) Turn on the yellow LED; Else turn off yellow LED; If (light sensor>511) Turn on the red LED Else turn off red LED; }

Points:

5 points: header comments

5 points: set up switch and LEDs

5 points: set up ADCs

5 points: While loop with testing values inside (continuously)

5 points: Handle green LED on

5 points: Handle green LED off

5 points: Handle yellow LED on with condition

5 points: Handle yellow LED off with condition

5 points: Handle red LED on with condition

5 points: Handle red LED of with condition

No extra points for writing the entire code package. I only asked for the algorithm.

5. Code Solution:

adcon0=0x18; // perform repeated A/D conversions - sweep adcon1=0x28; // sweep pins 0-3 (to get pins 0 and 1, but no more) adcon2=0x01; // sample and hold adst=1; // <- start measuring!

Points:

5 points: set up reg0 with correct values

5 points: set up reg1 with correct values 5 points: set up reg2 with correct values

5 points: start sampling (adst or adcon bit set)

No extra points for writing the entire code package. I only asked for a few lines.

FYI: