Jump to content
Sign in to follow this  
joli

24 Bit Data Type

Recommended Posts

Hi,

 

After a Boostc test period by modifying several apps maded in another compiler (very old) allready working in my costumers, i decided to adopt Boostc and use it for a new real project.

One of my needs for this particular project is, to have a 24 bit data type.

So, there is a way to define 24 bit data type variables ?

 

Another question is:

When i close/save my work to continue in the next day, when reopen it next day or several times in the same day, all work files opened in the edit area (right side) in the previous session, are closed. So, every time i have to open this files manually.

They are some missing IDE configuration to do that automatically ?

I mean: "When reopen one project all files opened in the previous session are reopened automatically"

 

Thanks

 

joli

Share this post


Link to post
Share on other sites
Hi,

 

After a Boostc test period by modifying several apps maded in another compiler (very old) allready working in my costumers, i decided to adopt Boostc and use it for a new real project.

One of my needs for this particular project is, to have a 24 bit data type.

So, there is a way to define 24 bit data type variables ?

 

Note: i know that before this project is sold, i have to change my actual FULL licence.

 

Another question is:

When i close/save my work to continue in the next day, when reopen it next day or several times in the same day, all work files opened in the edit area (right side) in the previous session, are closed. So, every time i have to open this files manually.

They are some missing IDE configuration to do that automatically ?

I mean: "When reopen one project all files opened in the previous session are reopened automatically"

 

Thanks

 

joli

Share this post


Link to post
Share on other sites
After a Boostc test period by modifying several apps maded in another compiler (very old) allready working in my costumers, i decided to adopt Boostc and use it for a new real project.

One of my needs for this particular project is, to have a 24 bit data type.

So, there is a way to define 24 bit data type variables ?

 

There are no built-in 24 bit data types. As far as we know there are no PIC compilers that have 24 bit data types.

 

Another question is:

When i close/save my work to continue in the next day, when reopen it next day or several times in the same day, all work files opened in the edit area (right side) in the previous session, are closed. So, every time i have to open this files manually.

They are some missing IDE configuration to do that automatically ?

I mean: "When reopen one project all files opened in the previous session are reopened automatically"

 

SourceBoost IDE does not reopen files that we open in previous session. We plan to add this feature eventually but this is a low priority item and it won't happen soon.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
There are no built-in 24 bit data types. As far as we know there are no PIC compilers that have 24 bit data types.
24 bit floats ??

 

Regards

Dave

Share this post


Link to post
Share on other sites
There are no built-in 24 bit data types. As far as we know there are no PIC compilers that have 24 bit data types.
24 bit floats ??

 

Regards

Dave

 

Some ADCs store the adc results (24bit) in signed 2s compliment format. The datas are usually sent out via SPI. In such case a it can be a little helpful if we could directly load the value into such data types.

 

Regards

Raghunathan.P

Share this post


Link to post
Share on other sites
There are no built-in 24 bit data types. As far as we know there are no PIC compilers that have 24 bit data types.
24 bit floats ??

 

Regards

Dave

 

Hi Dave,

No Dave, i mean 24 bit integer.

I know that no other compiler have it and i don't know why, because PIC as other little microcontrollers have so few resources.

 

Let me give an example that i have in hands:

 

Besides other things, not so few as you can think, my app have to mantain in memory the result of 16 counters with maximum capacity of 10000 (ten million), so i just need 24 bits (3 bytes).

For each counter i need two results, total and parcial results.

As i only can represent it by 32 bit vars, i need "2 x 16 x 4 = 128 bytes".

If i could use 24 bit variable, only needed "128 / 4 x 3 = 96 bytes".

Also all this data must be saved into a several external spi ram's (round buffer) for wich some pointer have to exist.

Also some time critical data have to exist in internal ram.

At the same time i have to mount/dismount packages for/from tx/rx with this counters info, besides other things.

The result will be some overhead and more unecessary code to save ram memory.

 

So, this is the reason i ask for.

 

