Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.design > #381124 > unrolled thread

OT: Reformatted update on table call problem

Started byRobert Baer <robertbaer@localnet.com>
First post2015-10-11 23:17 -0700
Last post2015-10-12 23:52 -0700
Articles 20 on this page of 39 — 6 participants

Back to article view | Back to sci.electronics.design


Contents

  OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-11 23:17 -0700
    Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-12 09:17 +0100
      Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:11 -0700
        Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-13 08:17 +0100
          Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-13 22:26 -0700
            Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-14 07:50 +0100
              Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-14 16:35 -0700
                Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-15 12:01 +0100
                  Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-15 22:41 -0700
                    Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-16 07:09 +0100
                      Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-16 08:50 +0100
                        Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-16 09:31 +0100
                          Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-17 21:34 -0700
                            Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-18 09:42 +0100
                              Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-19 09:12 +0100
                              Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-19 23:04 -0700
                      Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-17 21:08 -0700
                        Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-18 09:45 +0100
                          Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-19 23:08 -0700
                      Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-17 21:19 -0700
                        Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-18 09:50 +0100
                          Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-19 23:14 -0700
                  Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-17 21:03 -0700
                    Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-18 10:14 +0100
                      Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-19 23:31 -0700
                        Re: Reformatted update on table call problem "P E Schoen" <paul@pstech-inc.com> - 2015-10-20 20:30 -0400
                          Re: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-20 22:42 -0700
                            Re: Reformatted update on table call problem "P E Schoen" <paul@pstech-inc.com> - 2015-10-21 14:06 -0400
                              Re: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-23 21:01 -0700
                                Re: Reformatted update on table call problem "P E Schoen" <paul@pstech-inc.com> - 2015-10-24 01:08 -0400
                                  Re: Reformatted update on table call problem krw <krw@nowhere.com> - 2015-10-24 09:05 -0400
    Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-12 09:46 +0100
      Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-12 10:39 +0100
        Re: OT: Reformatted update on table call problem Martin Riddle <martin_ridd@verizon.net> - 2015-10-12 08:24 -0400
          Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:54 -0700
          Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:55 -0700
        Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:49 -0700
      Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:44 -0700
        Re: OT: Reformatted update on table call problem (OOPS!) Robert Baer <robertbaer@localnet.com> - 2015-10-12 23:52 -0700

Page 1 of 2  [1] 2  Next page →


#381124 — OT: Reformatted update on table call problem

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-11 23:17 -0700
SubjectOT: Reformatted update on table call problem
Message-ID<egISx.89569$s%4.86979@fx20.iad>
        LIST p=P16F648A
        #include P16F648A.inc
          ; Was P16F628A
        __CONFIG       _CP_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC & 
_LVP_OFF & _MCLRE_OFF & _BOREN_OFF
        __IDLOCS       0x0001

;                  VARIABLES
ptrlo       EQU         0x20    ; table pointer
ptrhi       EQU         0x21
COUNT1      EQU         0x22    ; delay counter
COUNT2      EQU         0x23
COUNT3      EQU         0x24
sSTATUS     EQU         0x25
sW          EQU         0x26
;
         ORG     0x0000
         GOTO    start
         GOTO    start
         GOTO    start
         GOTO    start
         ORG     0x0010
start:  ;**             setup I/O
; All pins have 10K in series with an LED to GND except OSC pins (and GND)

         CLRF    PORTB   ; Set all Port B pins to logic 0
         BSF     RB3,RB5 ; Bank 1 command comes next STATUS RP0 set
         CLRF    PORTB   ; sel all Port B pins as outputs
         BCF     RB3,RB5 ; Bank 0 command comes next STATUS RP0 clear

         CLRF    ptrlo   ; start offset pointers at zero
         CLRF    ptrhi

         CLRW
         MOVWF   PORTB   ; Port B to zero
         CALL    DELAY   ; "freeze" LEDs

         MOVLW   0xFF
         MOVWF   PORTB   ; Port B ones
         CALL    DELAY   ; "freeze" LEDs

repeat:
         INCF    ptrlo           ; next loc
         MOVF    ptrlo,W
         CALL    tab1    ;;*REMoving this, one sees 0x00 0xFF (counting)
                         ;  otherwise,one sees only repeating 0x00 0xFF
         MOVWF   PORTB   ; Port B from W
         CALL    DELAY   ; "freeze" LEDs
         GOTO    repeat
; ----------------------------------------------
DELAY   MOVWF   sW
     ;    MOVF    STATUS,W
     ;    MOVWF   sSTATUS
         CLRF    COUNT1
         CLRF    COUNT2
         MOVLW   d'45'  ; fudge for about 4 Sec delay
         MOVWF   COUNT3
LUPINR  DECFSZ  COUNT1
         GOTO    LUPINR
         DECFSZ  COUNT2
         GOTO    LUPINR
         DECFSZ  COUNT3
         GOTO    LUPINR
DEXIT: ; MOVF    sSTATUS,W
        ; MOVWF   STATUS
         MOVF    sW,W
         RETURN
; ---------------------------------------------- sine
         ORG             0x0100
tab1:
      ;;   RETLW   0x01    ;       [0]     t=0.7500        r=0.0000
         ADDWF  PCL,F
         RETLW   0x15    ;       [1]     t=0.7539        r=0.0240
         RETLW   0x14    ;       [2]     t=0.7578        r=0.0964
         RETLW   0x13    ;       [3]     t=0.7617        r=0.2173
         RETLW   0x12    ;       [4]     t=0.7656        r=0.3865

   Note the CALL tab1 does not work.
   Why?

[toc] | [next] | [standalone]


#381143

Frompiglet <erichpwagner@hotmail.com>
Date2015-10-12 09:17 +0100
Message-ID<mvfq7j$aak$1@dont-email.me>
In reply to#381124
On 12/10/2015 07:17, Robert Baer wrote:
>          ORG             0x0100
> tab1:
>       ;;   RETLW   0x01    ;       [0]     t=0.7500        r=0.0000
>          ADDWF  PCL,F
>          RETLW   0x15    ;       [1]     t=0.7539        r=0.0240
>          RETLW   0x14    ;       [2]     t=0.7578        r=0.0964
>          RETLW   0x13    ;       [3]     t=0.7617        r=0.2173
>          RETLW   0x12    ;       [4]     t=0.7656        r=0.3865
>
>    Note the CALL tab1 does not work.
>    Why?

Which part of the call does not work for you, the return of a value in W 
or the return of program flow?

Why not try something like this:
tab1:
	movlw 0x55 ; or other plainly visible pattern
	return

and then report back to the group.

Alternatively try simulating inside MPLAB without having to reflash any 
hardware at all.

piglet

[toc] | [prev] | [next] | [standalone]


#381276

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-12 19:11 -0700
Message-ID<BLZSx.10$VZ.6@fx05.iad>
In reply to#381143
piglet wrote:
> On 12/10/2015 07:17, Robert Baer wrote:
>> ORG 0x0100
>> tab1:
>> ;; RETLW 0x01 ; [0] t=0.7500 r=0.0000
>> ADDWF PCL,F
>> RETLW 0x15 ; [1] t=0.7539 r=0.0240
>> RETLW 0x14 ; [2] t=0.7578 r=0.0964
>> RETLW 0x13 ; [3] t=0.7617 r=0.2173
>> RETLW 0x12 ; [4] t=0.7656 r=0.3865
>>
>> Note the CALL tab1 does not work.
>> Why?
>
> Which part of the call does not work for you, the return of a value in W
> or the return of program flow?
* If the CALL is left in, i cannot determine _what_ the actual program 
flow *is* (see comment below).

>
> Why not try something like this:
> tab1:
> movlw 0x55 ; or other plainly visible pattern
> return
* That works.

>
> and then report back to the group.
>
> Alternatively try simulating inside MPLAB without having to reflash any
> hardware at all.
*  Emulators, simulators: can the PIC16F648A "work" with one of those, 
or must one use their "debug header" monster(about twice as long, 30% 
wider and 3-4 times taller) with a *different* interface to the PICkit3.
* I now (as of yesterday) have a new PCB that can physically accept that 
monster.
* That means i will have to learn how to use the simulator from scratch...

>
> piglet
   Note the commented lines in this snippet:
repeat:
         INCF    ptrlo           ; next loc
         MOVF    ptrlo,W
         CALL    tab1    ;;*REMoving this, one sees 0x00 0xFF (counting)
                         ;  otherwise,one sees only repeating 0x00 0xFF
         MOVWF   PORTB   ; Port B from W
         CALL    DELAY   ; "freeze" LEDs
         GOTO    repeat

   One sees it counting IF one REMoves the CALL (first detail comment).
   HOWEVER, all is lost if the CALL is left in; program acts as if a 
reset happens at the CALL (the repeating 0x00 0xFF).

[toc] | [prev] | [next] | [standalone]


#381307

FromMartin Brown <|||newspam|||@nezumi.demon.co.uk>
Date2015-10-13 08:17 +0100
Message-ID<mvib6j$1c3$1@speranza.aioe.org>
In reply to#381276
On 13/10/2015 03:11, Robert Baer wrote:
> piglet wrote:
>> On 12/10/2015 07:17, Robert Baer wrote:
>>> ORG 0x0100
>>> tab1:
>>> ;; RETLW 0x01 ; [0] t=0.7500 r=0.0000
>>> ADDWF PCL,F
>>> RETLW 0x15 ; [1] t=0.7539 r=0.0240
>>> RETLW 0x14 ; [2] t=0.7578 r=0.0964
>>> RETLW 0x13 ; [3] t=0.7617 r=0.2173
>>> RETLW 0x12 ; [4] t=0.7656 r=0.3865
>>>
>>> Note the CALL tab1 does not work.
>>> Why?
>>
>> Which part of the call does not work for you, the return of a value in W
>> or the return of program flow?

