Hcs08 AD converting problem

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

Hcs08 AD converting problem

Jump to solution
1,356 Views
Mico
Contributor I

Hello Im using demoboard mc9S08LC60. and i want convert value from potentiometer.

My code is in assembler, but evry registers are set like in demo code write in C .

 

Problem is that there is no results from AD converting .  - i thing that converting is not start.

here is my code. Thanks.

;*******************************************************************
;* This stationery serves as the framework for a user application. *
;* For a more comprehensive program that demonstrates the more *
;* advanced functionality of this processor, please see the *
;* demonstration applications, located in the examples *
;* subdirectory of the "Freescale CodeWarrior for HC08" program *
;* directory. *
;*******************************************************************

; Include derivative-specific definitions
INCLUDE 'derivative.inc'

; export symbols
XDEF _Startup, main
XDEF tlacidlo_ISR, main
XDEF prevod_ISR, main
; XDEF hodiny,main
; we export both '_Startup' and 'main' as symbols. Either can
; be referenced in the linker .prm file or from C/C++ later on


XREF __SEG_END_SSTACK ; symbol defined by the linker for the end of the stack


; variable/data section
MY_ZEROPAGE: SECTION SHORT ; Insert here your data definition

; code section
MyCode: SECTION


; zacoatok hlavneho programu
main:
_Startup:
; inicializacia
LDHX #__SEG_END_SSTACK ; initialize the stack pointer
TXS
CLI

LDA #$13
STA SOPT1 ; enable interrupts
; port B3-7 and port A as output
LDA #$F8
STA PTBDD

LDA #$E0
STA PTADD


; set clock FEI

Hodiny:

LDA $FFBE
STA $3E

LDA #$28
STA ICGC1

LDA #$51
STA ICGC2
BRCLR 3,ICGS1,Hodiny


; Counter overflow every 1ms
LDA #$1F
STA TPM1MODH
LDA #$40
STA TPM1MODL
; Stops timer and selects 1 as prescaler divisor
LDA #$08
STA TPM1SC

; set ad convertor
LDA #$20 ; 22 pta2 to je x os
STA ADCSC1 ; nastavenie adc prevodnika
LDA #$60 ;60
STA ADCCFG ;mo, bez clock divide, short sample, 8 bit , bus clock
LDA #$00
STA ADCSC2


mainLoop:
; Insert your code here


prevod: BRCLR 7,ADCSC1,prevod
LDA $13

feed_watchdog
BRA mainLoop













Labels (1)
0 Kudos
1 Solution
629 Views
bigmac
Specialist III

Hello,

 

If the debugger is observing the value in the ADCRL register, it is possible that this action is clearing the COCO flag prior to the test, during single stepping.  If you place a break point following the instruction where the flag is tested, rather than single stepping, does the code now work?

 

I note that you have selected continuous conversion mode.  Since you are initiating a conversion within each cycle of the loop, single conversion mode is more appropriate.  However, looping to write to ADCSC1 multilple times is wrong.  This register should be written once to start a conversion, and then wait until the COCO flag becomes set.

 

Regards,

Mac

 

View solution in original post

0 Kudos
5 Replies
629 Views
bigmac
Specialist III

Hello, and welcome to the forum.

 

I cannot see the code where you are waiting for the COCO flag to become set, and are then reading the ADCRL register to obtain the 8-bit conversion result.

 

Writing to ADCSC1 will intiate the conversions.  This should be done after the other registers have been initialised.  Additionally, you do not seem to have initialised the AD pin within the APCTL1 register.

 

I have also noticed that your GPIO initialisation does not match your comment.  But PTA0 will not be output since this is the AD pin.

 

For the initialisation process consider using the MOV instruction, rather than LDA/STA.  This will work for the low registers.

 

Regards,

Mac

 

0 Kudos
629 Views
Mico
Contributor I

Thank a lot.

 

Problem was with start converting.

 

For COCO register i waiting on the end of my code in mainLoop, but problem was because i dont repeatly set ADSC1 register. so COCO flag don set... something like this (sorry about my english :smileyhappy:  )

 

but now is evrything OK

 

mainLoop:
; Insert your code here

 LDA #$20
STA ADCSC1
  BRCLR 7,ADCSC1,mainLoop  ; COCO is 7th flag in this register
