Uploaded by Jeonghoon Lee

4180T1 F18Asol

advertisement
Score: _____________ Name:___________________________________________
EE 4180 Test I
Test is open book and notes. No electronic devices. Place all answers in the spaces provided.
1. (4%) SD cards have ___4___ signal & control lines, and use an _____SPI_____ bus interface.
Number(not counting pwr & gnd!)
Bus standard
2. (4%) The physics of how transistors operate makes _____PWM_____ more energy efficient than using a
D/A convertor output in most cases.
Acronym
3. (10%) Write a short C++ code segment below that would output “Hello World” followed by an ASCII
carriage return and line feed to the serial port on the right side of the mbed board at 115200 baud.
serial pc (p28,p27);
pc.baud(115200);
pc.printf(“Hello World\n\r”);
4. (4%) Why can’t you just hook up a relay coil directly to an mbed output pin to control the relay?
Needs more current that the output pin can provide. Must add a transistor driver
circuit to amplify current levels. Then the driver needs more power
5.
(4%) ____tristate____ logic outputs always have an additional output control line that forces the gate’s
output driver circuit to a high impedance state (unlike normal logic outputs that force it high or low)
6.
(4%) To interface to sensor ICs located on the same PCB, the ___I2C_______ bus uses only __2____
Bus standard
Number(not counting gnd!)
signal and control wires and each device must have a unique address.
7.
(4%) What hardware is needed to interface mbed to a real RS232 serial port?
Need an RS232 level shifter circuit to provide the positive and negative voltage levels.
8.
(8%) Write a short C++ mbed API code segment below that would output a voltage of 1.65V on pin
18.
AnalogOut myaout(p18);
Myaout = 1.65/3.3; //0.5
9. (4%) The RS232 ___CTS___ handshake (i.e., flow control) line had to be grounded on the Bluetooth
module in lab 3.
10. (4%) Why can USB devices be safely plugged in or unplugged with the power on, and what is this feature
called?
The power and ground pins are longer so they connect first and establish a common ground before
signal wires connect. This is called “hot pluggable”
Problem 11 Part 2 (30%): Complete the C++ program in the space below using the mbed APIs and
your design on the previous page to build the crane controller.
#include
#include
#include
volatile
volatile
"mbed.h"
"Servo.h"
"Motor.h"
bool alarm = false; //true when alarm tone should play
bool toggle_tone = true; //true every other interrupt
DigitalIn pb_up(p9,PullUp);
DigitalIn pb_down(p10,PullUp);
DigitalOut led(p7);
AnalogIn rotate_pot(p15);
PwmOut spkr(p21);
Motor m(p23, p6, p5); // pwm, fwd, rev
Servo servo(p22);
Ticker beeper;
void playtone(){
if (toggle_tone == false) {
if (alarm == true) {
spkr = 0.5;
led = 1;
} else {
spkr = 0.0;
led = 0;
}
} else {
spkr = 0.0;
led = 0;
}
toggle_tone = ! toggle_tone;
}
int main(){
spkr.period(1.0/1000.0);
beeper.attach(&playtone,0.5);
while(1) {
servo = rotate_pot;
if (pb_up == 0) {
alarm = true;
m.speed(0.25);
} else if (pb_down == 0) {
alarm = true;
m.speed(-0.25);
} else {
alarm = false;
m.speed(0);
}
wait(0.1);
}
}
Name:_______________________________________________________
Additional Details for Problem 11
Detach this page to work on test, but put your name on it and turn it in with your test!
Using two pushbuttons, a potentiometer, DC motor, RC servo, speaker, mbed and other parts as needed from
your kit as needed, design a controller for the model crane shown above. A 5V RC servo at the top of the
mast under the operating cabinet rotates the crane’s operating arm (jib). A geared 5V DC motor powers the
hoist winch that raises and lowers the crane’s hook by winding or unwinding the steel cable on a drum. A
speaker, spkr, inside the operator’s cabinet plays a loud warning beep tone using PWM when it is moving.
When the speaker is playing, LED1 flashes in sync with the speaker beeps
Up and down pushbuttons, pb_up and pb_down, move the crane’s hook up and down by running the DC
motor at one quarter speed (i.e. on 25% of time) in each direction when the switch contact is made (No
debouncing is required). The potentiometer, rotate_pot, moves the servo to control rotation of the crane. Use
software polling in an infinite loop to sample the switch and potentiometer ten times per second. To simplify
this problem, you can assume Up and Down are not hit at the same time, and assume the Servo.h mbed library
version will still work correctly, if a different PWM clock is used for the Speaker PWM pin.
When the crane is moving the DC hoist motor (up or down), it plays a very loud 1000 Hz. square wave
warning tone on a speaker using an energy efficient circuit. The tone plays (i.e. beeps) once per second and
is off half of the time (i.e. similar to a truck’s backup warning beeping alarm tone). The tone can start or stop
in the middle of a cycle when the crane starts/stops moving. While playing the alarm tone, it is still necessary
to keep sampling the pushbutton and pot control inputs for changes in a loop. Timers and interrupts must
be used to play the tone (i.e. no waits!).
You must use the following approach in your code solution: To play the alarm tone, start a timer interrupt
function, playtone that continuously interrupts at a rate of two times a second along that uses two global
Boolean variables, alarm and toggle_tone. Alarm is set/reset by the main program input polling loop and
checked in the ticker interrupt function to see if the alarm should sound. The interrupt function should check
alarm and then use and toggle a global Boolean variable, toggle_tone, to turn off the speaker 1000 Hz tone
half of the time (i.e. every other interrupt – Hint: check toggle_tone (and alarm), and then toggle toggle_tone
every interrupt) to turn the beeps and LED1 on/off as needed.
Download