> * If the CALL is left in, i cannot determine _what_ the actual program
> flow *is* (see comment below).

You should be able to. You may not understand what you are seeing but 
your call with PCLATH=0 is the same as Call 0 which apart from leaving a 
return address on the stack is the same as a cold start.

>>
>> Why not try something like this:
>> tab1:
>> movlw 0x55 ; or other plainly visible pattern
>> return
> * That works.
>
>>
>> and then report back to the group.
>>
>> Alternatively try simulating inside MPLAB without having to reflash any
>> hardware at all.

> *  Emulators, simulators: can the PIC16F648A "work" with one of those,
> or must one use their "debug header" monster(about twice as long, 30%
> wider and 3-4 times taller) with a *different* interface to the PICkit3.

You run the entire code inside a PC with no physical hardware at all. It 
is a full software simulation with cycle counting and timing if you 
bother to tell it what the clock rate is.

> * I now (as of yesterday) have a new PCB that can physically accept that
> monster.
> * That means i will have to learn how to use the simulator from scratch...

The simulation doesn't require any hardware and is the method of choice 
for debugging errant code. Crash and burn isn't anything like as 
effective at finding minor errors (typically fence post mistakes).

>> piglet
>    Note the commented lines in this snippet:
> repeat:
>          INCF    ptrlo           ; next loc
>          MOVF    ptrlo,W
>          CALL    tab1    ;;*REMoving this, one sees 0x00 0xFF (counting)
>                          ;  otherwise,one sees only repeating 0x00 0xFF
>          MOVWF   PORTB   ; Port B from W
>          CALL    DELAY   ; "freeze" LEDs
>          GOTO    repeat
>
>    One sees it counting IF one REMoves the CALL (first detail comment).
>    HOWEVER, all is lost if the CALL is left in; program acts as if a
> reset happens at the CALL (the repeating 0x00 0xFF).

It is doing exactly what you told it to do nothing more nothing less.
It cannot guess your intentions.

-- 
Regards,
Martin Brown

[toc] | [prev] | [next] | [standalone]


#381458

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-13 22:26 -0700
Message-ID<5IlTx.51971$2s.12040@fx01.iad>
In reply to#381307
Martin Brown wrote:
> On 13/10/2015 03:11, Robert Baer wrote:
>> piglet wrote:
>>> On 12/10/2015 07:17, Robert Baer wrote:
>>>> ORG 0x0100
>>>> tab1:
>>>> ;; RETLW 0x01 ; [0] t=0.7500 r=0.0000
>>>> ADDWF PCL,F
>>>> RETLW 0x15 ; [1] t=0.7539 r=0.0240
>>>> RETLW 0x14 ; [2] t=0.7578 r=0.0964
>>>> RETLW 0x13 ; [3] t=0.7617 r=0.2173
>>>> RETLW 0x12 ; [4] t=0.7656 r=0.3865
>>>>
>>>> Note the CALL tab1 does not work.
>>>> Why?
>>>
>>> Which part of the call does not work for you, the return of a value in W
>>> or the return of program flow?
>
>> * If the CALL is left in, i cannot determine _what_ the actual program
>> flow *is* (see comment below).
>
> You should be able to. You may not understand what you are seeing but
> your call with PCLATH=0 is the same as Call 0 which apart from leaving a
> return address on the stack is the same as a cold start.
* I have proven that PCLATH is set by the CALL - in this case to 0x0100 
and not the zero that would conveniently explain the apparent reset/cold 
start.

>
>>>
>>> Why not try something like this:
>>> tab1:
>>> movlw 0x55 ; or other plainly visible pattern
>>> return
>> * That works.
>>
>>>
>>> and then report back to the group.
>>>
>>> Alternatively try simulating inside MPLAB without having to reflash any
>>> hardware at all.
>
>> * Emulators, simulators: can the PIC16F648A "work" with one of those,
>> or must one use their "debug header" monster(about twice as long, 30%
>> wider and 3-4 times taller) with a *different* interface to the PICkit3.
>
> You run the entire code inside a PC with no physical hardware at all. It
> is a full software simulation with cycle counting and timing if you
> bother to tell it what the clock rate is.
>
>> * I now (as of yesterday) have a new PCB that can physically accept that
>> monster.
>> * That means i will have to learn how to use the simulator from
>> scratch...
>
> The simulation doesn't require any hardware and is the method of choice
> for debugging errant code. Crash and burn isn't anything like as
> effective at finding minor errors (typically fence post mistakes).
>
>>> piglet
>> Note the commented lines in this snippet:
>> repeat:
>> INCF ptrlo ; next loc
>> MOVF ptrlo,W
>> CALL tab1 ;;*REMoving this, one sees 0x00 0xFF (counting)
>> ; otherwise,one sees only repeating 0x00 0xFF
>> MOVWF PORTB ; Port B from W
>> CALL DELAY ; "freeze" LEDs
>> GOTO repeat
>>
>> One sees it counting IF one REMoves the CALL (first detail comment).
>> HOWEVER, all is lost if the CALL is left in; program acts as if a
>> reset happens at the CALL (the repeating 0x00 0xFF).
>
> It is doing exactly what you told it to do nothing more nothing less.
> It cannot guess your intentions.
>

