Searching \ for 'Program Counter over 255-What to do?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/timers.htm?key=count
Search entire site for: 'Program Counter over 255-What to do?'.

Truncated match.
PICList Thread
'Program Counter over 255-What to do?'
1998\05\26@001218 by PHXSYS

picon face
Hi everyone

In my program I am using the program counter to sequence several routines. I
am using it like this:

MOVF   SSTATE,W
MOVWF PCL

SSTATE is the address of the specific routine. My problem is SSTATE is an 8
bit value and my routine length goes over 255 addresses. When it goes over 255
it goes to the beginning of the program. I use the PAGE command before and
after routines, but it must be larger than a page.

I have to keep the code efficient because of the serial timing, I don't have
much room for additional code.

What are my options?

Is there an efficient way to make SSTATE a 16bit number and will that even
work? For example if SSTATE was at 355 would the program counter no where to
go?

Can I use a lookup table to provide any additional options? For example
offset the counter to GOTO's. I don't think I can do that.

Is there a way to utilize a lookdown table?

Any suggestions greatly appreciated.

Thanks in advance

Jon

1998\05\26@010328 by Regulus Berdin

flavicon
face
Try this:

       IF JUMP FOR ROUTINE0
               MOVLW 0
               MOVWF   SSTATE

       IF JUMP FOR ROUTINE1
               MOVLW 1
               MOVWF   SSTATE
       .
       .
       .

       IF JUMP FOR ROUTINE1
               MOVLW 1
               MOVWF   SSTATE

BRANCH:
       MOVF    SSTATE,W
       ADDWF   PCL
       GOTO    ROUTINE0
       GOTO    ROUTINE1
       .
       .
       .
       GOTO    ROUTINEX

Just preset values of SSTATE from 1 to X.


Reggie


----------
> From: PHXSYS <spam_OUTPHXSYSTakeThisOuTspamAOL.COM>
> To: .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU
> Subject: Program Counter over 255-What to do?
> Date: Tuesday, May 26, 1998 11:51 AM
>
> Hi everyone
>
> In my program I am using the program counter to sequence several
routines. I
> am using it like this:
>
> MOVF   SSTATE,W
> MOVWF PCL
>
> SSTATE is the address of the specific routine. My problem is SSTATE is an
8
> bit value and my routine length goes over 255 addresses. When it goes
over 255
> it goes to the beginning of the program. I use the PAGE command before
and
> after routines, but it must be larger than a page.
>
> I have to keep the code efficient because of the serial timing, I don't
have
> much room for additional code.
>
> What are my options?
>
> Is there an efficient way to make SSTATE a 16bit number and will that
even
> work? For example if SSTATE was at 355 would the program counter no where
to
{Quote hidden}

1998\05\26@013450 by Scott Dattalo

face
flavicon
face
> In my program I am using the program counter to sequence several routines. I
> am using it like this:
>
> MOVF   SSTATE,W
> MOVWF PCL

Recall that the lower 5 bits of 'PCLATH' are concatenated to PCL for a
computed goto such as this.

{Quote hidden}

You can do something like this:

       MOVF    SSTATE_HI,W     ;Get the high byte of the destination
       MOVWF   PCLATH          ;(actually only bits 0-4 are used)
       MOVF    SSTATE_LO,W     ;Get the low byte
       MOVWF   PCL             ;

However, if you know the destination bank AND it happens to be only one
bit different than the current bank, then you could get by with BSF/BCF's.

       BSF     PCLATH,0        ;Currently in bank 0, but we are about to
                               ;branch into bank 1
       MOVF    SSTATE,W        ;Get the low byte
       MOVWF   PCL             ;

Needless to say, you'll have to be extremely careful how the states are
grouped to avoid an inadvertent branch.

Scott

1998\05\26@071859 by Marco DI LEO

flavicon
face
PHXSYS wrote:
>
> Hi everyone
>
> In my program I am using the program counter to sequence several routines. I
> am using it like this:
>
> MOVF   SSTATE,W
> MOVWF PCL
>
> SSTATE is the address of the specific routine. My problem is SSTATE is an 8
> bit value and my routine length goes over 255 addresses. When it goes over 255
> it goes to the beginning of the program. I use the PAGE command before and
> after routines, but it must be larger than a page.

