EE234 Exam 3
Name:
Score:
Part 1. (2 points each)
(D )1. Which port pin is used by DACB channel 1 output? (a) PA2 (b) PA3 (c) PB2 (d) PB3
(D )2. Using the RS232 standard, when a computer intends to transmit data, which signal
should it assert to the modem that it is connected? (a) DTR (b) CTS (c) DSR (d) RTS
(A )3. If you want to use event channel 7 to trigger the DACB conversion, what value should
be written into the DACB_EVCTRL register? (a) 7 (b) 6 (c) 5 (d) 4
(D )4. Which of the SPI modules use PORTF pins? (a) SPIC (b) SPID (c) SPIE (d) SPIF
(D )5. How to start SPIC data transfer? (a) write into the SPIC_CTRL register (b) write into
the SPIC_INTCTRL register (c) write into the SPIC_STATUS register (d) write into the
SPIC_DATA register
(A )6. What is the function of the DSR? (a) indicate that the DCE device is ready (b) indicate
that the DTE is intended to transfer (c) indicate that the DTE has data to transfer (d) there is
an incoming call
(A )7. How does the local computer tell the local DCE that it already finished the data
transfer? (a) de-assert the RTS signal (b) assert the RTS signal (c) assert the DTR signal (d)
assert the LL signal
(B )8. For the XMEGA128A1U DACA with 3.6 V VREF, what value should be written into the
DACA data register in order to generate a 2.4 V output? (a) 2230 (b) 2730 (c) 3600 (d) 3990
(D )9. What is the benefit of using NULL modem connection in the RS232 protocol? (a) save
power (b) increase data rate (c) automate data transfer (d) save the use of two modems
(D )10. Which of the following bits of the DACx_CTRLA register allows the DAC output to be
used by on-chip ADC and AC (analog comparator)? (a) ENABLE (b) LPMODE (c) CH0EN (d)
IDOEN
(B )11. Assume that the XMEGA is running at 32 MHz, what is the highest frequency of the
SPI that can be used to shift data in and out data bits? (a) 32 MHz (b) 16 MHz (c) 8 MHz (d) 4
MHz
(C )12. What value should be written into the DACA_CH0DATA+1: DACA_CH0DATA register if
we want to generate 2.5V output with VREF = 3.3 V? (a) 1102 (b) 2102 (c) 3102 (d) 3702
(D )13. What is the benefit of using NULL modem connection in the RS232 protocol? (a) save
power (b) increase data rate (c) automate data transfer (d) save the use of two modems
(C )14. Which of the following RS-232 signals is asserted by a DTE to accept the incoming
call? (a) RTS (b) CTS (c) DTR (d) RI
(A )15. What voltage range is used to represent logic 0 in the RS-232 standard? (a) +3V~+25V
(b) -10V~+10V (c) -3V~-25V (d) +5V~+25V
Part 2 (10 points each )
1. You are given the subroutines putsUSARTE0 and newline_USARTE0 to call. String
pointer is passed in Z and memory specifier is passed in r16 for putsUSARTE0. Write
1
an instruction sequence to define the following strings and output them to USARTE0
module and displayed as two rows on the terminal window:
Oh, my god, the exam is so tough.
I can relax for three months after exam.
Solution:
call
newline_USARTE0
ldi
ZL, low(msg1 << 1)
ldi
ZH, high(msg1 << 1)
ldi
r16, 1
call
putsUSARTE0
call
newline_USARTE0
ldi
ZL, low(msg2 << 1)
ldi
ZH, high(msg2 << 1)
ldi
r16, 1
call
putsUSARTE0
msg1: .db
msg2: .db
“Oh, my god, the exam is so tough.”, 0
“I can relax for three months after exam.”, 0
2. The USART module baud rate is set by the BAUDCTRLA and BAUDCTRLB registers. Let fPER
be 32 MHz. Write an instruction sequence to set the USARTE0 baud rate to 9600. Assume
that CLK2X is set to 1. Set the BSCALE field to 0.
Solution: By setting BSCALE to 0,
The value BSEL = 32 x 106 / (8 x 9600) - 1 = 417 – 1 = 416 = 0x1A0
ldi
r20, 0xA0
sts
USARTE0_BAUDCTRLA, r20
ldi
r20, 0x01
sts
USARTE0_BAUDCTRLB, r20
; the following two instructions are optional
ldi
r20, 0x1C
; set CLK2X, TXEN, RXEN bits to 1
sts
USARTE0CTRLB, r20
3. Write a subroutine to initialize the DACB to dual channel mode, data register left justified,
use AVCC as reference voltage, start D/A conversion when writing into the DATA register,
and enable DACB and both channels and their output. Channels 0 and 1 of DACB are assigned
to PB2 and PB3 pins.
Solution:
initDACB:
ldi
r20, 0x0C
sts
PORTB_DIRSET, r20 ; configure PB2, PB3 for output
2
ldi
r20, 0x0D
sts
DACB_CTRLA, r20 ; enable DACB, and channel 1 and channel 0
ldi
r20, 0x40
sts
DACB_CTRLB, r20
; two channel operation
ldi
r20, 0x09
sts
DACB_CTRLC, r20
; select AVCC as reference voltage, value left justified
ret
4. Assume fPER is 32 MHz. For the USARTE0, with CLK2X bit (of the USARTE0_CTRLB register)
set to 1, BSCALE set to 0 find the values to be written into the USARTE0_BAUDCTRLA and
USARTE0_BAUDCTRLB registers to generate the baud rate of (a) 2400 (b) 5000 (c) 9600 (d)
16000 (e) 32000
Solution:
BSEL = 32x106 ÷ (8 x baud)
(a) 2400: BSEL = 1666 = 0x682
BAUDCTRLA 0x82; BAUDCTRLB 0x06
(b) 5000: BSEL = 799 = 0x31F
BAUDCTRLA 0x1F; BAUDCTRLB 0x03
(c) 9600: BSEL = 416 = 0x1A0
BAUDCTRLA 0xA0; BAUDCTRLB 0x01
(d) 16000: BSEL = 249 = 0xF9
BAUDCTRLA 0xF9; BAUDCTRLB 0x00
(e) 32000: BSEL = 124 = 0x7C
BAUDCTRLA 0x7C; BAUDCTRLB 0x00
5. Configuring the XMEGA128A1U on-chip digital to analog converter (DACA or DACB) to use
12-bit resolution and set VREF to 3.6 V, what values can be converted to (a) 0.6V (b) 1.4 V (c)
1.8 V (d) 2.4 V (e) 3.2 V? (12 points)
Solution:
(a) 0.6 x 4095 / 3.6 = 683 = 0x2AB
(b) 1.4 x 4095 / 3.6 = 1593 = 0x639
(c) 1.8 x 4095 / 3.6 = 2048 = 0x800
(d) 2.4 x 4095 / 3.6 = 2730 = 0xAAA
(e) 3.2 x 4095 / 3.6 = 3640 = 0xE38
6. Assume that you are reading temperature from the TC72 temperature sensor. What are
the actual temperatures corresponding to the following temperature reading from TC72?
The left half is the MSB of temperature whereas the right half is the LSB of the temperature
(a) 01011010/0100 0000
90.25oC
(b) 11110001/0100 0000
-14.75oC
(c) 01101101/10000000
109.5oC
(d) 11110101/01000000
-10.75oC
(e) 11011101/10000000
-34.5oC
Solution:
(a) Integer part = 1011010 = 90; fraction part = 0.25; temperature = 90.25oC
(b) Temperature is negative; take its two’s complement = 00001110/1100 0000
Integer part = 14; fraction part = 0.75; Tempe rature = -14.75oC
3
(c) Integer part = 1101101 = 109; fractional part = 0.5; Temperature = 109.5oC
(d) Temperature is negative; take its two’s complement = 1010/1100 0000
Integer part = 1010 = 10; fraction part = 0.75; temperature = -10.75oC
(e) Temperature is negative; takes its 2’s complement = 00100010/10000000
Integer part = 34; fractional part = 0.50. Temperature = -34.5oC
7. For the circuit shown in Figure 12.10, the most significant bit of the byte sent out from the
MOSI pin will reach QH at the 8th clock cycle. The least significant bit will appear at QA. To
display a value (0 to 9) at certain display, you need to send the display select value followed
by the segment pattern for the value. Fill in the following blanks:
(a) display 9 at display #7 send 0x7F followed by 0x7B
(b) display 3 at display #6 send 0xBF followed by 0x79
(c) display 5 at display #5 send 0xDF followed by 0x5B
(d) display 6 at display #4 send 0xEF followed by 0x5F
(e) display 2 at display #3 send 0xF7 followed by 0x6D
3.3 V
470
.
.
.
a
b
g
.
.
. g
common
cathode
IMAX
3.3 V
reset
DS QH
MOSI
SCK
PD0
XMEGA128A1
#0
. . .
. . .
a
b
. . . g
common
cathode
SC
Q. G
LC .
.
OE
QA
74HC595 #2
.
.
.
IMAX = (3.3 – 0.1 – 1.8 ) ¸ 0.47 ¸ 7 = 20.85 mA
Figure 12.10 Two 74HC595s together drive eight seven-segment displays
4
common
cathode
IMAX = 20.85 mA
reset
OE
#6
a
b
IMAX
QG
QF
.
.
74HC595 #1
.
QA
DS
SC LC SQH
#7
470