[toc] | [prev] | [next] | [standalone]


#381463

Frompiglet <erichpwagner@hotmail.com>
Date2015-10-14 07:50 +0100
Message-ID<mvktqt$5l2$1@dont-email.me>
In reply to#381458
On 14/10/2015 06:26, Robert Baer wrote:
> * I have proven that PCLATH is set by the CALL - in this case to 0x0100
> and not the zero that would conveniently explain the apparent reset/cold
> start.
>

Are you sure? Have you mixed up PCH and PCLATH.

What happens during a CALL is 11 bits of PC are loaded from the opcode 
(all of PCL and 3 low bits of PCH) and two bits from PCLATH go to PCH. 
During arith on pc then the arith changes 8 bits of PCL and all 5 bits 
of PCH are loaded from PCLATH. Neither arith nor CALL  writes or changes 
the value in PCLATH. Unless you restrict your table and code using it to 
the first 255 locations then PCLATH has to be written to by your code 
before doing the table lookup.

It is all in the chip datasheet.

piglet

[toc] | [prev] | [next] | [standalone]


#381549

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-14 16:35 -0700
Message-ID<2FBTx.1$Bl2.0@fx27.iad>
In reply to#381463
piglet wrote:
> On 14/10/2015 06:26, Robert Baer wrote:
>> * I have proven that PCLATH is set by the CALL - in this case to 0x0100
>> and not the zero that would conveniently explain the apparent reset/cold
>> start.
>>
>
> Are you sure? Have you mixed up PCH and PCLATH.
>
> What happens during a CALL is 11 bits of PC are loaded from the opcode
> (all of PCL and 3 low bits of PCH) and two bits from PCLATH go to PCH.
> During arith on pc then the arith changes 8 bits of PCL and all 5 bits
> of PCH are loaded from PCLATH. Neither arith nor CALL writes or changes
> the value in PCLATH. Unless you restrict your table and code using it to
> the first 255 locations then PCLATH has to be written to by your code
> before doing the table lookup.
>
> It is all in the chip datasheet.
>
> piglet
>
   Concerning "datasheets, here is a code snippet:
; ----------------------------------------------
; From AN556 page 3, EXAMPLE 4:
         org     0x02ff     ;Table located end of page 2
Table:
         addwf   PCL,F      ;value in pc will not roll over to page 3
         retlw   d'65'      ;NOTE assembler doesn't recognize 'A' etc..
         retlw   d'66'      ;     so assembler will crash.
         retlw   d'67'      ;     Therefore used decimal equivalent
; *Also discovered that PC _CAN_ indeed "rollover" to page 3, I modified the
;  code to show that fact thus:
;Table:   MOVF    PCLATH,W
;         CALL    DISPL   ; to show that CALL sets PCLATH (documentation
;                                does NOT state this fact).
;         MOVLW   0xA5
;         CALL    DISPL   ; use unique "marker"
;         GOTO    start   ; !!!     See 0x00 0xFF 0x02 0xA5 repeat (!!)

[toc] | [prev] | [next] | [standalone]


#381603

FromMartin Brown <|||newspam|||@nezumi.demon.co.uk>
Date2015-10-15 12:01 +0100
Message-ID<mvo12b$l30$1@speranza.aioe.org>
In reply to#381549
On 15/10/2015 00:35, Robert Baer wrote:
> piglet wrote:
>> On 14/10/2015 06:26, Robert Baer wrote:

>>> * I have proven that PCLATH is set by the CALL - in this case to 0x0100
>>> and not the zero that would conveniently explain the apparent reset/cold
>>> start.

Seems unlikely since it can only hold values in the range 0x00 to 0xff.

