|
|
View previous topic :: View next topic |
Author |
Message |
john.ma
Joined: 19 Nov 2012 Posts: 23
|
PIC24 Bit array equality testing |
Posted: Thu Nov 29, 2012 11:47 am |
|
|
Hi Guys,
Could someone confirm whether they're also getting the same output through MPSIM when using the below code? Testing for same bits returns false if referenced as array element :/
I tested this with version PCD 4.138
Code: |
#include <24fj128GA010.h>
#fuses NODEBUG // Debug Mode. 1.11 NODEBUG No Debug mode for ICD
#fuses HS,PR_PLL // Crystal HS, 4xPLL
#fuses NOIESO // No 2-speed Start Up
#fuses NOJTAG // No JTAG
#fuses NOPROTECT // No Memory Protection
#fuses NOWDT // No WatchDog Timer
#use delay(clock=32M, crystal=8M)
int outIndex, outDataSize=16, x, duration;
int1 outputData[] = { 1,0,0,1,1,0,1,0,1,0,1,0,1,0,0,0};
int1 temp3= 0, temp2=0, temp;
void main()
{
duration = 0;
outIndex = 0;
temp3 = outputData[outIndex];
temp2 = outputData[duration];
if(temp2 == outputData[outIndex])
x = 19; // doesnt work
if(outputData[outIndex] == outputData[duration])
x = 20; // doesnt work
if(temp2 == temp3)
x = 21; // works
if(temp3 == outputData[duration])
x = 22; // doesnt work
if(!(outputData[duration] ^ temp3))
x = 22; // works
// Does not compile. Error 84 Pointers to bits are not permitted
// Reodering terms resolves compiler error (?!)
//if(!(temp3 ^ outputData[duration))
// x = 22;
// Doesnt work.
for( duration=outIndex; temp3 == outputData[duration] ; duration++);
duration = (duration-outIndex);
// Works. Terms must be in that order otherwise compiler will raise error
for( duration=outIndex; !(outputData[duration] ^ temp3) ; duration++);
duration = (duration-outIndex);
}
|
Thanks |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Nov 30, 2012 4:08 am |
|
|
I don't have the PIC24 compiler, but from the release notes for 4.139 I noted this: Quote: | 4.139 Some packed structure problems have been fixed | You might give the new version a try... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Sun Dec 02, 2012 2:27 am |
|
|
This seems to relate to a long standing problem with PCD, and 'types'.
If you code, with 4.137:
Code: |
if(outputData[outIndex]==temp2)
x = 19;
//Versus
if(temp2 == outputData[outIndex])
x = 19; // doesnt work
|
The former correctly references the bit field, calling a subroutine to solve the value of the bit, while the latter does not.
If then you try:
Code: |
if((int8)temp2==(int8)outputData[outIndex])
x = 19;
|
This again forces the subroutine call, and works.
Same applies to the noted error about bitfields....
Code: |
if(!((int8)temp3 ^ (int8)outputData[duration]))
x = 22;
|
So:
Code: |
temp3 = outputData[outIndex];
//Works because though 'temp3' is an int1, in the expression on the right
//the compiler 'sees' the array as int8, and performs the access.
if(temp2==outputData[outIndex])
//Fails because the compiler tries to use 'int1' as the basic type, and this
//doesn't access the bit array correctly.....
if(temp2==(int8)outputData[outIndex])
//works again.....
//as does:
if(!(temp3 ^ (int8)outputData[duration]))
x = 22;
|
It appears you can make it always work, by preceding every point where you access a bit array, with an int8 cast.
It appears that in getting bit arrays to work, CCS have 'missed' a little bit in the type casting, with the code needed to correctly access the bits, only being called if the expression is using int8 or larger types, while the bit field returned is an int1. Hence if everything in the expression is int1, the access code fails....
The code still does the same, not using the bitfield access, unless you force use of int8, with 4.140.
Best Wishes |
|
|
john.ma
Joined: 19 Nov 2012 Posts: 23
|
|
Posted: Fri Dec 07, 2012 3:59 am |
|
|
Ttelmah,
If I could buy you a pint I would. Second time you've helped me :D
Much appreciated. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Fri Dec 07, 2012 9:37 am |
|
|
Glad it worked.
If no-one else has done so, I'll post a bug report to CCS. They might then fix this.
Best Wishes |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Mon Dec 10, 2012 3:21 pm |
|
|
FYI, CCS, have said this will be fixed in the next release.
Watch this space.
Best Wishes |
|
|
|
|
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
|