Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® Software > 24 bits a 8 bits

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



24 bits a 8 bits
Moderator:
JFMD

Post Reply
Follow this topic



24 bits a 8 bits

Jeisson Andres posted on 13 Jul 2012 5:17 PM PST
Member
6 Forum Posts

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




Re: 24 bits a 8 bits

danaaknight posted on 13 Jul 2012 06:35 PM PST
Top Contributor
1773 Forum Posts

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.



Re: 24 bits a 8 bits

Bob Marlowe posted on 14 Jul 2012 01:40 AM PST
Top Contributor
1768 Forum Posts

Or using the "union" statement

union TwentyFourToEightbit {

   BYTE EightBit[3];

   uint24 TwentyFour;

} MyUnion;

 

   MyUnion.TwentyFour = 0x112233;

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

 

Bob



Re: 24 bits a 8 bits

H L posted on 14 Jul 2012 07:28 AM PST
Top Contributor
679 Forum Posts

 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.

 

 

 



Re: 24 bits a 8 bits

danaaknight posted on 14 Jul 2012 08:27 AM PST
Top Contributor
1773 Forum Posts

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[i] = yourval & 0x000000FF, yourval = yourval >> 8, i++ );
 

 

Regards, Dana.



Re: 24 bits a 8 bits

Bob Marlowe posted on 14 Jul 2012 10:05 AM PST
Top Contributor
1768 Forum Posts

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



Re: 24 bits a 8 bits

danaaknight posted on 14 Jul 2012 06:47 PM PST
Top Contributor
1773 Forum Posts

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.



Re: 24 bits a 8 bits

Bob Marlowe posted on 15 Jul 2012 01:48 AM PST
Top Contributor
1768 Forum Posts

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



Re: 24 bits a 8 bits

H L posted on 15 Jul 2012 02:55 AM PST
Top Contributor
679 Forum Posts

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

 



Re: 24 bits a 8 bits

danaaknight posted on 15 Jul 2012 03:40 AM PST
Top Contributor
1773 Forum Posts

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.



Re: 24 bits a 8 bits

danaaknight posted on 15 Jul 2012 03:47 AM PST
Top Contributor
1773 Forum Posts

Configuration -

 

Regards, Dana.



Re: 24 bits a 8 bits

Robert-CY posted on 18 Jul 2012 02:43 PM PST
Cypress Employee
129 Forum Posts

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



Re: 24 bits a 8 bits

Bob Marlowe posted on 19 Jul 2012 11:03 PM PST
Top Contributor
1768 Forum Posts

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

 

 



Re: 24 bits a 8 bits

danaaknight posted on 19 Jul 2012 04:18 AM PST
Top Contributor
1773 Forum Posts

@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.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20