>> Are you sure? Have you mixed up PCH and PCLATH.
>>
>> What happens during a CALL is 11 bits of PC are loaded from the opcode
>> (all of PCL and 3 low bits of PCH) and two bits from PCLATH go to PCH.
>> During arith on pc then the arith changes 8 bits of PCL and all 5 bits
>> of PCH are loaded from PCLATH. Neither arith nor CALL writes or changes
>> the value in PCLATH. Unless you restrict your table and code using it to
>> the first 255 locations then PCLATH has to be written to by your code
>> before doing the table lookup.
>>
>> It is all in the chip datasheet.
>>
>> piglet
>>
>    Concerning "datasheets, here is a code snippet:
> ; ----------------------------------------------
> ; From AN556 page 3, EXAMPLE 4:
>          org     0x02ff     ;Table located end of page 2
> Table:
>          addwf   PCL,F      ;value in pc will not roll over to page 3
>          retlw   d'65'      ;NOTE assembler doesn't recognize 'A' etc..
>          retlw   d'66'      ;     so assembler will crash.
>          retlw   d'67'      ;     Therefore used decimal equivalent
> ; *Also discovered that PC _CAN_ indeed "rollover" to page 3, I modified
> the
> ;  code to show that fact thus:
> ;Table:   MOVF    PCLATH,W
> ;         CALL    DISPL   ; to show that CALL sets PCLATH (documentation
> ;                                does NOT state this fact).
> ;         MOVLW   0xA5
> ;         CALL    DISPL   ; use unique "marker"
> ;         GOTO    start   ; !!!     See 0x00 0xFF 0x02 0xA5 repeat (!!)

WTF don't you use the software PIC emulator and single step it?

Then you can watch all the registers and understand the thing properly.

You might find this page informative if you are still struggling:
http://pcbheaven.com/picpages/Program_Flow_Instructions/

The problem you are having is because PCL & PCH are both 8 bits wide 
whereas the CALL and GOTO locations are 11 bits and 2bits from PCLATH.

It is quite a nasty gotcha for the unwary. It is good practice to keep 
PCLATH pointed at the page where you intend to execute instructions.

-- 
Regards,
Martin Brown

[toc] | [prev] | [next] | [standalone]


#381741

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-15 22:41 -0700
Message-ID<g60Ux.30755$pi.6960@fx05.iad>
In reply to#381603
Martin Brown wrote:
> On 15/10/2015 00:35, Robert Baer wrote:
>> piglet wrote:
>>> On 14/10/2015 06:26, Robert Baer wrote:
>
>>>> * I have proven that PCLATH is set by the CALL - in this case to 0x0100
>>>> and not the zero that would conveniently explain the apparent
>>>> reset/cold
>>>> start.
>
> Seems unlikely since it can only hold values in the range 0x00 to 0xff.
>
>>> Are you sure? Have you mixed up PCH and PCLATH.
>>>
>>> What happens during a CALL is 11 bits of PC are loaded from the opcode
>>> (all of PCL and 3 low bits of PCH) and two bits from PCLATH go to PCH.
>>> During arith on pc then the arith changes 8 bits of PCL and all 5 bits
>>> of PCH are loaded from PCLATH. Neither arith nor CALL writes or changes
>>> the value in PCLATH.
* Not true; I have proven that PCLATH is indeed altered by a CALL.

  Unless you restrict your table and code using it to
>>> the first 255 locations then PCLATH has to be written to by your code
>>> before doing the table lookup.
* NOPE.

>>>
>>> It is all in the chip datasheet.
>>>
>>> piglet
>>>
>> Concerning "datasheets, here is a code snippet:
>> ; ----------------------------------------------
>> ; From AN556 page 3, EXAMPLE 4:
>> org 0x02ff ;Table located end of page 2
>> Table:
>> addwf PCL,F ;value in pc will not roll over to page 3
>> retlw d'65' ;NOTE assembler doesn't recognize 'A' etc..
>> retlw d'66' ; so assembler will crash.
>> retlw d'67' ; Therefore used decimal equivalent
>> ; *Also discovered that PC _CAN_ indeed "rollover" to page 3, I modified
>> the
>> ; code to show that fact thus:
>> ;Table: MOVF PCLATH,W
>> ; CALL DISPL ; to show that CALL sets PCLATH (documentation
>> ; does NOT state this fact).
>> ; MOVLW 0xA5
>> ; CALL DISPL ; use unique "marker"
>> ; GOTO start ; !!! See 0x00 0xFF 0x02 0xA5 repeat (!!)
>
> WTF don't you use the software PIC emulator and single step it?
>
> Then you can watch all the registers and understand the thing properly.
>
> You might find this page informative if you are still struggling:
> http://pcbheaven.com/picpages/Program_Flow_Instructions/
>
> The problem you are having is because PCL & PCH are both 8 bits wide
> whereas the CALL and GOTO locations are 11 bits and 2bits from PCLATH.
>
> It is quite a nasty gotcha for the unwary. It is good practice to keep
> PCLATH pointed at the page where you intend to execute instructions.
>
   What i have discovered about PCLATH with my LED display system is that
         ORG 0x00h
         BCF PCLATH, 4    ; <---\
         BSF PCLATH, 3    ; <----Try deleting these; it will still work
         GOTO Label_1_Far ; <-- and PCLATH will be set appropriately
         .
         .
         .
         ORG 0xA00h
