You are on page 1of 4

FUNDAMENTALS OF MECHATRONICS CLASS TEST THREE HOURS ATTEMPT ALL QUESTIONS

QUESTION ONE

Describe the operation of a hardware stack clearly explaining how it is initialised. Explain the two terms: stack
underflow and stack overflow with respect to the operation of the stack. Explain its use when handling interrupts
and also when handling subroutine calls. [5]

A stack is initialised by making the stack pointer point to the last RAM location so the stack grows towards lower
addresses. A stack underflow occurs when more data items are retrieved from the stack than are pushed onto the
stack. A stack overflow occurs when the stack encroaches onto data area of memory.

The hardware Stack is used to store return addresses meaning subroutines can be nested. There are also used to save
all the processor registers meaning that interrupts can be nested.

The internal registers within the MC6809 microprocessor have the following values:

PC = $C043, SP = $8000, U = $6800, ACCA = $9F, ACCB = $A5,

CCR = $E2, IX = $9000, IY = $FF00 and DPR = $C0.

7FF6 E2 <= SP
7FF7 9F
7FF8 A5
7FF9 C0
7FFA FF
7FFB 00
7FFC 90
7FFD 00
7FFE C0
7FFF 43
Draw a memory fragment diagram showing the contents of the stack after a non maskable interrupt on NMI has
occurred and control has been transferred to the interrupt service routine. [10]

Describe the use of the DAA (Decimal Adjust Arithmetic) instruction in supporting decimal addition by adding the
two Binary Coded Decimal numbers $3854 and $4927 representing the decimal numbers 3854 and 4927. [10]

Add 54 and 27 first and note the Half Carry flag and the overall carry
0101 0100 Illegal digit 1011 means add 0110 to LSnibble
0010 0111
0111 1011
0000 0110
1000 0001 $81 No carry from lower byte position

Now add 38 and 49


0011 1000
0100 1001
1000 0001 Half carry flag is et so add $6 to lower nibble
0000 0110
1000 0111 Correct BCD result 8781
QUESTION TWO

Listing Q.2 shows an MC6809 microprocessor assembly language program. Assemble the program by hand into
machine code following the usual listing format produced by most assemblers and convert the code into both Intel
Hex format records and Motorola S format records. Include the end of file record in each case. [20]
0000 ORG $0000
0000 TAIL_POINTER RMB 2
0002 HEAD_POINTER RMB 2

1000 BUFFER_START EQU $1000


1FFF BUFFER_END EQU $1FFF
08 ACIA_RDRF EQU $08
8000 ACIA_RDR EQU $8000
8001 ACIA_STATUS EQU $8001

DC00 ORG $DC00


DC00 B6 8001 ACIA_ISR LDA ACIA_STATUS
DC03 85 08 BITA #ACIA_RDRF
DC05 27 13 BEQ ACIA_ERROR
DC07 B6 8000 LDA ACIA_RDR
DC0A BE 0000 LDX TAIL_POINTER
DC0D A7 80 STA 0,X+
DC0F 8C 1FFF CMPX #BUFFER_END
DC12 23 03 BLS NO_WRAP_AROUND
DC14 8E 1000 LDX #BUFFER_START
DC17 BF 0000 NO_WRAP_AROUND STX TAIL_POINTER
DC1A 3B ACIA_ERROR RTI
Listing Q.2

:10DC0000B6800185082713B68000BE0000A7808CQQ
:0BDC10001FFF23038E1000BF00003BQQ
:00000001FF
S113DC00B6800185082713B68000BE0000A7808CQQ
S10EDC101FFF23038E1000BF00003BQQ
S9030000FC

Explain how the index registers IX and IY are incremented and decremented on the MC6809 microprocessor using
instructions from the microprocessor’s instruction set. [5]

LEAX 1,X and LEAX -1,X are the equivalent of INCX and DECX respectively

LEAY 1,Y and LEAY -1,Y are the equivalent of INCY and DECY respectively.

QUESTION THREE