Yes, as I wrote in an answer to previous question you posted, if you
want to use this technique and your code extends over 256 memory
locations you have to play with PCLATH.

> I have to keep the code efficient because of the serial timing, I don't have
> much room for additional code.
>
> What are my options?
>
> Is there an efficient way to make SSTATE a 16bit number and will that even
> work? For example if SSTATE was at 355 would the program counter no where to
> go?

You can use two register for the SState value (i.e. SStateL and SStateH)
to hold a 16 bit number.

So, using the code fragment you posted in "MOVLW where the literal is a
label", the sequence:

>         movlw   Ckstrt          ; then make sure start bit persists**** LOOK H
ERE
>         movwf   SState
>         goto    w10
> ;
> Ckstrt  decfsz  STime,F  ; verify start bit by sampling at center **** LOOK HE
RE

becomes:

       movlw   high Ckstrt     ; Get the high addr of the 'Ckstrt'
routine
       movwf   SStateH         ; Store in high register
       movlw   low Ckstrt      ; Get the low address byte
       movwf   SStateL         ; Store in low register
       goto    w10
;
Ckstrt  decfsz  STime,F  ; verify start bit by sampling at center ****
LOOK HERE

Then, when your state machine has to call the appropriate routine use:

       movf        SStateH, W    ;Load the high byte of address
       movwf       PCLATH        ;Set the PCLATH register
       movf        SStateL, W    ;Load the low byte of the routine
address
       movwf       PCL           ;Jump to the routine at
SStateH:SStateL

> Can I use a lookup table to provide any additional options? For example
> offset the counter to GOTO's. I don't think I can do that.
>
> Is there a way to utilize a lookdown table?

Yes, you can also build a jump table and use an index rather than the
routine address for SState in a form like this:

       movlw   0          ; 0 stands for 'Ckstrt' (you can also use
#define's
       movwf   SState     ; to make your code more readable)
       goto    w10

Then to dispatch to the proper routine:

       movlw   high table ; Make sure PCLATH points to the current code
page
       movwf   PCLATH
       movf    SState,W   ; Get the index in the table
       addwf   PCL, F     ; Jump to the proper entry
table   goto    SState     ; Index 0
       goto    Getbit     ; Index 1
       goto    ...        ; Index ...

Ciao
 Marco

----
Marco DI LEO                  email: m.dileospamKILLspamsistinf.it
Sistemi Informativi S.p.A.    tel:   +39 6 50292 300
V. Elio Vittorini, 129        fax:   +39 6 5015991
I-00144 Roma                  web:   http://members.tripod.com/~mdileo/
Italy

1998\05\26@074954 by White Horse Design

flavicon
face
At 13:16 26/05/98 +0200, you wrote:
>PHXSYS wrote:
>>
>> Hi everyone
>>
>> In my program I am using the program counter to sequence several
routines. I
>> am using it like this:
>>
>> MOVF   SSTATE,W
>> MOVWF PCL
>>
>> SSTATE is the address of the specific routine. My problem is SSTATE is an 8
>> bit value and my routine length goes over 255 addresses. When it goes over

Are you saying you have over 255 different states? I can't see this as
there wouldn't be any room for your real code?!

Just use a jump table (as someone else mentioned) but if you don't have
more than 256 states you don't need more than a single byte SSTATE. (I'm
not too familiar with the 54 but am using the 74).

There's an example of how to use jump tables simply and more complicatedly
(for over a 2k page jump in the Microchip manual), also there are lots of
examples in the embedded application book (free from your local distie) and
also there are examples (app notes) on the CD and on the Microchip web
site. Have fun!


Regards

Adrian

WWW    WWW   Adrian Gothard
WWW WW WWW   White Horse Design
WWWWWWWWWW   +44-385-970009 (Mobile/SMS), +44-118-962-8913/4 (voice/fax)
WWWW  WWWW   .....whdKILLspamspam.....zetnet.co.uk, http://www.users.zetnet.co.uk/whd
---
Developers of GPS satellite-based tracking systems

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...