Label_1_Far

   Granted that i have not tried this particular set of instructions 
(used a CALL instead), i have proven that the CALL (and *very* likely 
the GOTO) will set PCLATH to the new page, and further more, that 
instruction execution *WILL* roll-over (contrary to AN556).

   When i have the time, i will attempt simulation, and see how well it 
follows reality.

[toc] | [prev] | [next] | [standalone]


#381745

Frompiglet <erichpwagner@hotmail.com>
Date2015-10-16 07:09 +0100
Message-ID<mvq47l$l5e$1@dont-email.me>
In reply to#381741
On 16/10/2015 06:41, Robert Baer wrote:
>    What i have discovered about PCLATH with my LED display system is that
>          ORG 0x00h
>          BCF PCLATH, 4    ; <---\
>          BSF PCLATH, 3    ; <----Try deleting these; it will still work
>          GOTO Label_1_Far ; <-- and PCLATH will be set appropriately
>          .
>          .
>          .
>          ORG 0xA00h
> Label_1_Far
>
>    Granted that i have not tried this particular set of instructions
> (used a CALL instead), i have proven that the CALL (and *very* likely
> the GOTO) will set PCLATH to the new page, and further more, that
> instruction execution *WILL* roll-over (contrary to AN556).
>
>    When i have the time, i will attempt simulation, and see how well it
> follows reality.

I wonder whether you  have some assembler feature turned on that is 
generating extra code for page crossing jumps ? - have you looked at the 
disassembly listing to check it agrees with what you wrote?

What to mean by "roll over"? - Instruction execution will always 
roll-over, the pc is a 13 bit wide presettable up counter, the debate is 
about behavior during presetting.

piglet

[toc] | [prev] | [next] | [standalone]


#381756

FromMartin Brown <|||newspam|||@nezumi.demon.co.uk>
Date2015-10-16 08:50 +0100
Message-ID<mvqa95$e9m$2@speranza.aioe.org>
In reply to#381745
On 16/10/2015 07:09, piglet wrote:
> On 16/10/2015 06:41, Robert Baer wrote:
>>    What i have discovered about PCLATH with my LED display system is that
>>          ORG 0x00h
>>          BCF PCLATH, 4    ; <---\
>>          BSF PCLATH, 3    ; <----Try deleting these; it will still work
>>          GOTO Label_1_Far ; <-- and PCLATH will be set appropriately
>>          .
>>          .
>>          .
>>          ORG 0xA00h
>> Label_1_Far
>>
>>    Granted that i have not tried this particular set of instructions
>> (used a CALL instead), i have proven that the CALL (and *very* likely
>> the GOTO) will set PCLATH to the new page, and further more, that
>> instruction execution *WILL* roll-over (contrary to AN556).
>>
>>    When i have the time, i will attempt simulation, and see how well it
>> follows reality.
>
> I wonder whether you  have some assembler feature turned on that is
> generating extra code for page crossing jumps ? - have you looked at the
> disassembly listing to check it agrees with what you wrote?
>
> What to mean by "roll over"? - Instruction execution will always
> roll-over, the pc is a 13 bit wide presettable up counter, the debate is
> about behavior during presetting.
>
> piglet

I don't think he is smart enough to understand the difference :(

We are flogging a dead horse. I hope there isn't money riding on this.

-- 
Regards,
Martin Brown

[toc] | [prev] | [next] | [standalone]


#381758

Frompiglet <erichpwagner@hotmail.com>
Date2015-10-16 09:31 +0100
Message-ID<mvqchj$dmp$1@dont-email.me>
In reply to#381756
On 16/10/2015 08:50, Martin Brown wrote:
>
> We are flogging a dead horse. I hope there isn't money riding on this.
>

Spoilsport! I was looking forward to seeing Microchip forced into 
recalling a billion pic chips for having code installed that cheated on 
published specification.

piglet

[toc] | [prev] | [next] | [standalone]


#381934

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-17 21:34 -0700
Message-ID<njFUx.179459$2X5.3553@fx30.iad>
In reply to#381758
piglet wrote:
> On 16/10/2015 08:50, Martin Brown wrote:
>>
>> We are flogging a dead horse. I hope there isn't money riding on this.
>>
>
> Spoilsport! I was looking forward to seeing Microchip forced into
> recalling a billion pic chips for having code installed that cheated on
> published specification.
>
> piglet
   There has to be some kind of cheat WRT PCLATH, otherwise the 