An MC68HC11 microcontroller is being driven by a 7.3728 MHz crystal. The value $83 is written into the
configuration register TMSK2 during initialisation after power on reset. What is the interval between the main timer
counter (TCNT) overflow interrupts and determine the exact number of interrupts per second to 6 decimal places.
[10]

A 7.3728 MHz crystal gives an Enable frequency of 1.8432 MHz. Enable period is 0.5425347222 micro seconds. TCNT
prescale factor is 16. TCNT incremented every 16 * 0.5425347222 microseconds or 8.6805555556 microseconds.
Multiply by 65536 to get 568 888.888 microseconds or 0.5688888 seconds. 1.6981132078 interrupts per second.

Another MC68HC11 microcontroller is being driven by an 8 MHz crystal. Its serial link supported by the SCI
subsystem is running at 9600 bps. Determine the configuration byte which must be written to the register BAUD
during initialisation after power on reset. [7]
Baud Rate = Crystal frequency /(4 * 16 * P * R) or P * R = crystal frequency /(4 * 16 * Baud Rate)

8000000/(64 * 9600) = 8000000/614400 = 13.020833. Select SCI Prescale factor of 13 and Rate Select factor of 1.

Hence $30 must be written into BAUD during initialisation.

In an MC68HC11 microcontroller operating in the normal expanded mode, the two Motorola MC6821 PIAs in the
system are selected by low active chip selects CSIO1 and CSIO2. Internal configuration registers have been relocated
to the address range $9000 through $905F. Determine the addresses of all the internal registers of the two PIAs. [8]

CSIO1 starts at $9060 and CSIO2 starts at $9800. Assume A0, A1 connected to RS0 and RS1. Then the addresses are

PIA1 PIA2

DDRA 9060 (CRA2 = ’0’) 9800 (CRA2 = ‘0’)

PRA 9060 (CRA2 = ’1’) 9800 (CRA2 = ’1’)

CRA 9061 9801

DDRB 9062 (CRB2 = ’0’) 9802 (CRB2 = ’0’)

ORB 9062 (CRB2 = ’1’) 9802 (CRB2 = ’1’)

CRB 9063 9803

QUESTION FOUR

Assuming a reference voltage of 5V for the 8-bit ADC on the MC68HC11 microcontroller, determine the digital result
from converting a 4.17 volt analogue input sample on an analogue input channel. What analogue input voltage is
required to produce a result of $3E? [6]

Vin/VREF = Digital Result/255; Digital Result = 255 vin/VREF. Result = 255 (4.17)/5 = 212.67 => 213 or $D5

$3E is 48+14 = 62. 62/255 = vin/VREF. Vin = 62 VREF/255 = 1.215686 volts.

Describe the input capture and output comparison operations on the MC68HC11 microcontroller and explain how an
incoming input event can be related to a corresponding out going output event with the use of these two features.
Describe pulse width modulation (PWM) on the speed control of a DC motor using output comparison. [5]

Input capture. When programmed incoming event occurs, current value of TCNT is transferred to corresponding
capture register. Interrupt occurs.

Each time TCNT is incremented, hardware compares TCNT value with contents of output comparison registers.
When a match occurs, programmed output comparison event takes place immediately with no software delays.

Draw the corresponding circuit diagram used in this application and explain its operation. [4]

Mark space ratio gives the effective DC voltage across the motor and is therefore proportional to its speed. Program
for the output comparison channel to change its state each time, i.e. toggle. Add a delay time corresponding to the
mark or space which ever is now on the output line.
Q2

RC DC
VBAT MOTOR
RB
Q1
PWM CONTROL SIGNAL

103 bytes are to be written to the Microchip 25LC640 Serial EEPROM starting at address $10EA. Come up with a
schedule of write operations, clearly stating the number of bytes written with each write operation and the start
address of that write operation. [10]

Opening Byte balance Start Address End Address Bytes written Closing Byte Balance

WEL command

103 bytes 10EA 10FF 22 81

WEL command

81 bytes 1100 111F 32 49

WEL command

49 bytes 1120 113F 32 17

WEL command

17 bytes 1040 10FF 17 0

You might also like