To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 3995
3994  |  3996
Subject: 
System interupt problems?
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Wed, 17 Jun 1998 22:11:04 GMT
Original-From: 
Timothy B. Gold <goldt@ee.byu.edu#ihatespam#>
Viewed: 
1172 times
  
I need some help! We have a handy board hooked up to some decoders,
which we will use to help track our robot as it moves across the floor.
We have to do a few pokes and a peek to read the decoders, but we've got
it all set up and it works beautifully if you do it manually.

  However, because the encoders have a very high resolution, we need to
constantly read the decoders so that their counters don't overflow and
wrap-around.  I figured that I'd write an assembly routine and have it
triggered by the system interrupt (TOC4) so that it is constantly
reading the decoders and keeping a total of how much they have changed.

  I successfully wrote an assembly routine that works just fine if it is
called from a C program.  To test it, I have a simple loop that runs the
motor forward and the backward (for a specified amount of time), calling
my assembly routine to update the value and the displaying the global
counter each time.

  However, if I take the EXACT same piece of code and link it in to the
TOC4 interrupt, it doesn't work correctly.  While before I read approx.
80 (forward) and -80 (reverse) for each turn of the motor, now it reads
approx. -6 (forward) and -1100 (reverse) for each turn.

  I'll attach the code I'm using below.  Does anyone have any ideas as
to what might be causing the problem?  Are there some other things going
on with the interrupt that I should be aware of?  I have tried slowing
it down a little (keeping a count and only reading the decoders once
every 200 TOC4 interrupts or so), but the results are identical.

  Any help would be appreciated -- this one's had me stumped all day and
I have't been making any progress with it.  Thanks!

----------------------------CODE:--------------------------------

/* Assembly routine(s) use to read the decoder
   and update a global counter. This piece of code
   will actually only read one decoder -- reading
   the other one will be added when this is debugged */

#include "/usr/local/ic/libs/6811regs.asm"

        ORG MAIN_START

variable_COUNT: /* this is the total count from the decoder */
FDB 00

variable_TCOUNT: /* this is used to store the value just read
    from the decoder */
FDB 00

subroutine_initialize_module:
#include "/usr/local/ic/libs/ldxibase.asm"

        ldd     TOC4INT,X
        std     interrupt_code_exit+1
        ldd     #interrupt_code_start
        std     TOC4INT,X
rts

/* This is the interrupt routine that doesn't work... */

interrupt_code_start:

ldd #$c
stab $4000 /* poke(0x4000,0x0c) -- latch internal decoder counter
              on ouput */
ldd #$1
stab $4000 /* poke (0x4000,0x01) -- pull reset for decoder high */
ldd #$d
stab $4000 /* poke (0x4000,0x0d) -- pull reset for decoder
       back down */
ldab $4000 /* peek (0x4000) -- get value from decoder */
clra       /* clear upper byte of variable */
tba        /* copy regb to rega */
anda #$80  /* check to see if number is negative */
cmpa #0
beq skip_pos /* skip ahead if number if positive */
ldaa #$ff    /* sign extend upper byte of count if negative */
skip_pos:
std variable_TCOUNT  /* store read value (from decoder) to TCOUNT */
ldd variable_COUNT   /* load count into double accum. */
addd variable_TCOUNT /* add TCOUNT to COUNT */
std variable_COUNT   /* store COUNT to memory */

interrupt_code_exit:
        jmp     $0000


/* This is the stand-alone routine that DOES work...
   (same piece of code, except for one changed label and
    an RTS at the end instead of a JMP) */

subroutine_mytest:

ldd #$c
stab $4000 /* poke(0x4000,0x0c) -- latch internal decoder counter
              on ouput */
ldd #$1
stab $4000 /* poke (0x4000,0x01) -- pull reset for decoder high */
ldd #$d
stab $4000 /* poke (0x4000,0x0d) -- pull reset for decoder
       back down */
ldab $4000 /* peek (0x4000) -- get value from decoder */
clra       /* clear upper byte of variable */
tba        /* copy regb to rega */
anda #$80  /* check to see if number is negative */
cmpa #0
beq skip   /* skip ahead if number if positive */
ldaa #$ff    /* sign extend upper byte of count if negative */
skip:
std variable_TCOUNT  /* store read value (from decoder) to TCOUNT */
ldd variable_COUNT   /* load count into double accum. */
addd variable_TCOUNT /* add TCOUNT to COUNT */
std variable_COUNT   /* store COUNT to memory */
rts



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR