Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

program memory usage need help

Status
Not open for further replies.

syenidogan

Member level 1
Member level 1
Joined
Mar 6, 2014
Messages
41
Helped
2
Reputation
4
Reaction score
3
Trophy points
8
Visit site
Activity points
297
without

sprintf(lcddata,"C.TEMP:%.02fC" ,dert);

Memory Summary:
Program space used 45Eh ( 1118) of 1000h words ( 27.3%)
Data space used 53h ( 83) of 170h bytes ( 22.6%)
EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
Configuration bits used 0h ( 0) of 2h words ( 0.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)

Loaded E:\pic_projeler\1 wire bus ds18b20\1wiresergu\1wire.cof.

********** Build successful! **********



with

sprintf(lcddata,"C.TEMP:%.02fC" ,dert);

Memory Summary:
Program space used F23h ( 3875) of 1000h words ( 94.6%)
Data space used 97h ( 151) of 170h bytes ( 41.0%)
EEPROM space used 0h ( 0) of 100h bytes ( 0.0%)
Configuration bits used 0h ( 0) of 2h words ( 0.0%)
ID Location space used 0h ( 0) of 4h bytes ( 0.0%)

Loaded E:\pic_projeler\1 wire bus ds18b20\1wiresergu\1wire.cof.

********** Build successful! **********

compiler is HI-TECH C Compiler for PIC10/12/16 MCUs (PRO Mode) V9.83

these are the output without and with sprintf. why program space usage are changing too much. (from %27.3 %to 94.6)
 

Code:
void FloatToString (float Value, char * String, char Accuracy)
{
	signed long k = 1;
	signed long tmp; 
	char Len;
	while (Accuracy--) k = k * 10;
	if (Value<0)	tmp = ((signed long)Value)*k - (float)(Value*k); 
		else tmp = (float)(Value*k) - ((signed long)Value)*k;
	sLongToStr((signed long)Value, String);
	Len = StringLen(String);
	String[Len++]='.';
	uLongToStr(tmp, String+Len);
}
Code:
signed long uLongTosLong (unsigned long Value)
{
	signed long Result;
	if ((Value)&(1<<30)) Result = - (0xFFFFFFFF - Value);
	else Result = Value;
	return Result;
}
Code:
void sLongToStr (signed long Value, char * String)
{
	unsigned long tmp;
	if (Value<0) 
	{
		Value=-Value;
		tmp=Value;
		*String++='-';
		uLongToStr(tmp, String+1);
	}
	else
	{
		tmp=Value;
		uLongToStr(tmp, String);
	}
}
 
The reason is 'sprintf' and it's associated functions are among the most memory hungry in the C library. It has lots of features you may not need to use so in a device with limited memory it is often better to use your own routines which can be optimized for only the features you use.

Brian.
 
it is often better to use your own routines which can be optimized for only the features you use

Another possibility would be test different compiler optimization levels to check if can reach some reduction of memory usage. In order to allow the program keep some level of portability to other uC cores, it is somewhat advisable to use the standard C libraries instead of direct access to special function registers.
 
Another possibility would be test different compiler optimization levels to check if can reach some reduction of memory usage. In order to allow the program keep some level of portability to other uC cores, it is somewhat advisable to use the standard C libraries instead of direct access to special function registers.

" it is somewhat advisable to use the standard C libraries instead of direct access to special function registers. "

what you mean by standart libraries ? what are they and where i can find them ?
what does accesing to special function registers mean ? what are they?

i know maybe these are basic question but it will help me if you can just give me one example for each.

- - - Updated - - -

Code:
void FloatToString (float Value, char * String, char Accuracy)
{
	signed long k = 1;
	signed long tmp; 
	char Len;
	while (Accuracy--) k = k * 10;
	if (Value<0)	tmp = ((signed long)Value)*k - (float)(Value*k); 
		else tmp = (float)(Value*k) - ((signed long)Value)*k;
	sLongToStr((signed long)Value, String);
	Len = StringLen(String);
	String[Len++]='.';
	uLongToStr(tmp, String+Len);
}
Code:
signed long uLongTosLong (unsigned long Value)
{
	signed long Result;
	if ((Value)&(1<<30)) Result = - (0xFFFFFFFF - Value);
	else Result = Value;
	return Result;
}
Code:
void sLongToStr (signed long Value, char * String)
{
	unsigned long tmp;
	if (Value<0) 
	{
		Value=-Value;
		tmp=Value;
		*String++='-';
		uLongToStr(tmp, String+1);
	}
	else
	{
		tmp=Value;
		uLongToStr(tmp, String);
	}
}
firstly thankx for helping.

what is the accuracy parameter in real you use in FloatToString function ? accuracy is .03 in 2.03 ? decimal accuracy i mean ?
also i didnt see the function uLongToStr u use in other functions? is it a function known by compiler or ?
 