LDA $13

feed_watchdog
BRA mainLoop

 

 

 Thanks Mico

 

 

0 Kudos
628 Views
Mico
Contributor I

I hoped that my problem its solved, but is still here.

 

When i debug and run my program, i cant see changes .(led no light)  but when i stop and sart just step prgram evryhting is OK. (mean that LED start lighting. )

 

 

;*******************************************************************
;* This stationery serves as the framework for a user application. *
;* For a more comprehensive program that demonstrates the more *
;* advanced functionality of this processor, please see the *
;* demonstration applications, located in the examples *
;* subdirectory of the "Freescale CodeWarrior for HC08" program *
;* directory. *
;*******************************************************************

; Include derivative-specific definitions
INCLUDE 'derivative.inc'

; export symbols
XDEF _Startup, main
XDEF tlacidlo_ISR, main
   
; XDEF hodiny,main
; we export both '_Startup' and 'main' as symbols. Either can
; be referenced in the linker .prm file or from C/C++ later on


XREF __SEG_END_SSTACK ; symbol defined by the linker for the end of the stack


; variable/data section
MY_ZEROPAGE: SECTION SHORT ; Insert here your data definition

; code section
MyCode: SECTION

;prerusenie tlacidlom zmena lediek .... na konci naspet povoli prerusenie myslim overit
tlacidlo_ISR: BRSET 5,PTBD,L2

BCLR 7,PTBD
BSET 5,PTBD
BSET 2,IRQSC
RTI
L2: BCLR 5,PTBD
BSET 7,PTBD
BSET 2,IRQSC
RTI



; zacoatok hlavneho programu
main:
_Startup:
; inicializacia
LDHX #__SEG_END_SSTACK ; initialize the stack pointer
TXS
CLI

LDA #$13
STA SOPT1 ; enable interrupts
; nastavenie portu B3-7 ako vystup
LDA #$F8 ; ak dam iba $Fo tak mi do A zapise hodnotu z pamet miesta F0
STA PTBDD

LDA #$E0
STA PTADD

; nastavenie prerusenia tlacidla
BCLR 5,IRQSC ; PADAJUCA HRANA
BSET 4,IRQSC ; IRQ pin enable
BSET 1,IRQSC ; IRQ hardware interrupt request whenever IRQF = 1
; NASTAVENIE HODIN INTERNE HODINY POTREBNE K AD PREVODNIKU NA NASTAVENIE RYCHLISTI PREVODU

Hodiny:
; nahranie toho NVI... nieco treba to odlozit ICGTRM,NVICGTRM
LDA $FFBE
STA $3E
LDA #$28
STA ICGC1
LDA #$51
STA ICGC2
BRCLR 3,ICGS1,Hodiny

; nastavenie ad prevodnika

LDA #$60 ;60
STA ADCCFG ;mo, bez clock divide, short sample, 8 bit , bus clock
LDA #$00
STA ADCSC2

;LDA #$01
;STA APCTL1

mainLoop:
; Insert your code here

LDA #$20 ; set AC convertor
STA ADCSC1
BRCLR 7,ADCSC1,mainLoop ; wait until conversion is complete

LDA $13 ; load Data results low register
STA ,X
AND #$E0
STA $00 ;set data results register like outputs for PTAD

LDA ,X
AND #$F8
STA $02 ; set data results register like outputs for PTBD


feed_watchdog
BRA mainLoop

 

 

Thx

0 Kudos
630 Views
bigmac
Specialist III

Hello,

 

If the debugger is observing the value in the ADCRL register, it is possible that this action is clearing the COCO flag prior to the test, during single stepping.  If you place a break point following the instruction where the flag is tested, rather than single stepping, does the code now work?

 

I note that you have selected continuous conversion mode.  Since you are initiating a conversion within each cycle of the loop, single conversion mode is more appropriate.  However, looping to write to ADCSC1 multilple times is wrong.  This register should be written once to start a conversion, and then wait until the COCO flag becomes set.

 

Regards,

Mac

 

0 Kudos
629 Views
Mico
Contributor I

THX problem is solved, i just take out  write to ADCSC1 from loop.

 

and ist true that during single steping COCO is clearing. (when i placed a break point  behind test COCO, cond doesnt work  )

0 Kudos