summaryrefslogtreecommitdiff
path: root/cmpen472hw11_McDonnell/bin/main.dbg
diff options
context:
space:
mode:
Diffstat (limited to 'cmpen472hw11_McDonnell/bin/main.dbg')
-rw-r--r--cmpen472hw11_McDonnell/bin/main.dbg148
1 files changed, 139 insertions, 9 deletions
diff --git a/cmpen472hw11_McDonnell/bin/main.dbg b/cmpen472hw11_McDonnell/bin/main.dbg
index a4a7b7a..8f41846 100644
--- a/cmpen472hw11_McDonnell/bin/main.dbg
+++ b/cmpen472hw11_McDonnell/bin/main.dbg
@@ -60,6 +60,17 @@ CRGFLG EQU $0037 ; Clock and Reset Generator Flags
CRGINT EQU $0038 ; Clock and Reset Generator Interrupts
RTICTL EQU $003B ; Real Time Interrupt Control
+; symbols/addresses
+ATDCTL2 EQU $0082 ; Analog-to-Digital Converter (ADC) registers
+ATDCTL3 EQU $0083
+ATDCTL4 EQU $0084
+ATDCTL5 EQU $0085
+ATDSTAT0 EQU $0086
+ATDDR0H EQU $0090
+ATDDR0L EQU $0091
+ATDDR7H EQU $009e
+ATDDR7L EQU $009f
+
TIOS EQU $0040 ; Timer Input Capture (IC) or Output Compare (OC) select
TIE EQU $004C ; Timer interrupt enable register
TCNTH EQU $0044 ; Timer free runing main counter
@@ -114,8 +125,12 @@ numPoints dc.w 2048 ; Max Number of points for waves
timeTrigger dc.b $00 ; Tracks when timer is triggered
-increment dc.w 1 ; Used for increment 31.25Hz -> 1
- ; 125Hz -> 4
+increment dc.w 1 ; Used for increment 31.25Hz -> 1 for sawtooth
+ ; 15.625Hz -> 1 for triangle & square
+ ; 100Hz -> ~3 for sawtooth
+ ; 100Hz -> ~6 for triangle & square
+
+adcvalue dc.b 00 ; Buffer to store the value from the adc
waveType dc.b 'S' ; Used to track wave type 'T' for increasing triangle,
; 't' for decreasing triangle,
@@ -155,6 +170,13 @@ pgstart lds #$3100 ; initialize the stack pointer
ldx #msg ; Load the address of the welcome message into X
jsr WriteString ; Write the string to the serial console
+ ldaa #%11000000 ; Turn on ADC, clear flags, disable ADC interrupt
+ staa ATDCTL2
+ ldaa #%00001000 ; Single conversion per sequence
+ staa ATDCTL3
+ ldaa #%10000111 ; 8-bit, ADCLK=24MHz/16=1.5MHz, sampling time = 2(1/ADCLK)
+ staa ATDCTL4
+
bset RTICTL,%00011001; set RTI: dev=10*(2**10)=2.555msec for C128 board
; 4MHz quartz oscillator clock
bset CRGINT,%10000000; enable RTI interrupt
@@ -267,6 +289,8 @@ oc5isr ldd interval ; Load the interval for the next clock c
bset TFLG1,%00100000 ; Clear CH5 interrupt flag
ldaa #1 ; Load 1 into A
staa timeTrigger ; Signal that timer went off
+ jsr ReadADC ; Read teh value from the ADC
+ jsr StartADC ; Start next ADC Read
ldd outputCnt ; Load the count of values outputed into D
addd #1 ; Increase output count by 1
std outputCnt ; Update the count of outputted values
@@ -276,6 +300,46 @@ oc5isr ldd interval ; Load the interval for the next clock c
oc5Done RTI ; Return from interrupt
;*************************************************************************
+; StartADC subroutine
+;
+; This subroutine will set flags to start analog signal aquisition.
+;
+; Input: No input, values hard coded
+; Output: ADC starts acquisition
+; Registers in use: A for setting up the ADC control register
+; Memory locations in use: ADC control register 5
+;
+; Comments: The ADC will start right justified, unsigned, single conversion.
+;
+
+StartADC
+ psha ; Save A to the stack
+ ldaa #%10000111 ; Right justified, unsigned, single conversion
+ staa ATDCTL5 ; Single channel, channel 7, start
+ pula ; Restore A from the stack
+ rts ; Return from caller
+
+;*************************************************************************
+; ReadADC subroutine
+;
+; This subroutine will read the value acquired by the ADC into a memory location.
+;
+; Input: The value acquired by the ADC
+; Output: The value acquired by the ADC in adcvalue memory location.
+; Registers in use: B to read and store the value.
+; Memory locations in use: adcvalue byte memory location for output.
+;
+; Comments: Only 1 byte will be read from the ADC.
+;
+
+ReadADC
+ pshb ; Save B to the stack
+ ldab ATDDR0L ; Read value from ADC into B
+ stab adcvalue ; Store the value in adcvalue
+ pulb ; Restore B from the stack
+ rts ; Return to caller
+
+;*************************************************************************
; PrintWave subroutine
;
; This subroutine will print a one byte decimal value to the serial console.
@@ -386,7 +450,7 @@ TriangleDec clra ; Clear A
pula ; Restore A from the stack
subd increment ; Subtract increment from D
cpd #0 ; Compare D to 0
- blt DonePrint ; If D < 0, done
+ bge DonePrint ; If D >= 0, done
ldaa #'T' ; Load 'T' into A
staa waveType ; Update wave type to increasing triangle
clrb ; Clear B
@@ -413,7 +477,7 @@ StartTimer5oc
PSHD
LDAA #%00100000
STAA TIOS ; set CH5 Output Compare
- STAA TIE ; set CH5 interrupt Enable
+ ;STAA TIE ; set CH5 interrupt Enable
LDAA #%10000000 ; enable timer, Fast Flag Clear not set
STAA TSCR1
LDAA #%00000000 ; TOI Off, TCRE Off, TCLK = BCLK/1
@@ -471,6 +535,7 @@ GenWave
ldd #0 ; Clear D
std outputCnt ; Clear outputCnt
staa outputVal ; Clear outputVal
+ staa timeTrigger ; Clear timeTrigger
jsr StartTimer5oc ; Start Timer on CH5
@@ -488,6 +553,50 @@ genLoop ldaa timeTrigger ; Load timeTrigger into A
rts ; Return
;*************************************************************************
+; ADCSample subroutine
+;
+; This subroutine will setup OC5 timer to sample the ADC every 125 usec and print
+; the value to the serial console.
+;
+; Input: No input, values hardcoded
+; Output: The acquired signal on the serial console.
+; Registers in use: A for reading the timeTrigger and adcvalue variables
+; D for reading outputCnt.
+; Memory locations in use: outputCnt, outputVal, timeTrigger, numPoints, adcvalue
+;
+; Comments: This subroutine requires the OC5 timer to be setup, the serial uart
+; to be setup, and the ADC on pin 7 to be setup.
+;
+
+ADCSample
+ pshd ; Save D to the stack
+ ldd #0 ; Clear D
+ std outputCnt ; Clear outputCnt
+ staa outputVal ; Clear outputVal
+ staa timeTrigger ; Clear timeTrigger
+
+ jsr StartTimer5oc ; Start Timer on CH5
+
+adcLoop ldaa timeTrigger ; Load timeTrigger into A
+ beq adcLoop ; If A == 0, loop
+ clra ; Clear A
+ staa timeTrigger ; Clear timeTrigger
+ ldab adcvalue ; Load the ADC value into B
+ ldy #buffer ; Load the address of buffer into Y
+ jsr PrintDecimalWord; Print the ADC value to the serial console
+ ldaa #CR ; Load CR into A
+ jsr putchar ; Print CR to serial
+ ldaa #LF ; Load LF into A
+ jsr putchar ; Print LF to serial
+ ldd outputCnt ; Load outputCnt into D
+ cpd numPoints ; Compare D to numPoints
+ blo adcLoop ; If D < numPoints, Loop
+
+ jsr StopTimerCH5 ; Turn off timer
+ puld ; Restore D from the stack
+ rts ; Return
+
+;*************************************************************************
; PrintTime subroutine
;
; This subroutine will print the time, command prompt, and maybe an error prompt.
@@ -654,7 +763,7 @@ isQ cmpa #'q' ; Compare A to 'q'
lbne badCommand ; If B != NULL, branch to ecDone
jmp TypeWrite ; Jump to TypeWrite
isGw cmpa #'g' ; Compare A to 'g'
- lbne badCommand ; If A != 'g', branch to badCommand
+ lbne isADC ; If A != 'g', branch to isADC
ldaa 1,x+ ; Load next character into B
cmpa #'w' ; Compare A to 'w'
bne isGt ; If A != 'w', branch to isGt
@@ -731,6 +840,22 @@ isGq2 cmpb #'2' ; Compare B to '2'
ldx #doneWave ; Load the address of doneWave
jsr WriteString ; Write string
lbra ecDone ; Branch always to ecDone
+isADC cmpa #'a' ; Compare A to 'a'
+ bne badCommand ; If A != 'a', bad command
+ ldaa 1,x+ ; Load next character
+ cmpa #'d' ; Compare A to 'd'
+ bne badCommand ; If A != 'd', bad
+ ldaa 1,x+ ; Load next character
+ cmpa #'c' ; Compare A to 'c'
+ bne badCommand ; If A != 'c', bad
+ ldaa 1,x+ ; Load next character
+ bne badCommand ; If A != NULL, bad
+ ldx #adcMsg ; Load the address of the ADC message into X
+ jsr WriteString ; Write the string to serial console
+ jsr ADCSample ; Branch to ADCSample
+ ldx #doneADC ; Load the doneADC message into X
+ jsr WriteString ; Write the string to the serial console
+ lbra ecDone ; Branch always to ecDone
badSeconds puld ; Restore Seconds from the stack
std seconds ; Restore seconds before change
badMinutes puld ; Restore minutes from the stack
@@ -1048,18 +1173,20 @@ twMsg dc.b 'Wave Generator and Clock stopped and Typewrite program
; Messages for different waveforms
swMsg dc.b 'sawtooth wave generation...',CR,LF,NULL
-sw2Msg dc.b 'sawtooth wave 125Hz generation...',CR,LF,NULL
+sw2Msg dc.b 'sawtooth wave 100Hz generation...',CR,LF,NULL
tMsg dc.b 'triangle wave generation...',CR,LF,NULL
sqMsg dc.b 'square wave generation...',CR,LF,NULL
-sq2Msg dc.b 'square wave 125Hz generation...',CR,LF,NULL
-
+sq2Msg dc.b 'square wave 100Hz generation...',CR,LF,NULL
+adcMsg dc.b 'analog signal acquisition...',CR,LF,NULL
doneWave dc.b 'Done generating wave.',CR,LF,NULL
+doneADC dc.b 'Done acquiring wave.',CR,LF,NULL
; prompt: command prompt string
prompt dc.b 'HW 11> ',NULL
; msg: this is the main option menu string
msg dc.b 'Commands:',CR,LF
+ dc.b 'adc: analog signal acqusition, for total 2048 points',CR,LF
dc.b 'gw: generate sawtooth wave, printing 0 through 255, repeated for total 2048 points',CR,LF
dc.b 'gw2: generate sawtooth wave of 125Hz, wave repeated for total 2048 points',CR,LF
dc.b 'gt: generate triangle wave, printing 0 through 255, then 255 down to 0, repeated for total 2048 points',CR,LF
@@ -1069,5 +1196,8 @@ msg dc.b 'Commands:',CR,LF
dc.b 'h: Display the hours on the 7 segment displays',CR,LF
dc.b 'm: Display the minutes on the 7 segment displays',CR,LF
dc.b 's: Display the seconds on the 7 segment displays',CR,LF
- dc.b 'q: Stop the clock and enter typewriter',CR,LF,NULL
+ dc.b 'q: Stop the clock and enter typewriter',CR,LF,CR,LF
+ dc.b '(1) Save Terminal output to file,',CR,LF
+ dc.b '(2) Run analog signal command - connect an analog signal to ADC pin 7',CR,LF
+ dc.b '(3) When ready, enter adc command to start the 2048 point ADC data capture.',CR,LF,NULL