Published:2011/8/10 1:37:00 Author:Phyllis From:SeekIC
By Ron Coates
The 18Fxx2 series of processors have either 16 k or 32 k of Flash ROM. However, each program instruction takes at least one word (i.e., two bytes) so in terms of the number of lines of program code you could write, you are looking at a maximum of 8 k or 16 k. Consequently, in terms of programming, you can only ever address even numbered ROM locations.
If you look at the program memory window for a 16F series program, the program address increments by one for each line, i.e., 0000, 0001, 0002 etc. The same code in an 18F would produce a program where each line incremented by two; 0000, 0002, 0004 etc. This doesn’t matter in the normal course of events, but when we come to lookup tables, it does.
The whole of the ROM memory is completely linear and there are no problems with CALL or GOTO instructions, no matter what the length of the program.
Look up tables
One of the features of PIC processors which has come in for some criticism in the past has been that lookup tables of any reasonable length were difficult to implement.
One of the most useful features of the ’18 series is that you can write lookup tables of virtually any length that will fit in the amount of Flash ROM available.
It might be useful at this point to look in detail at the only way you could implement a look up table in the ’16 series.
This was called a ’computed goto’ by Microchip and required the programmer to prepare the lookup table as a subroutine starting with the command to add the value in the W register to the program counter. This was followed by a list of the values that were to be returned. To use the table you had to ensure that the value in W was the required table position before you called the subroutine. After the subroutine, the main program would have the looked up value in W.
The following example would return the maximum speed a driver should do in any intermediate gear. We will call the subroutine SPEED.
SPEED
ADDWF PCL
RETLW OxFF
RETLW OxOA
RETLW 0x20
RETLW 0x3C
RETLW 0x50
If the main program had the value of the gear (1, 2, 3 or 4) in W, then calling this subroutine would cause the program to jump to the line corresponding to the gear and return the maximum speed as a hex number. Note that the first line of the table corresponds to a value in W of zero. Since in this instance we would never have a value of zero, a dummy value (FF) is inserted.
The limitation of the above is that the value in W can only vary between 00 and FF (or 0 to 255 in decimal). And so you can only have 256 lines in the table. If you need a longer table that this, you have to split your table into 256 line chunks and use additional calculations to make sure you look up the right chunk. Clearly for values of several thousand, this is not practical.
The above method can still be used on the ’18 series and is still useful for short tables. However the situation is even worse now, as the program counter only recognizes even numbers. This means that whether W contains 0 or 1 makes no difference and the program will jump to the first line of the table (OxFF in the above example). For the program above to work properly with an 1 8F, you would need values of 2, 4, 6 and 8 in W. This also means that the maximum length of your table is now only 128.
If you need longer look up tables, you need to use an alternative method. This is described in detail in section 5 of the Data Sheet but these are general principles only. Any amount of the available Flash ROM can be used by the programmer as a lookup table (or series of lookup tables). So if we were using a chip with 32 k of ROM and we only needed 4 k For the program itself (remember this would be the equivalent of about two thousand lines of code), then 28 k would be available as look up table space.
This is a very significant step forward and may well mean that applications which previously used an external EPROM to store data can now become true ’single-chip’ applications with considerable savings in complexity, PCB size and, of course, cost.
There ore also larger 18F chips available with up to 128 k of ROM. Consult the Microchip website for the latest information on these.
Reprinted Url Of This Article: http://www.seekic.com/blog/project_solutions/2011/08/10/GOODBYE_'16_WELCOME_PIC18F__Part_2__ROM_(program_memory)_and_long_lookup_tables__(1).html
Print this Page | Comments | Reading(950)
Author:Ecco Reading(30162)
Author:Ecco Reading(3459)
Author:Ecco Reading(3180)
Author:Ecco Reading(3659)
Author:Ecco Reading(5230)
Author:Ecco Reading(3247)
Author:Ecco Reading(3388)
Author:Ecco Reading(3528)
Author:Ecco Reading(3934)
Author:Ecco Reading(3706)
Author:Ecco Reading(3676)
Author:Ecco Reading(3713)
Author:Ecco Reading(6026)
Author:Ecco Reading(3691)
Author:Ecco Reading(4477)