View previous topic :: View next topic |
Author |
Message |
jdboyer
Joined: 31 Jan 2005 Posts: 3
|
Can PCM compiler generate 16-bit wide bitfields? |
Posted: Mon Jan 31, 2005 9:03 am |
|
|
I am porting a project from another compiler. The code was originally written for a PIC18F6520, and now has to function on a PIC16C67.
There is a portion of the code that uses 16-bit wide bitfields:
Code: |
struct dacStruct {
int16 param1 : 2;
int16 param2 : 8;
int16 param3 : 3;
int16 param4 : 2;
int16 param5 : 1;
}
|
When I try to compile this structure, the compiler doesn't seem to like it. Since the structure straddles 8-bit boundries, I suppose this might be causing the error? Is this a known limitation of the CCS compiler?
Thanks! |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 31, 2005 10:32 am |
|
|
Code: |
struct dacStruct
{
int8 param1 : 2;
int8 param2;
int8 param3 : 3;
int8 param4 : 2;
int8 param5 : 1;
}test; |
This is more optimized:
Code: |
struct dacStruct
{
int8 param2;
int8 param1 : 2;
int8 param3 : 3;
int8 param4 : 2;
int8 param5 : 1;
}test; |
|
|
|
jdboyer
Joined: 31 Jan 2005 Posts: 3
|
|
Posted: Mon Jan 31, 2005 12:08 pm |
|
|
Mark wrote: | Code: |
struct dacStruct
{
int8 param1 : 2;
int8 param2;
int8 param3 : 3;
int8 param4 : 2;
int8 param5 : 1;
}test; |
This is more optimized:
Code: |
struct dacStruct
{
int8 param2;
int8 param1 : 2;
int8 param3 : 3;
int8 param4 : 2;
int8 param5 : 1;
}test; |
|
Well... I think I neglected to mention that this is a bitstream, so I can't re-organize the fields as you suggest, however, if indeed only 8-bit fields are allowed, I could probably just break it up as shown...
Code: |
struct dacStruct {
int8 param1 : 2;
int8 param2a : 6;
int8 param2b : 2;
int8 param3 : 3;
int8 param4 : 2;
int8 param5 : 1;
};
|
Then just write some code to patch param2a and param2b together. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Mon Jan 31, 2005 2:29 pm |
|
|
Look at Mark's first suggestion. He left the fields in the same order you were using them. His concern is that they don't map well to the RAM and so aren't efficient in RAM use. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 31, 2005 2:42 pm |
|
|
rwyoung wrote: | Look at Mark's first suggestion. He left the fields in the same order you were using them. His concern is that they don't map well to the RAM and so aren't efficient in RAM use. |
I believe that he has a 16bit word that he wants to access. The first example will actually use 3 bytes instead of 2 so it is probably not a good way to go. |
|
|
jdboyer
Joined: 31 Jan 2005 Posts: 3
|
|
Posted: Mon Jan 31, 2005 3:03 pm |
|
|
Mark wrote: | rwyoung wrote: | Look at Mark's first suggestion. He left the fields in the same order you were using them. His concern is that they don't map well to the RAM and so aren't efficient in RAM use. |
I believe that he has a 16bit word that he wants to access. The first example will actually use 3 bytes instead of 2 so it is probably not a good way to go. |
Yes, it is a serialized bit stream that comes in one of the ports (the stream comes from a serial TLV5608 DAC if you must know). The bitstream produced off of the part is a 16-bit value that enters the 16C67 serially and is stored as two adjacent bytes. The 16 bit value is split into a 4-bit address and a 10-bit (left justified) DAC value. The screwy thing about this part is the left justification of the data, thus the 2-bits of padding on the LSB of the word.
Like I said before, the PIC18 series and the compiler I used before (Microchip) does not have a problem with 16 bit wide bitfields. It appears that either the PIC16 or the CCS PCM compiler only operates in chunks of 8 bits at a time. Because the left justified data "straddles" the byte boundary, that is why I came across the problem in the first place.
The older code wanted to "union" the structure with a two byte memory location in order to quickly pull the data into another variable without much gyration in 'C' (yes, I realize that the assembly code for this operation could get ugly).
I think the only thing I'm left with is to pull out the pieces "param2a" and "param2b" and shift / OR them manually.
Thanks for your help. |
|
|
|