2.03 accuracy 2
1.1 accuracy 1
3.1415 accuracy 4
just amount of digits after the dot
Code:
void uLongToStr (unsigned long Value, char * String)
{
  char zero=0;
  char tmp=0;
  unsigned long cnt=1000000000;
  while (cnt!=1)
  {
    while (Value>=cnt)
    {
      Value-=cnt;
      tmp++;
    }
    if (tmp) zero=1;
    if (zero) * String++ = tmp+48;
    tmp=0;
    cnt/=10;
  }
  * String = Value+48;
}
 
2.03 accuracy 2
1.1 accuracy 1
3.1415 accuracy 4
just amount of digits after the dot
Code:
void uLongToStr (unsigned long Value, char * String)
{
  char zero=0;
  char tmp=0;
  unsigned long cnt=1000000000;
  while (cnt!=1)
  {
    while (Value>=cnt)
    {
      Value-=cnt;
      tmp++;
    }
    if (tmp) zero=1;
    if (zero) * String++ = tmp+48;
    tmp=0;
    cnt/=10;
  }
  * String = Value+48;
}
it is working ty.
but,
it is not giving correct values between zero and minus one.
 

Try this:
Code:
void FloatToString (float Value, char * String, char Accuracy)
{
        signed long k = 1;
        signed long tmp;
        char Len, Len2, i=0;
        char AftDot[6];
        for (tmp = Accuracy; tmp; tmp--)  k *= 10;
        tmp = MOD(((signed long)Value)*k - Value*k);
        sLongToStr((int)Value, String);
        Len = StringLen(String);
        String[Len++]='.';
        sLongToStr(tmp, AftDot);
        Len2 =  StringLen(AftDot);

        while (Accuracy--)
        {
              if (Accuracy>=Len2) String[Len++] = '0';
              else String[Len++] = AftDot[i++];
        }
}
Code:
unsigned char StringLen (char * String)
{
        char cnt=0;
        while (* String++) cnt++;
        return cnt;
}
Code:
void sLongToStr (signed long Value, char * String)
{
        unsigned long tmp;
        if (Value<0) 
        {
                Value=-Value;
                tmp=Value;
                *String='-';
                uLongToStr(tmp, String+1);
        }
        else
        {
                tmp=Value;
                uLongToStr(tmp, String);
        }
}
Code:
void uLongToStr (unsigned long Value, char * String)
{
  char zero=0;
  char tmp=0;
  unsigned long cnt=1000000000;
  while (cnt!=1)
  {
    while (Value>=cnt)
    {
      Value-=cnt;
      tmp++;
    }
    if (tmp) zero=1;
    if (zero) * String++ = tmp+48;
    tmp=0;
    cnt/=10;
  }
  * String = Value+48;
}
 

Try this:
Code:
void FloatToString (float Value, char * String, char Accuracy)
{
        signed long k = 1;
        signed long tmp;
        char Len, Len2, i=0;
        char AftDot[6];
        for (tmp = Accuracy; tmp; tmp--)  k *= 10;
        tmp = MOD(((signed long)Value)*k - Value*k);
        sLongToStr((int)Value, String);
        Len = StringLen(String);
        String[Len++]='.';
        sLongToStr(tmp, AftDot);
        Len2 =  StringLen(AftDot);

        while (Accuracy--)
        {
              if (Accuracy>=Len2) String[Len++] = '0';
              else String[Len++] = AftDot[i++];
        }
}
Code:
unsigned char StringLen (char * String)
{
        char cnt=0;
        while (* String++) cnt++;
        return cnt;
}
Code:
void sLongToStr (signed long Value, char * String)
{
        unsigned long tmp;
        if (Value<0) 
        {
                Value=-Value;
                tmp=Value;
                *String='-';
                uLongToStr(tmp, String+1);
        }
        else
        {
                tmp=Value;
                uLongToStr(tmp, String);
        }
}
Code:
void uLongToStr (unsigned long Value, char * String)
{
  char zero=0;
  char tmp=0;
  unsigned long cnt=1000000000;
  while (cnt!=1)
  {
    while (Value>=cnt)
    {
      Value-=cnt;
      tmp++;
    }
    if (tmp) zero=1;
    if (zero) * String++ = tmp+48;
    tmp=0;
    cnt/=10;
  }
  * String = Value+48;
}

tmp = MOD(((signed long)Value)*k - Value*k); What is MOD?
 

Sorry, it just a module of value
Code:
unsigned long MOD (signed long Value)
{
        if (Value>0) return Value;
        else return -Value;
}
 

Sorry, it just a module of value
Code:
unsigned long MOD (signed long Value)
{
        if (Value>0) return Value;
        else return -Value;
}

tmp = MOD(((signed long)Value)*k - Value*k); What does the signed long before value does in this expression ?
 

type conversion ?

let say value is 3.023452 and let say accuracy is 2. (signed long)Value)*k what we are getting ? 302 or ?
what this expression giveus?
(((signed long)Value)*k - Value*k)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top