Subject:
|
Read A/D converter
|
Newsgroups:
|
lugnet.robotics.handyboard
|
Date:
|
Thu, 22 Oct 1998 06:07:42 GMT
|
Original-From:
|
HECTOR NORIEGA <110060.2126@compuserve/StopSpam/.com>
|
Viewed:
|
1492 times
|
| |
| |
"HI" , I am trying to read the A/D converter but the program gets "Hung-Up"
on the line
"ANALOOP", the CCF bit never sets. Please give me a hint. Here is the
Assembly code.
/* MAGLEV.ASM, Magnetic Levitation by Hector Noriega, 28JUNE1998.*/
/*Handy Board */
/* Program to read PE1, ADR2 of Analog to Digital and write
/* and write the byte to PORTC.
BASE EQU $1000
ADCTL EQU $30 ; A/D Control/status Register
ADR1 EQU $31 ; A/D Result Register 1
ADR2 EQU $32 ; A/D Result Register 2
PIOC EQU $02 ; Parallel I/O Control register
HPRIO EQU $3C ; Highest Priority Interrupt and misc.
OPTION EQU $39 ; system configuration Options
ANALOG2 FCB $00
ORG $8000 ;PCODE_ORIGIN, builds upwards
FCB 0
ORG $C500 ;MAIN_CODE
NOP
NOP
NOP
NOP
NOP
LDS #$FEFF ;ini. Stack Pointer to top of RAM,grows
downwards
/**********************A/D*************************************/
LDX #BASE
LDAB #$65 ;0110 0101
STAB HPRIO,X ;HPRIOtest SMOD & MDA bit(normal expanded mode)
LDAB #$00
STAB PIOC,X ;PIOC $1002
/*INAD is a subroutine to read Analog channels *********/
BSR STARTAD
BSR INAD
LDAA #$80 ; to make the output bypolar
ABA ; add B to A
LDAB #$FF ; to set port "C"
STAB $07,X ;DDRC 1007 Set portc to output
STAA $6FFF ; L byte FF to PORTB,
BRA LOOP1 ; H byte 6F to PORTC latch
/* ; and data byte to PORTC*/
/* ; turn on interrupts*/
/*******************A/D subroutine*******************/
STARTAD
PSHX
LDX #BASE ;point to registers
BSET OPTION,X,$80 ; ADPU=to power up,set bit in mem.
BCLR OPTION,X $40 ; CSEL = 0 to select clock
LDX #60 ;Delay >100us for E=3MHZ or less
DLY100
DEX
BNE DLY100
PULX
RTS
INAD
LDX #BASE
LDAB #%00100001
STAB ADCTL,X ;start conversion
/* ;also clears CCF*/
/* ;wait for fist conversion done*/
ANALOOP
LDAB ADCTL,X /* poll for analog conversion*/
ANDB #$80
BEQ ANALOOP
LDAB ADR2,X ; load B with result
RTS
|
|
Message has 1 Reply: | | RE: Read A/D converter
|
| I didn't look that closely at your program but I have included a routine to read the analog ports that I know works. After assembling and loading the program, you make two c function calls: powerup_ad(); and read_ad(i); where i is the analog port (...) (26 years ago, 22-Oct-98, to lugnet.robotics.handyboard)
|
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|