following would definitely NOT work:
    ORG 0x100
    MOVLW	HIGH(TAB1)
    MOVWF	PCLATH   ; the program would NOT continue to the
			 ;   next line if PCLATH acted on/in next
			 ;   instruction cycle...
    MOVF		prtlo,W
    CALL		TAB1
;---
    ORG 0x0700
TAB1:
    MOVLW	HIGH(TAB1_DATA)
    ADDWF	ptrhi,W
    MOVWF	PCLATH
    MOVLW	LOW(TAB1_DATA)
    ADDWF	ptrlo,W
    BTFSC	STATUS,C
    INCF		PCLATH,F
    MOVWF	PCL,F
; ---
    ORG 0x0800
TAB1_DATA:
    RETLW 	...

[toc] | [prev] | [next] | [standalone]


#381948

Frompiglet <erichpwagner@hotmail.com>
Date2015-10-18 09:42 +0100
Message-ID<mvvltv$iq5$1@dont-email.me>
In reply to#381934
On 18/10/2015 05:34, Robert Baer wrote:

>     MOVLW    HIGH(TAB1)
>     MOVWF    PCLATH   ; the program would NOT continue to the
>               ;   next line if PCLATH acted on/in next
>               ;   instruction cycle...
>     MOVF        prtlo,W

You have confused PCH with PCLATH.

The program does continue to the next line because PCLATH is *not* the 
high part of the program counter. It is a latch that is only copied to 
the high part of the program counter in special conditions. Those are, a 
call, goto, or where pcl is the destination of an instruction.

Please read section 4.3 of the datasheet (page 30 DS40044G).

piglet

[toc] | [prev] | [next] | [standalone]


#382029

FromMartin Brown <|||newspam|||@nezumi.demon.co.uk>
Date2015-10-19 09:12 +0100
Message-ID<n028ko$gfm$1@speranza.aioe.org>
In reply to#381948
On 18/10/2015 09:42, piglet wrote:
> On 18/10/2015 05:34, Robert Baer wrote:
>
>>     MOVLW    HIGH(TAB1)
>>     MOVWF    PCLATH   ; the program would NOT continue to the
>>               ;   next line if PCLATH acted on/in next
>>               ;   instruction cycle...
>>     MOVF        prtlo,W
>
> You have confused PCH with PCLATH.
>
> The program does continue to the next line because PCLATH is *not* the
> high part of the program counter. It is a latch that is only copied to
> the high part of the program counter in special conditions. Those are, a
> call, goto, or where pcl is the destination of an instruction.
>
> Please read section 4.3 of the datasheet (page 30 DS40044G).

You can lead a horse to water but you can't make it think!

-- 
Regards,
Martin Brown

[toc] | [prev] | [next] | [standalone]


#382133

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-19 23:04 -0700
Message-ID<kPkVx.98475$iI3.57946@fx25.iad>
In reply to#381948
piglet wrote:
> On 18/10/2015 05:34, Robert Baer wrote:
>
>> MOVLW HIGH(TAB1)
>> MOVWF PCLATH ; the program would NOT continue to the
>> ; next line if PCLATH acted on/in next
>> ; instruction cycle...
>> MOVF prtlo,W
>
> You have confused PCH with PCLATH.
>
> The program does continue to the next line because PCLATH is *not* the
> high part of the program counter. It is a latch that is only copied to
> the high part of the program counter in special conditions. Those are, a
> call, goto, or where pcl is the destination of an instruction.
>
> Please read section 4.3 of the datasheet (page 30 DS40044G).
>
> piglet
>
   Thanks.

[toc] | [prev] | [next] | [standalone]


#381932

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-17 21:08 -0700
Message-ID<uXEUx.37027$os5.4374@fx14.iad>
In reply to#381745
piglet wrote:
> On 16/10/2015 06:41, Robert Baer wrote:
>> What i have discovered about PCLATH with my LED display system is that
>> ORG 0x00h
>> BCF PCLATH, 4 ; <---\
>> BSF PCLATH, 3 ; <----Try deleting these; it will still work
>> GOTO Label_1_Far ; <-- and PCLATH will be set appropriately
>> .
>> .
>> .
>> ORG 0xA00h
>> Label_1_Far
>>
>> Granted that i have not tried this particular set of instructions
>> (used a CALL instead), i have proven that the CALL (and *very* likely
>> the GOTO) will set PCLATH to the new page, and further more, that
>> instruction execution *WILL* roll-over (contrary to AN556).
>>
>> When i have the time, i will attempt simulation, and see how well it
>> follows reality.
>
> I wonder whether you have some assembler feature turned on that is
> generating extra code for page crossing jumps ? - have you looked at the
> disassembly listing to check it agrees with what you wrote?
>
> What to mean by "roll over"? - Instruction execution will always
> roll-over, the pc is a 13 bit wide presettable up counter, the debate is
> about behavior during presetting.
>
> piglet
>
   AN556, page 3 and I quote:
