> 1 cycle shown in the section 29 instruction set of the Mid Range
> Reference manual
Yes... In general, it's true that ADDWF takes one cycle.
However, an ADDWF (or any other write instruction) with PCL as
its destination requires two cycles.
-Andy
=== Andrew Warren -- @spam@aiwKILLspamcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation
anyway is there any restriection in where this instruction can be use in
creating a jump table.
I know one of it is that the jump table should be with in 256 bytes(0x0000
to 0x0100) as by doing ADDWF PCL,F
we are doing a change at a max of 256.
i try the table on 0x0200 it does not work(16f876)
can any one enlighten me why?
And to make it even worse, in table 29-1 on page
29-3 in the same manual, there is a "note 3" that says
that "If the PCL is modified, the instruction takes 2 cycles".
*But* note 3 is only marked on the 4 skip instructions,
even if it is actualy valid for *any* instruction that
*could* modify the PCL...
> anyway is there any restriection in where this instruction
> can be use in creating a jump table.
> I know one of it is that the jump table should be with in 256
> bytes(0x0000 to 0x0100) as by doing ADDWF PCL,F
> we are doing a change at a max of 256.
> i try the table on 0x0200 it does not work(16f876)
> can any one enlighten me why?
Hi.
Download and read application note AN556 from Microchip.
The text does pretty well describes "table reades" with
"computed goto's", but the code examples has some errors,
so use them with care. :-)
Jan-Erik.
PS.
You seems to have a erratic shift key on your keyboard, it
doesn't work at the beginning of a new sentence...
That's because the addition to PCL is 8 bit and the high bits aren't
managed properly(16xx doesn't have 16 bit add command) you need to
increment PCLATH for the next section of the table (I only found this
out last weekend) There is a good worked example in the techref at
piclist.com. The basic understanding I got from the list (thanks David
and Jan-erik Olin and others) is that the addwf pcl is limited to 8 bits
but a direct goto is 11 bits and PCLATH 3,4 are the page bits. This
leaves bits 0-3 of PCLATH which need to be set according to the page
location on computed (addwf PCL,F)jump. Hence a table that starts at
0800h is called after setting PCLATH,3 to 1 and the continuation of the
table past 0900H requires a conditional incf PCLATH,f to continue the
table past the first 256b
Below is the example sent to me that helped lots and the link to the
techref I am no expert but the following code helped lots
Steve....
> That's because the addition to PCL is 8 bit and the high bits aren't
> managed properly(16xx doesn't have 16 bit add command) you need to
> increment PCLATH for the next section of the table (I only found this
> out last weekend) There is a good worked example in the techref at
> piclist.com. The basic understanding I got from the list (thanks David
> and Jan-erik Olin and others) is that the addwf pcl is limited to 8 bits
> but a direct goto is 11 bits and PCLATH 3,4 are the page bits. This
> leaves bits 0-3 of PCLATH which need to be set according to the page
> location on computed (addwf PCL,F)jump. Hence a table that starts at
> 0800h is called after setting PCLATH,3 to 1 and the continuation of the
> table past 0900H requires a conditional incf PCLATH,f to continue the
> table past the first 256b
<snip>
The easiest way to handle this is to make sure PCLATH is set right
before you perform the computed jump, THEN make sure that all possible
jumop-to locations are in the same page...The code is then trivial.
--Bob
--
--------------
Bob Axtell
PIC Hardware & Firmware Dev http://beam.to/baxtell
1-520-219-2363
> Hi every one,
>
> May I take the opportunity here to ask some question about PCL.
>
> 1) Is PCL post increased by PIC after execution of instruction, or is it
> increased before execution of instruction?
[ NOTE: My response here assumes a PIC12 or PIC16. Things are different on a
PIC18 ]
PCL is effectively incremented at the beginning of the instruction. Thus,
given the code:
MOVLW 0x00
ADDWF PCL,F
NOP
NOP
all four instructions will execute.
With this code:
MOVLW 1
ADDWF PCL,F
NOP
NOP
The first NOP will be skipped.
> 2) Is the following set of codes have the same effect on program flow?
>
> A1 MOVLW 0x00
> ADDWF PCL,f
>
> A2 GOTO A2
Because W is zero, the ADDWF PCL,F is effectively a NOP, so this will
execute the MOVLW, the ADDWF and then repeat the GOTO indefiniitely.
Because W is 0xFF, adding it to PCL will keep resetting PCL to point to the
ADDWF instruction. So, in this case the MOVLW will execute, and then the
ADDWF will be repeated indefinitely. The GOTO will never be reached.
[ NOTE: these explanations assume that the code involved does not span a 256
byte page boundary, and that PCLATH is properly set to point to the code
page.]
>> 2) Is the following set of codes have the same effect on program flow?
>>
>> A1 MOVLW 0x00
>> ADDWF PCL,f
>>
>> A2 GOTO A2
>
> Because W is zero, the ADDWF PCL,F is effectively a NOP, so this will
> execute the MOVLW, the ADDWF and then repeat the GOTO indefiniitely.
>> B1 MOVLW 0xFF
>> ....
>> ADDWF PCL,f
>> B2 GOTO $-1
>
> Because W is 0xFF, adding it to PCL will keep resetting PCL to point to
the
> ADDWF instruction. So, in this case the MOVLW will execute, and then the
> ADDWF will be repeated indefinitely. The GOTO will never be reached.
I have to apology here for not stated clearly my question. Actually I was
giving 4 pieces of codes and I was comparing A1 to A2, B1 to B2.
But I thinks I get the answers from your post anyway.
Thanks a lot.
WH Tan
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads
> 2) Is the following set of codes have the same effect on program flow?
>
> A1 MOVLW 0x00
> ADDWF PCL,f
>
> A2 GOTO A2
>
>
> B1 MOVLW 0xFF
> ....
> ADDWF PCL,f
>
> B2 GOTO $-1
I'm not sure what you are asking, but GOTO $-1 will go to the previous
instruction whereas A2 GOTO A2 will go to itself. The assembler "$" symbol
refers to the address of the current instruction.
*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
-- http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads