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
txs
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
rts
;-----------------------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
rts
;-----------------------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
rts
;-----------------------ADC_STOP subroutine----------------------------
;power off the ADC by writing CH=11111 to ADCSC1
ADC_STOP mov #STOPADC,ADCSC1
rts
;----------------------end code-----------------------------
James
James,
I tried you code and it worked perfectly for me on a QG8. The chip that comes with the spyder (the 8 pin one) is a QG4. Are you using the 16pin QG8 or the 8pin QG4? Your program is configured to run on the QG8 as written- a couple of EQU's must be changed to run on the QG4. With the in-circuit debugger, this runs for me on the QG4 but the ADC does not work properly.
Hello,
Running the code on a QG4, using equates for the QG8, may work but is not guaranteed to do so. Primarily, the stack is placed at an invalid RAM location, and the code is placed at an invalid flash location for the QG4.
RAM and flash memory may exist at the specified locations, but is not tested, and not guaranteed.
Regards,
Mac