24 bits a 8 bits

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

I made a SPI communication between PSoC5 and a microconversor, the goal of my project is to display microconversor data on a PC . The problem with this is that the microconversor is 24-bit resolution and to send them to the PC I need to convert that data to a size 8-bit. 

   

Does anyone know how to do this in PSoC Creator 2.0 ?...

   

Regards,

   

Jeisson

0 Likes
13 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

double dataunk = 0;

   

 

   

lowbyte = dataunk & 0x0000FF;

   

midbyte = ( dataunk >> 8 ) & 0x0000FF;

   

highbyte = ( dataunk >> 16 ) & 0x0000FF;                      // & probably not needed, but to be safe.

   

 

   

The above could be done with an array and a for loop, I was just lazy.

   

 

   

You would reverse on receive side.

   

 

   

Or send as an ascii string, using sprintf() to convert to string, and convert back on PC side if you need

   

to use it as a numeric. If only to display just print it on PC side.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Or using the "union" statement

   

union TwentyFourToEightbit {

   

   BYTE EightBit[3];

   

   uint24 TwentyFour;

   

} MyUnion;

   

 

   

   MyUnion.TwentyFour = 0x112233;

   

   if (MyUnion.EightBit[0] != 0x11) Help();

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 for dana:

   

"double dataunk = 0;"

   

Is this double a double precision float type?

   

 

   

For Bob

   

it should be careful that the byte arrangement inide the union would be different with BIG or LITTLE Endian.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Interesting results -

   

 

   

//                                                                                         HiTech                   Imagcraft
 
//union TwentyFourToEightbit {                              // 385 ROM, 0 RAM     500 ROM, 2 RAM  
//
//  unsigned char EightBit[3];
//
//    unsigned long TwentyFour;
//
//} MyUnion;
//
//MyUnion.TwentyFour = 0x00112233;

   


 
//unsigned long dataunk = 0;                                  // 395 ROM, 0 RAM,    583 ROM, 4 RAM
//unsigned char lowbyte, midbyte, highbyte;
//
//lowbyte = dataunk & 0x000000FF;
//midbyte = ( dataunk >> 8 ) & 0x000000FF;
//highbyte = ( dataunk >> 16 ) & 0x000000FF;

   


 
//unsigned long yourval = 0x00112233;                // 399 ROM, 0 RAM     600 ROM, 4 RAM
//unsigned char dataunk[3], i;
//for(i = 0; i < 2; dataunk = yourval & 0x000000FF, yourval = yourval >> 8, i++ );
 

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You can sratch some more bytes when you use >>= and i++ within the index, but that's only marginal. The main point is, that a complete empty project without any code uses exactly 500 bytes for the boot, so the union-method uses the densest code. Give it a try and access the unit-members and check the code needed.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Empty Project

   

Imagcraft 479 bytes ROM,    2 Bytes RAM

   

HiTech    382 bytes ROM,    0 Bytes RAM

   

 

   

Of course this test over simplifies because I did not examine, in detail, what is and is

   

not being done in boot between the two compilers.

   

 

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

And as you may see from my last post the Designer 5.2 with latest boot.asm uses 500 bytes when there are no lines in main.c. So I presume you are using an earlier version. Or I have to check my optimization settings...

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 I have the Hi-tech pro version and it does provide smaller code. Too bad we can not have support from Hi-tech anymore. 😞

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

My current config of Designer -

   

 

   

Imagecraft Compiler Standard V7.05
PSoC Designer Content 5.2 (SP1) - Build 2551 - 02-March-2012.09:00:45
PSoC Designer Core 5.2 (SP1) - Build 2551 - 02-March-2012.09:00:45
PSoC Designer Documentation 5.2 (SP1) - Build 2551 - 07-March-2012.12:36:48

   

 

   

HiTech V9.61PL2

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Configuration -

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Hi guys,

   

totally appreciate your inputs (really do!) about Designer and the associated compilers. More people using these compilers would actually read it if it were in the Designer forum 😉

   

Cheers, Robert

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Yes, Robert, you are right, but when the thread was started we did not know where it would lead to. Startinig a second thread to display our results would have been of no use to clarify the topic. What exactly could we have done better? (within the limits of this forum-software)

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

@Robert-CY, I actually felt the performance measures I was posting were very

   

old news, re HiTech vs Imagcraft.

   

 

   

I made comments a long time ago in Designer tool on psocdeveloper.com about

   

the still significant code density HiTech yields. This becuse I have a project right

   

up against FLASH size limits.

   

 

   

Stay cool, because here it is hoter than Hades 🙂

   

 

   

Regards, Dana.

0 Likes