Experiment #12

advertisement
Laboratory Experiment #12:
Assembly Programming (II)
Ari Mahpour
Pei-Chun Chen
ECE 425 Lab
Contents
Abstract ........................................................................ 3
Procedure ..................................................................... 3
Results and Interpretation ........................................... 4
Conclusion .................................................................... 5
Attached Code .............................................................. 6
Pictures ......................................................................... 8
Abstract
In this laboratory experiment, the students were required to write a program in
assembly language that would record the period of an inputted frequency. In addition, rather
than prior to the previous laboratory experiment which functioned using the polling method,
we were to implement our project using an interrupt. This required a knowledge in both the
TIM and interrupt programming.
Procedure
The code to this laboratory experiment was broken down into a few parts. The main
program performed an interrupt service (found in chapter 6) which would wait for the interrupt
to occur and then proceed with determining the period of the input signal. The code is found in
section 6.7 of the corresponding lecture book. A bit of modification was necessary to ensure
that the code worked with our specifications.
The second portion of the program was the subroutines. A total of three subroutines
were written for this laboratory experiment: The timer initialization, the period measurer, and
the period value capturer. The timer initialization merely set up the timer channels, prescaler,
and interrupts (local and global) to ensure that the procedure would work properly. The next
subroutine, the period measurer, would perform a count in between the edges. Once we
acquired our data from edge to edge we then ran the period value capturer subroutine to store
that value. We would then have our period of the input frequency.
Results and Interpretation
We spent a considerable amount of time trying to interpret our data which usually
occurs in laboratory experiments. We were quite convinced that our code was working properly
but didn’t understand how we were to read our output. Our first test required an input signal at
a frequency of 40 KHz. To calculate our period we use the following equation:
1
= π‘ƒπ‘’π‘Ÿπ‘–π‘œπ‘‘ (𝑠)
πΉπ‘Ÿπ‘’π‘ž (𝐻𝑧)
π‘ƒπ‘’π‘Ÿπ‘–π‘œπ‘‘ =
1
1
=
= 2.5 ∗ 10−5 𝑠 = 25 µπ‘ 
6
40𝐾𝐻𝑧 40 ∗ 10
The contents of out calculated output period was placed across memory $902 and $903
(Using accumulator D). Our program reported 32 in hexadecimal format. At first we did not
understand how to interpret that data but with the help of the instructor we first converted it
to decimal and then divided it by the prescaler. Doing so gave us 25 (µs) which was the value
we were looking for.
The second test required a different input to ensure that our program was functioning
for all inputs. This time we tested 25 KHz which should return a 40 µs period. After running our
software we were able to get 50 in hexadecimal value. Converting that value to decimal and
dividing it by the prescaler did indeed gave us 40 µs.
Conclusion
This laboratory experiment was a true culmination of all that we have learned up until
chapter 8 in the lecture book. By using the TIM and interrupt systems we were able to code
such a program using our knowledge from the previous 5 chapters (fundamentals in assembly
coding). Though it was a challenging laboratory experiment it was also rewarding being able to
see our hard work come to fruition. Overall the laboratory experiments were very valuable not
only as an aid to learn the corresponding lecture material but also to get a practical understand
on how everything tied together. In the future, should we be required to program a
microcontroller such as the Motorola 68HC12, we will feel very confident to meet the
challenge.
Attached Code
****************
* Ari Mahpour *
*
Lab 12
*
****************
* Referencing from page 273 in book
****************
* Declarations *
****************
REG_BASE
TMSK1
TMSK2
TCTL4
TIOS
TC2H
TSCR
TFLG1
TMSK2_IN
TCTL4_IN
TIOS_IN
TSCR_IN
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
$0000
$008C
$008D
$008B
$0080
$0094
$0086
$008E
$02
$10
EQU $00
EQU $80
INTRP_ADDR EQU
USER_VEC
EQU
$6000
$FE1A
ORG
FDB
FDB
FCB
$0900
$0000
$0000
$02
edge_1
period
edge_cnt
;address of reg base
;declare offset of reg from base
;declare offset of reg from base
;declare offset of reg from base
;declare offset of reg from base
;declare offset of reg from base
;declare offset of reg from base
;declare offset of reg from base
;enable TOI,prescaler=4
;config IC2 for rising edge
;select ch2 for IC
;enable timer,normal flag clr
;User RAM at $0900
;reserved word for variable
;reserved word for variable
;counter for edges
****************
* Main Program *
****************
ORG $4000
*From page 224-225
ldd #INTRP_ADDR
pshd
ldd #!21
;Timer Overflow DBUG-12 Interrupt offset
ldx USER_VEC
jsr 0,x
pulx
movb
#$00,edge_1
movb
#$00,period
bsr TIMER_INIT ;timer initialization subroutine
bra
*
; branch forever
****************
* Subroutines *
****************
TIMER_INIT:
sei
ldaa
staa
ldaa
staa
ldaa
staa
ldaa
staa
;set I bit
#TMSK2_IN
TMSK2
#TCTL4_IN
TCTL4
#TIOS_IN
TIOS
#TSCR_IN
TSCR
;load TMSK2 using index addr
;enable TOI,prescaler=4
;conf IC2 for rising edge
;select ch2 for IC
;select ch2 for IC
;enable timer, standard flg clr
MOVB #$04,TMSK1 ;enable interrupts
cli
;clear I bit
rts
end
MEAS_PER:
org
;return from subroutine
INTRP_ADDR
;move to address $6000
ldaa edge_cnt
deca
staa edge_cnt
lbeq PERIOD_VAL
;load the edge counter
;edge_cnt = edge_cnt -1
;if z=1 (long branch) --> PERIOD_VAL
ldd
std
;Else
;store the edge in Ch2
TC2H
edge_1
*Clear flag (p 276)
ldaa TFLG1
oraa #$04
staa TFLG1
rti
;to clear IC2 flag, read flag first
;then write 1 to it
*Capture the value of period once edge-to-edge has been detected
PERIOD_VAL ldd TC2H
subd edge_1
std period
swi
end
Pictures
MCLK (MHz)
Prescalar
Actual clock (MHz)
Actual Period (ns)
Decimal Hex
8
4
2
0.5
Test 1
Input frequency (KHz)
Input period (us)
PERIOD_VAL
Actual value (divided by CLK)
40
25
50
25
Test 2
Input frequency (KHz)
Input period (us)
PERIOD_VAL
Actual value (divided by CLK)
25
40
80
40
32
50
Download