Ok, someone will tellme i have to use some 18F or 24F pic. No thanks, i prefer PIC16F886 :)

 

Please consider my words as result of a bad day of work, and not a cricism of Boostc that by what i see until now, is very good.

 

Regards,

joli

Share this post


Link to post
Share on other sites
There are no built-in 24 bit data types. As far as we know there are no PIC compilers that have 24 bit data types.
24 bit floats ??

 

Regards

Dave

 

Some ADCs store the adc results (24bit) in signed 2s compliment format. The datas are usually sent out via SPI. In such case a it can be a little helpful if we could directly load the value into such data types.

 

Regards

Raghunathan.P

Hi ra68gi,

 

Agree, one more reason that make sense.

Maybe all C# compiler makers, think in terms of ansi c# that have 8, 16 and 32 bit data types.

In such cases as is my present case, we have to do it manually or even in assembly.

 

Regards,

joli

Share this post


Link to post
Share on other sites

Hi,

 

One time i have so many 24 bit data saved on the internal ram and conscious they are many ways to do this, let me show one that i wrote.

The only thing the code do for demo purposes, is to increment 24 bit value placed inside of one array, that can be any.

Of course in the real app, i need do addtional operations with this values.

The creation of arrays was a way to have and reserve ram space for 24 bit values (variables).

 

char parcnt1[3];					// Parcial count result (24 bit);
char acccnt1[3];					// Accumulated count result (24 bit);
char *aptr;						 // Pointer to array i want

// 32 bit ram memory but only 24 bit used
// This is a temporary space to work with a simple var
union					   
{
long temp32;					// 4th byte not used
struct
{
	char	templo;			 // Low byte	 |
	char	tempmid;			// Middle byte  | 24 bit space
	char	temphi;			 // High byte	|
}stemp;
}utemp;

////////////////////////////////////////////////////////////////////////////////
// Purpose: Copy array pointed by aptr to the temp struct
////////////////////////////////////////////////////////////////////////////////
void Copy2Temp( void )
{
utemp.stemp.templo = *aptr;
aptr++;
utemp.stemp.tempmid = *aptr;
aptr++;
utemp.stemp.temphi = *aptr;
aptr--;
aptr--;						 // Pointer back to the index 0
}

////////////////////////////////////////////////////////////////////////////////
// Purpose: Update array with temp struct contents
////////////////////////////////////////////////////////////////////////////////
void CounterUpd( void )
{
*aptr = utemp.stemp.templo;
aptr++;
*aptr = utemp.stemp.tempmid;
aptr++;
*aptr = utemp.stemp.temphi;
}

////////////////////////////////////////////////////////////////////////////////
// Purpose: Increment value inside of temp struct
////////////////////////////////////////////////////////////////////////////////
char CounterInc( void )
{
Copy2Temp();					// First copy my array to temp struct
utemp.temp32++;				 // Increment value
CounterUpd();				   // Update my array
}

void main( void )
{
parcnt1[0] = 0xFF;			  // this is array i want work on
parcnt1[1] = 0x20;			  // so i assign 0x3020ff
parcnt1[2] = 0x30;
aptr = &parcnt1[0];			 // aptr point to my array
CounterInc();				   // Increment value
}

 

The objective of this code is to avoid as can as possible repetive code and by other hand to have universal functions to do what i have to do and finally to save ram space.

Of course if had 24 bit vars the code seing in the main() would be so:

 

var24bit parcnt1; // where "var24bit" would be 24 bit type as "long" is 32 bit type

void main( void )

{

parcnt1++;

}

That's it

 

Please feel free to advise about simplest ways.

 

regards,

joli

Edited by joli

Share this post


Link to post
Share on other sites
After a Boostc test period by modifying several apps maded in another compiler (very old) allready working in my costumers, i decided to adopt Boostc and use it for a new real project.

One of my needs for this particular project is, to have a 24 bit data type.

So, there is a way to define 24 bit data type variables ?

 

There are no built-in 24 bit data types. As far as we know there are no PIC compilers that have 24 bit data types.

 

