Using ADC in QG8 with Assembly Step in CW Debugger

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using ADC in QG8 with Assembly Step in CW Debugger

3,380 Views
admin
Specialist II
Hi,
I have written a short code for Assembly Step to test my QG8 circuit, when I use Assembly Step within MainLoop: loading the EQU values and stores to Port B it display correctly.

However, I would like to display the sampled data in ADCRL continuosly i.e varying the input voltage at ADCH 0 and display it on the LEDs. When I step the code within MainLoop: the value displays on the LEDs does not change, can anyone have a look at my code and suggest why the value loaded from ADCH0 remains unchanged?

Thanks!

Code:
; application entry point
            ABSENTRY _Startup

; export symbols
            XDEF _Startup
            ; we use '_Startup' as an export symbol. This allows
            ; us to reference '_Startup' either in the linker
            ; *.prm file or from C/C++ later on.
           
            ; Include derivative-specific definitions
            INCLUDE 'derivative.inc'




;*==========================*
;*      data section        *
;*==========================*

                ORG   $F500        
ZERO            equ   $C0               ; 7 segment LED digit
ONE             equ   $F9
TWO             equ   $a4
THREE           equ   $B0
FOUR            equ   $99
FIVE            equ   $92
SIX             equ   $82
SEVEN           equ   $78
EIGHT           equ   $80
NINE            equ   $18
DOT             equ   $EF


;Latch select 7 segment led digit

Digit           equ   $08
Deci            equ   $04
Sec_Deci        equ   $02

;*---------------------------*
;*   program variables       *
;*---------------------------*

ADCSample       DS.B   1

;//***************************//

            ORG    ROMStart

_Startup:

;_Initialize Set up:

            LDHX   #RAMEnd+1           ; initialize the stack pointer
            TXS

;//======== ADC SETUP ==========//

            lda   #%00001011           ; high pwr | /1 | short sampling | 10 bit | Asynchronous clock (ADACK) 
            sta   ADCCFG
            lda   #%00100000           ; interrupt disabled | Continuous Conversion | ADCH 0 |
            sta   ADCSC1               ;
            lda   #%00100000           ; Software trigger | Compare function enabled | Compare triggers when input is less than compare level |       
            sta   ADCSC2               ;
            lda   #%00000001           ; disable the I/O port
            sta   APCTL1               ; used as analog inputs.


;//========PORT SETUP===========//

            lda   #%00001110           ; set pin PA1 PA2 PA3 output 
            sta   PTADD
            lda   #%11111111           ; set port B as output                   
            sta   PTBDD              


;         ******************       
;**********                **********
;*//======{  PROGRAM MAIN  }======//*
;**********                **********
;         ******************

MainLoop:
            lda   #Sec_Deci            ;select 2nd decimal(7 segment LED)
            sta   PTAD
            lda   ADCRL                ;load low byte sample
            sta   PTBD                 ;display low byte
           
            lda   #Deci                ;select 1st decimal(7 segment LED)           
            sta   PTAD
            lda   ADCRL
            sta   PTBD
           
            lda   #Digit               ;select digit(7 segment LED)           
            sta   PTAD
            lda   ADCRL
            sta   PTBD
           
           
            bra   MainLoop

            org   Vreset
            dc.w  _Startup


 

 



Message Edited by Learner on 2008-02-05 06:03 AM

Message Edited by Learner on 2008-02-05 06:12 AM
Labels (1)
0 Kudos
11 Replies

740 Views
bigmac
Specialist III
Hello,
 
I am not entirely sure of what you are attempting to achieve.  Assuming a single 7-segment display digit is connected to
Port B,
simply writing the lower 8 bits of the 10-bit ADC reading is unlikely to be meaningul.  With this setup, at best you
might display
a single (hexadecimal) digit, based on the upper 4-bits of the 8-bit ADC result.
 
I can also see a couple of issues related to the ADC.  Firstly, since the result you are expecting is a single byte, the ADC
should
set for 8-bit operation, rather than 10-bit, as you appear to have.  Secondly, you do not wait until each conversion
is complete before
attempting to read the result.
 
READ_ADC_HEX:
    brclr  ADCSC1_COCO,ADCSC1,*  ; Wait for conversion complete
    lda    ADCRL                 ; Will also clear COCO flag
    nsa                          ; Get high nybble value
    and    #$0F
    tax
    clrh
    lda    NUMTAB,x              ; Lookup table for 7-seg digit (0-9, A-F)
    sta    PTBD
    rts
 
NUMTAB:    ; Lookup table for 7-seg digit
    dc.b   $C0,$F9,$A4,$B0
    dc.b   ....
    etc.
 
With continuous conversion mode, new conversions will be completed very rapidly (within a few microseconds), and the
display of a rapidly changing value
would possibly be "blurred".  An alternative might be to manually start each conversion,
at a rate determined by a timing process, perhaps about five times per second.
 
I also note that you have defined the variable ADCSample, intended to be within RAM.  However, the is preceded by the
ORG $F500 directive, which is outside of RAM boundaries. 
 
Regards,
Mac
 


Message Edited by bigmac on 2008-02-05 08:47 PM
0 Kudos

740 Views
admin
Specialist II
Hi bigmac,
Thank you for your suggestions!

Can you explain whats the difference to save the variables and equates to the ram instead of Flash?

The QG8 has

Z_RAMStart:         equ   $00000060

and

RAMStart:           equ   $00000100

Do you know why and whats this for? Which address should I be using to store the variables?

Thanks!


0 Kudos

740 Views
bigmac
Specialist III
Hello,


Learner wrote:
Can you explain whats the difference to save the variables and equates to the ram instead of Flash?


Tthe use of equates is a programming convenience, to make assembly code easier to follow.  They allow a meaningful
label to be used in lieu of a non-descript numeric constant.  The equates themselves do not generate any code, or
consume any RAM.  However, an instruction in which the equate name is used will occupy flash.

The assignment of a variable always refers to read-write memory (or RAM).  Flash is considered read-only memory. 
The use of flash for the storage of non-volatile data requires a programming process, similar to the programming of
code.
 
  ORG <RAM location>
...
...
ADCSample:    DS.B   1
 
This specifies that the assembler reserve space at the current location for a one-byte variable, to be identified by the
name ADCSample.  The current locatiion requires to be an address within read-write memory.
 
If you needed to program constant data, the current location requires to be within flash, otherwise the value will not be
retained.
 
  ORG <Flash location>
...
...
STRING1:     DC.B   "The quick brown fox"
 
Regards,
Mac
 


Message Edited by bigmac on 2008-02-06 02:47 AM
0 Kudos

740 Views
PeterHouse
Contributor I
Noob,

The 08 has ZERO page and NON-ZERO page RAM.  The first 256 byte page of RAM is called the ZERO page and is special since there are certain instructions which can address this memory using only a single address byte in the op code.  NON-ZERO page RAM must have two bytes of address information. 

ZERO page Ram is used to shorten the instruction parameter length to reduce code size and to increase execution speed.

Generally you will want to use ZERO page Ram for storage of flags and often used variables and use NON-ZERO page Ram for arrays and less frequently used data.  There is no penalty for using ZERO page Ram.

The ZERO page RAM starts at $60 since the on chip peripheral registers are located beginning at the lowest address in ZERO page Ram.

Good Luck,

Peter House
0 Kudos

740 Views
admin
Specialist II
Thanks guys!


What I am trying to do is to step through the MainLoop once and get the reading of ADCRL to display on the LEDs, then I will change the voltage and step through the MainLoop again to display the new sampled voltage on the LEDs.

Code:
;//======== ADC SETUP ==========//            lda   #%00110011          ; high speed | /2 | long sampling | 8 bit | Asynchronous clock (ADACK)              sta   ADCCFG            lda   #%00100000          ; interrupt disabled | Continuous Conversion | ADCH 0 |            sta   ADCSC1              ;             lda   #%00100000          ; Software trigger | Compare function enabled | Compare triggers when input is less than compare level |                    sta   ADCSC2              ;             lda   #%00000001          ; disable the I/O port            sta   APCTL1              ; used as analog inputs.;//========PORT SETUP===========//            lda   #%00001110          ; set pin PA1 PA2 PA3 output              sta   PTADD            lda   #%11111111          ; set port B as output                                sta   PTBDD               ;         ******************        ;**********                **********;*//======{  PROGRAM MAIN  }======//*;**********                **********;         ******************MainLoop:            lda   #Sec_Deci            sta   PTAD            brclr  ADCSC1_COCO,ADCSC1,GO  ; Wait for conversion completeGO:         lda   ADCRL            sta   PTBD                         bra   MainLoop            org   Vreset            dc.w  _Startup

 

What is happening now  is that LED pattern does not change and when I look at the value of Acc in the Register window in Debugger, lda ADCRL loads the same value as the previous step of the MainLoop; after I have already changed the voltage at ADC0.






Message Edited by Learner on 2008-02-05 04:00 PM
0 Kudos

740 Views
bigmac
Specialist III
Hello,
 
Your code has the label G0 on the incorrect line. the next instruction will be executed
independent of the state of the COCO bit.  If you wish to use an explicit label, the
following would be required -
 
G0:   brclr  ADCSC1_COCO,ADCSC1,GO  ; Wait for conversion complete
 
Regards,
Mac
 
0 Kudos

740 Views
admin
Specialist II
Hi bigmac,

When I trace the MainLoop using asm step or another other steps it gets stuck on this line

G0:   brclr  ADCSC1_COCO,ADCSC1,GO  ; Wait for conversion complete

its as if the ADCSC1_COCO bit never sets/conversion never completes, its the same when I click on Run -> Start.

The Source window in the Debugger highlights

G0:   brclr  ADCSC1_COCO,ADCSC1,GO  ; Wait for conversion complete

and stuck on that line.

I have tested with another new QG8 with same outcome, may be I am missing something else in my code?
0 Kudos

740 Views
JimDon
Senior Contributor III
Could be the deugger is reading the register and clearing the bit.
Try setting a break point at the line after - do step over that line.
0 Kudos

740 Views
admin
Specialist II
Hi JimDon,
I tried that but it didnt do anything.
0 Kudos

740 Views
allawtterb
Contributor IV
Try disabling the compare function. You have it turned on and COCO will only be set when the value is less than ADCCV, which you don't set so I will assume it to be 0 so COCO is never set.  You can disable this by loading ADCSC2 with 0x00 instead of 0x20.
0 Kudos

740 Views
admin
Specialist II
Hi allawtterb,
I have disabled the compare but its still the same. I have also tried

Code:
lda   #%00100000          ; high speed | /2 | short sampling | 8 bit | Bus clock sta   ADCCFG

 
What can I do to varify the ADC is actually working? any ideas?
           
0 Kudos