CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Lookup table 12F675 - packing 12 bits into 14

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
john cutler



Joined: 06 Sep 2003
Posts: 82
Location: Hot Tub, California

View user's profile Send private message

Lookup table 12F675 - packing 12 bits into 14
PostPosted: Tue Jan 21, 2003 11:41 am     Reply with quote

I've seen some other posts about shrinking lookup tables in rom. I'm using a 12F675 (or maybe 676) with PCWH 3.136. I see in the Microchip data shee that the program memory is 14 bits wide. I'm trying to send 12 bit data to an SPI Multiplying DAC and am hoping to squeeze the 3 digit hex numbers into 14 bit space.

Since there's no CCS data type for 14 bits (or 12) can I use a struct - and then make a table of structs? The CCS manual says that

value = read_program_eeprom(addr) returns 16 bits for PCM and 8 bits for PCH. The 12F675 compiles under PCM, but onl has a 14 bit word.

I know I can always go to a wider PIC, but I'm trying to keep costs down.

All help gladly accepted!!

John
___________________________
This message was ported from CCS's old forum
Original Post ID: 10857
PCM programmer



Joined: 06 Sep 2003
Posts: 20336

View user's profile Send private message

Re: Lookup table 12F675 - packing 12 bits into 14
PostPosted: Tue Jan 21, 2003 2:43 pm     Reply with quote

:=I've seen some other posts about shrinking lookup tables in rom. I'm using a 12F675 (or maybe 676) with PCWH 3.136. I see in the Microchip data shee that the program memory is 14 bits wide. I'm trying to send 12 bit data to an SPI Multiplying DAC and am hoping to squeeze the 3 digit hex numbers into 14 bit space.
:=
:=Since there's no CCS data type for 14 bits (or 12) can I use a struct - and then make a table of structs? The CCS manual says that
:=
:=value = read_program_eeprom(addr) returns 16 bits for PCM and 8 bits for PCH. The 12F675 compiles under PCM, but onl has a 14 bit word.
-----------------------------------------------------------
The 12F675 does not have the ability to directly read its
program memory. Only some of the Flash PICs have this ability.

So with the 12F675, if you want to read program memory, you
have to encode the data in RETLW instructions. But then
you only get 8 bits per ROM location. The compiler will
create the RETLW instructions for you, as well as the access
code, if you use the const keyword.
For an example of how to do this, see the topic in the back of
the manual, "How can a constant data table be placed in ROM ?".
___________________________
This message was ported from CCS's old forum
Original Post ID: 10862
john cutler



Joined: 06 Sep 2003
Posts: 82
Location: Hot Tub, California

View user's profile Send private message

Re: Lookup table 12F675 - packing 12 bits into 14
PostPosted: Tue Jan 21, 2003 4:04 pm     Reply with quote

:=:=I've seen some other posts about shrinking lookup tables in rom. I'm using a 12F675 (or maybe 676) with PCWH 3.136. I see in the Microchip data shee that the program memory is 14 bits wide. I'm trying to send 12 bit data to an SPI Multiplying DAC and am hoping to squeeze the 3 digit hex numbers into 14 bit space.
:=:=
:=:=Since there's no CCS data type for 14 bits (or 12) can I use a struct - and then make a table of structs? The CCS manual says that
:=:=
:=:=value = read_program_eeprom(addr) returns 16 bits for PCM and 8 bits for PCH. The 12F675 compiles under PCM, but onl has a 14 bit word.
:=-----------------------------------------------------------
:=The 12F675 does not have the ability to directly read its
:=program memory. Only some of the Flash PICs have this ability.
:=
:=So with the 12F675, if you want to read program memory, you
:=have to encode the data in RETLW instructions. But then
:=you only get 8 bits per ROM location. The compiler will
:=create the RETLW instructions for you, as well as the access
:=code, if you use the const keyword.
:=For an example of how to do this, see the topic in the back of
:=the manual, "How can a constant data table be placed in ROM ?".
___________________________
This message was ported from CCS's old forum
Original Post ID: 10866
john cutler



Joined: 06 Sep 2003
Posts: 82
Location: Hot Tub, California

View user's profile Send private message

Re: Lookup table 12F675 - packing 12 bits into 14
PostPosted: Tue Jan 21, 2003 4:11 pm     Reply with quote

Thanks - I was afraid of that...Can I assume that a 16F87X would allow direct access, and if so, can I #ORG and #ROM the 12 bit values (as longs) into a consecutive table in program flash rom and then access them via value = read_program_eeprom ( addr) to recover a 16 bit value, and lose the first 4 bits, Sounds do-able to me - but then I haven't tried it yet :)

Thanks,

John

:=:=I've seen some other posts about shrinking lookup tables in rom. I'm using a 12F675 (or maybe 676) with PCWH 3.136. I see in the Microchip data shee that the program memory is 14 bits wide. I'm trying to send 12 bit data to an SPI Multiplying DAC and am hoping to squeeze the 3 digit hex numbers into 14 bit space.
:=:=
:=:=Since there's no CCS data type for 14 bits (or 12) can I use a struct - and then make a table of structs? The CCS manual says that
:=:=
:=:=value = read_program_eeprom(addr) returns 16 bits for PCM and 8 bits for PCH. The 12F675 compiles under PCM, but onl has a 14 bit word.
:=-----------------------------------------------------------
:=The 12F675 does not have the ability to directly read its
:=program memory. Only some of the Flash PICs have this ability.
:=
:=So with the 12F675, if you want to read program memory, you
:=have to encode the data in RETLW instructions. But then
:=you only get 8 bits per ROM location. The compiler will
:=create the RETLW instructions for you, as well as the access
:=code, if you use the const keyword.
:=For an example of how to do this, see the topic in the back of
:=the manual, "How can a constant data table be placed in ROM ?".
___________________________
This message was ported from CCS's old forum
Original Post ID: 10867
PCM programmer



Joined: 06 Sep 2003
Posts: 20336

View user's profile Send private message

Re: Lookup table 12F675 - packing 12 bits into 14
PostPosted: Tue Jan 21, 2003 4:32 pm     Reply with quote

:=Thanks - I was afraid of that...Can I assume that a 16F87X would allow direct access, and if so, can I #ORG and #ROM the 12 bit values (as longs) into a consecutive table in program flash rom and then access them via value = read_program_eeprom ( addr) to recover a 16 bit value, and lose the first 4 bits, Sounds do-able to me - but then I haven't tried it yet <img src="http://www.ccsinfo.com/pix/forum/smile.gif" border="0">
---------------------------------------------------------

Here is a demo program:

<PRE>
//-----------------------------------------------------------
// 877rom.c --
// This program tests the CCS functions which read and write
// from the program eeprom in a 16F877 chip.
<BR>
//-------------------------------------------------------------
// INCLUDE FILES
<BR>
#include "16F877.h"
<BR>
//-------------------------------------------------------------
// COMPILER DIRECTIVES
<BR>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(Clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
<BR>
#define DATA_START_ADDRESS 0x1800
#define NUM_DATA_WORDS 6
<BR>
// Reserve space for our data in ROM.
#org DATA_START_ADDRESS, DATA_START_ADDRESS + NUM_DATA_WORDS -1 {}
<BR>
// Put some sample data into ROM.
// We can store a 14-bit word in each ROM location.
#rom DATA_START_ADDRESS = {0x1555, 0x1234, 0x2AAA, 0x0000, 0x3FFF, 0x2999}
<BR>
//============================================================
main()
{
char i;
long address;
long value;
<BR>
address = DATA_START_ADDRESS;
<BR>
for(i = 0; i < NUM_DATA_WORDS; i++)
{
value = read_program_eeprom(address);
printf("\%lx\n\r", value);
address++;
}
printf("\n\r");
<BR>
while(1);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 10868
john cutler



Joined: 06 Sep 2003
Posts: 82
Location: Hot Tub, California

View user's profile Send private message

Re: Lookup table 12F675 - packing 12 bits into 14
PostPosted: Tue Jan 21, 2003 5:10 pm     Reply with quote

Thanks again!! is the read_program_eeprom() function very slow or long? - I guess I should get to work and do a list and see. The help you (and others) offer here is a godsend.

Jc
___________________________
This message was ported from CCS's old forum
Original Post ID: 10869
PCM programmer



Joined: 06 Sep 2003
Posts: 20336

View user's profile Send private message

Re: Lookup table 12F675 - packing 12 bits into 14
PostPosted: Tue Jan 21, 2003 5:47 pm     Reply with quote

:=Thanks again!! is the read_program_eeprom() function very slow or long? - I guess I should get to work and do a list and see. The help you (and others) offer here is a godsend.
:=
--------------------------------------------------
That function appears to take about 20 instructions in
the .LST file. The actual read operation is fast.
The 20 instructions are what takes up the time.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10871
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group