Another question is:

When i close/save my work to continue in the next day, when reopen it next day or several times in the same day, all work files opened in the edit area (right side) in the previous session, are closed. So, every time i have to open this files manually.

They are some missing IDE configuration to do that automatically ?

I mean: "When reopen one project all files opened in the previous session are reopened automatically"

 

SourceBoost IDE does not reopen files that we open in previous session. We plan to add this feature eventually but this is a low priority item and it won't happen soon.

 

Regards,

Pavel

 

All compilers from Knudsen Data (CC5X , CC8E , CC7A and CC1B - first 3 products for PIC , the last for SX) have the bit type + signed and unsigned types of 8 , 16 , 24 and 32 bit data , in addition it has 16 , 24 , 32 bit float types - and math lib's for it all.

 

You can find him here : http://www.bknd.com

 

You guys should join forces , that would give one hell of a product.

 

Kind regards Henrik

Share this post


Link to post
Share on other sites
All compilers from Knudsen Data (CC5X , CC8E , CC7A and CC1B - first 3 products for PIC , the last for SX) have the bit type + signed and unsigned types of 8 , 16 , 24 and 32 bit data , in addition it has 16 , 24 , 32 bit float types - and math lib's for it all.

 

You can find him here : http://www.bknd.com

 

You guys should join forces , that would give one hell of a product.

 

Kind regards Henrik

Hi Henrik,

 

I already knew this compiler, the question is when i look at him couple years ago, it had some anoying limitations that as i can see minuts ago, longer exist.

url you post haven't any forum. Can you tell me more about it?

By the way, may be isn't correct talk about this in this forum, at least i don't feel confortable, so if you want tell me where whe can procced in another forum or maybe be e-mail, please do.

 

One word to David and Pavel: Sorry about that and thank you for your understanding.

 

Regards,

joli

Share this post


Link to post
Share on other sites

Back to post #8,

 

After doing some tests and see code results, i concluded that for the compiler point of view, more eficient code is generated if use array index instead of pointers.

This situation have to do with FSR, INDF PIC mechanisms manipulation.

I recall that the objective is to have a long collection of 24 bits variables, because boostc doesn't support this type, having in account RAM limitations.

So the idea is to have this colection organized as follows:

parcnt[0] \

parcnt[1] | 1st 24 bit var

parcnt[2] /

 

parcnt[3] \

parcnt[4] | 2nd 24 bit var

parcnt[5] /

 

... and so on...

 

the same to acucnt[]

 

I made some adjusts in the struct using typedef in way to get a more readable code, as suggested by a friend in this forum (good trick).

typedef union
{
ulong	   var32bit;
struct
{
	uchar   templo;
	uchar   tempmid;
	uchar   temphi;
}stmp24;
}UTMP;

UTMP utmp;
#define temp32  utmp.var32bit
#define templo  utmp.stmp24.templo
#define tempmid utmp.stmp24.tempmid
#define temphi  utmp.stmp24.temphi

unsigned char ix;
void main( void )
{
parcnt1[0] = 0xFF;			  // this is 24 bit var part of array i want work on
parcnt1[1] = 0x20;
parcnt1[2] = 0x30;
CounterInc( 1 );				   // Function call to Increment value
}

 

Of course the functios have to reflect this changes:

 

char IncCounter( uchar cntindex )
{
ix = (cntindex-1)*3;	// Adjust index to appropriate place
// Copy array number into temp buffer
templo = buff24bit[ix++];
tempmid = buff24bit[ix++];
temphi = buff24bit[ix++];
temp32++;					   // Increment value inside of 32 bit var
aix-=3;						 // Reajdust array index
buff24bit[ix++] = templo;	  // copy back incremented value
buff24bit[ix++] = tempmid;
buff24bit[ix++] = temphi;
}

 

Instead of proposed in post #8, now only one function do everthing:

- Copy 3 byte array indexed by passed parameter, originaly loaded with 0x3020FF.

