James Karns

S08QG8 ADC Problem - Watchdog Timeout while waiting for conversion

Discussion created by James Karns on Apr 12, 2009
Latest reply on Apr 12, 2009 by bigmac

Hey all;

I took a class a couple years ago using the MC68HC908QY4 with Assembler.  Thats the limit of my experience programming microprocessors.  Trying to sample two conditioned signals from an aerometer and import them into Matlab (i.e datalogger) but running into trouble getting the basic ADC working

Using S08QG8 (Spyder discovery kit) and CodeWarrior 5.7.0

With both the simulator and the chip monitor (SofTecHCS08) the program gets locked in an endless loop executing ADC_WAIT and triggers the Watchdog

In the simulator the ADACT bit sets and clears and the result is stored into ADCRL but COCO never sets

In the chip monitor the ADACT bit sets and clears and the result is stored into ADCRL then COCO sets but the program never branches

Am I missing something really simple?

Any help would be appreciated

complete code included as attachment

; Code Section: ORGed to start of flash                                *
;               this is where you put all of the program code           *
               org    FLASHSTART
;Standard startup code
MAIN:    lda  #$D2             ;BKGDPE Enabled
             sta   SOPT1     ;systems options
               lda   #$00
             sta    SOPT2         ;systems options        
             ldhx  #RAMEND+1        ;re-initialize the stack pointer
             cli               ;enable interrupts
;Replace this with program startup code
MAININIT:    bsr    INIT_GPIO         ;setup GPIO ports
               bsr    INIT_ADC    ;initialize ADC for pins ADP0 and ADP1 

;Replace this with your main execution loop
MAINLOOP:     bsr  GET_ADC         ;the ADC voltage is in A
             bsr ADC_OUT         ;the ADC voltage is in Port B
ENDPROG:              ;if you don't feed the watchdog, the CPU will reset
             sta    WATCHDOG        ;feed the watchdog
             bra    MAINLOOP   
;-----------------------INIT_GPIO Subroutine----------------------------           
INIT_GPIO:    lda   #$00            ;zero byte
               sta   PTBD            ;clear port B data
               sta   PTBSE           ;turn off slew rate for all port B
               sta   PTBDS           ;set drive strength to low for all port B
               sta   PTBPE           ;disable internal pull up resistors for all port B
               lda   #$FF            ;one byte
               sta   PTBDD           ;enable output for all port B

;-----------------------INIT_ADC Subroutine----------------------------           
INIT_ADC:    bsr  ADC_STOP        ;disable ADC while configuring
             mov  #$00,ADCCFG     ;fast clock settings,8b mode
             mov  #$00,ADCSC2     ;software trigger, no compare
             bset  ADCPIN1,APCTL1  ;enable ADC pin ADP0

;-----------------------GET_ADC Subroutine-----------------------------
;perform a single conversion on the ADC
;channel number (0-7) passed in accumulator A
;ADC data returned in accumulator A
GET_ADC      mov   #ADCPIN1,ADCSC1         ;stop current pin and initiate conversion
WAIT_ADC     brclr COCO,ADCSC1,WAIT_ADC     ;poll COCO until conversion complete
             lda  ADCRL                   ;read data, clearing COCO
             bsr  ADC_STOP  ;the ADC voltage is in A 
DONE_ADC:    rts                        

;----------------------ADC_OUT Subroutine------------------------------                  
ADC_OUT:     sta  PTBD             ;send sample to output port

;-----------------------ADC_STOP subroutine----------------------------
;power off the ADC by writing CH=11111 to ADCSC1
;----------------------end code-----------------------------