"The user either has to be cautious as to where in a page the Table 
resides or has to monitor page roll-over and add it to the PCLATH ahead 
of the computed GOTO."
   Does not that imply that rollover will not happen unless one diddles 
PCLATH?

[toc] | [prev] | [next] | [standalone]


#381949

Frompiglet <erichpwagner@hotmail.com>
Date2015-10-18 09:45 +0100
Message-ID<mvvm2k$iq5$2@dont-email.me>
In reply to#381932
On 18/10/2015 05:08, Robert Baer wrote:
>    AN556, page 3 and I quote:
> "The user either has to be cautious as to where in a page the Table
> resides or has to monitor page roll-over and add it to the PCLATH ahead
> of the computed GOTO."
>    Does not that imply that rollover will not happen unless one diddles
> PCLATH?
>

When they talk about rollover they refer to what happens after the 
arithmetic to PCL not to the normal incrementing of program counting 
that ocuurs after each instruction.

Please read section 4.3 of the datasheet (page 30 DS40044G).

piglet

[toc] | [prev] | [next] | [standalone]


#382134

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-19 23:08 -0700
Message-ID<mTkVx.161553$uZ5.62210@fx18.iad>
In reply to#381949
piglet wrote:
> On 18/10/2015 05:08, Robert Baer wrote:
>> AN556, page 3 and I quote:
>> "The user either has to be cautious as to where in a page the Table
>> resides or has to monitor page roll-over and add it to the PCLATH ahead
>> of the computed GOTO."
>> Does not that imply that rollover will not happen unless one diddles
>> PCLATH?
>>
>
> When they talk about rollover they refer to what happens after the
> arithmetic to PCL not to the normal incrementing of program counting
> that ocuurs after each instruction.
>
> Please read section 4.3 of the datasheet (page 30 DS40044G).
>
> piglet
>
   Still does not explain the AN556 error(s).

[toc] | [prev] | [next] | [standalone]


#381933

FromRobert Baer <robertbaer@localnet.com>
Date2015-10-17 21:19 -0700
Message-ID<15FUx.26195$Bl2.25051@fx27.iad>
In reply to#381745
piglet wrote:
> On 16/10/2015 06:41, Robert Baer wrote:
>> What i have discovered about PCLATH with my LED display system is that
>> ORG 0x00h
>> BCF PCLATH, 4 ; <---\
>> BSF PCLATH, 3 ; <----Try deleting these; it will still work
>> GOTO Label_1_Far ; <-- and PCLATH will be set appropriately
>> .
>> .
>> .
>> ORG 0xA00h
>> Label_1_Far
>>
>> Granted that i have not tried this particular set of instructions
>> (used a CALL instead), i have proven that the CALL (and *very* likely
>> the GOTO) will set PCLATH to the new page, and further more, that
>> instruction execution *WILL* roll-over (contrary to AN556).
>>
>> When i have the time, i will attempt simulation, and see how well it
>> follows reality.
>
> I wonder whether you have some assembler feature turned on that is
> generating extra code for page crossing jumps ? - have you looked at the
> disassembly listing to check it agrees with what you wrote?
>
> What to mean by "roll over"? - Instruction execution will always
> roll-over, the pc is a 13 bit wide presettable up counter, the debate is
> about behavior during presetting.
>
> piglet
>
   From ASM listing:
                       00038 ; From AN556 page 3, EXAMPLE 5:
0080                  00039         org     0x80 ;code location page 0
0080   3002           00040         movlw   HIGH Table
0081   008A           00041         movwf   PCLATH
                       00042 ;       movlw   ptrlo,F
MPASM  5.41                      AN556CHK.ASM   10-12-2015
LOC  OBJECT CODE     LINE SOURCE TEXT
   VALUE

                       00043
                       00044
0082   3020           00045         movlw   ptrlo
0083   22FF           00046         call    Table
0084   2086           00047         CALL    DISPL
                       00048 ; Does NOT work; see 0x00, 0xFF, 0xFF, 0xFF
0085   2810           00049         GOTO    start


                       00071 ; From AN556 page 3, EXAMPLE 4:
02FF                  00072         org     0x02ff ;Table, end of page 2
02FF   080A           00073 Table:  MOVF    PCLATH,W
0300   2086           00074         CALL    DISPL
0301   30A5           00075         MOVLW   0xA5
0302   2086           00076         CALL    DISPL
0303   2810           00077         GOTO    start
0304   0782           00078         addwf   PCL,F
0305   3441           00079         retlw   d'65'
0306   3442           00080         retlw   d'66'
0307   3443           00081         retlw   d'67'

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | sci.electronics.design


csiph-web