- Increment 24 bit inside of temp32 that is a 32 bit variable, result is 0x302100.

- Copy back to the array, the temp32 result.

 

As reg68gi said about get 24 bit value from spi, in the function IncCounter() instead of temp32++, we can have:

temp32 << 1;

temp32.BIT0 = SPIBIT;

Of course, if we talk about few variables, is preferable use 32 bit vars even with the waste of one byte by each.

 

The objective of this is to see if some one have an more simple way to do this job.

 

Regards,

joli

Share this post


Link to post
Share on other sites
As reg68gi said about get 24 bit value from spi, in the function IncCounter() instead of temp32++, we can have:

temp32 << 1;

temp32.BIT0 = SPIBIT;

Of course, if we talk about few variables, is preferable use 32 bit vars even with the waste of one byte by each.

 

The objective of this is to see if some one have an more simple way to do this job.

 

Regards,

joli

 

Hi Joli, acquiring 24bit signed data & storing it in 32bit signed can be a bit confusing. My approach is like this.. First I test if its MSB(24bit signed) is a 1.

If its 1 then its a signed data. I store the rest of the bits in our normal 32bit(long) unsigned type. Then on the long data I do a 2's compiliment. finally to

get the signed 32 bit data, I multiply it with -1. Here is an example done on 18bits of data. The rest of the adc bits where purposefully truncated.

u can modify the code for 24bit signed.

unsigned long adc_counter, adc_counter1;
signed long adc_buff1;

   if(adc_digit_sign_flag==1)			  //If the MSB of the 24bit signed data is a 1 then..do 2's compliments.
	{
	  adc_counter1 = adc_counter;
	  adc_counter1 = ~ adc_counter1;  // 1's compliment.
	  adc_counter1 = adc_counter1 & 0x003FFFF; // 0x003ffff;0b00000000000000111111111111111111;rest of the bits other than the bits we use must be 
																	  // forced to zero.
	  adc_counter1 += 1;	   // 2's compliment.						  
	 }

   if( adc_digit_sign_flag == 1)	// set a flag for MSB of the 24bit signed data. convert it into 32bit signed l_adc_buff1 if the flag is 1.
	  {
		adc_buff1 = (-1)* adc_counter1;
	  }

I hope the above code can help u come out with a method of storing 24bit signed data.

Regards

Raghunathan.P

Share this post


Link to post
Share on other sites

Hi Raghunathan.P

 

I hope the above code can help u come out with a method of storing 24bit signed data.

Regards

Raghunathan.P

 

Thank you by your reply.

Perhaps i haven't explained properly, but i never mentioned "signed data".

Original post have to do with the Boostc 24 bit data type lack.

 

Imagine you have 24 engines for which you have to keep the number of laps that each has until now.

I have to count to 10 million (10,000,000). To represent this number 3 simple bytes enough

 

1. My job is to keep 24 variables with 3 byte each (24 x 3 = 72 bytes) that should fit on a single ram page.

2. Each PIC16F886 Page1, 2 or 3 have 80 bytes and pages 0, 2 and 3 are already full.

3. So i only have page 1.

4. I should be able to update those 24 variables adding any value, 1, 2, 10 whatever, but always positive values.

 

Example below shows how data is placed in ram

			---------
RAM ADDR+0 |   LSB   |<-|
		---------   |
RAM ADDR+1 |   MID   |<-| 24 bit Counter number 1
		---------   |
RAM ADDR+2 |   LSB   |<-|
		---------   
		---------
RAM ADDR+3 |   LSB   |<-|
		---------   |
RAM ADDR+4 |   MID   |<-| 24 bit Counter number 2
		---------   |
RAM ADDR+5 |   LSB   |<-|
		---------   
			-
And so on, until an total of 24 Counters with 3 bytes each (24 bits).

As Boostc doesn't have 24 bit data types, but only 8, 16 and 32 bit, how to do what i need within 80 byte limitation?

 

Now, picking your example, can you explain to me what it do?

 

Regards,

joli

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×