CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Float performance

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FMOpt2000



Joined: 10 Jan 2008
Posts: 17

View user's profile Send private message

Float performance
PostPosted: Wed Jan 25, 2012 9:42 am     Reply with quote

Hi,
I've a firmware on which I need to normalize some result.
The firmware has a polling structure and the float division use a lot of time.
I don't need a particular precision.

When the firmware starts, reads from EEPROM 2 values and I calculate
the "normalizzazione" variables (L=left,R=right).
During the polling, I do the float computation.

Is there a way to reduce the time computation in some way (reducing the precision)?

Here, part (incomplete) of firmware:
Code:

main()
{
    limit_foot_h_left=read_EEPROM(0x00);
    limit_foot_h_right=read_EEPROM(0x01);
    normalizzazione_L=((127-limit_foot_h_left)/100.0);
    normalizzazione_R=((limit_foot_h_right-127)/100.0);

while (1)
  {
   pot_lev_2=127-(127-pot_lev_2)/normalizzazione_L;
   }
}
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 25, 2012 10:40 am     Reply with quote

Quickest solution is to NOT use floats ! Really, just use simple int8 bit math as the data appears to be 8 bits anyway ?

Also consider /128 as opposed to /100.0 . That will shave a LOT of time off the 'math', though you may need to adjust the result.

Since we don't know the range or precision or accuracy required it's hard to guess which is better overall since the application is unknown to us.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Jan 25, 2012 4:33 pm     Reply with quote

Also note that multiplication is faster than division. If you can precalculate X=1/normalizzazione_L and then multiply by X when needed it will be faster.

But if there is ANY way to use long ints instead of floats it will be much faster.

consider:

pot_lev_2=127-(127-pot_lev_2) * Xnormint / 256;

where Xnormint is a precalculated 16 bit int.
_________________
The search for better is endless. Instead simply find very good and get the job done.
FMOpt2000



Joined: 10 Jan 2008
Posts: 17

View user's profile Send private message

PostPosted: Thu Jan 26, 2012 8:39 am     Reply with quote

Good,
I've improved a lot the polling rate, but in some cases
the RS232 is blocked by an over-rate.
Is there a way to reset/flush the buffer or port?
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 26, 2012 9:18 am     Reply with quote

you should have 'errors' added to the use rs232(....) options....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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