AnsweredAssumed Answered

HLP: sprintf corrupts the data....

Question asked by Venkatesh TK on Dec 1, 2009
Latest reply on Dec 2, 2009 by Venkatesh TK

/***********************/

Processor : MCF5485

IDE: CW-6.4 Build 6

/***********************/ 

 

Hi all,

 

I need a sprintf in my code to convert a float to string...

In my product there is an external interrupt every 6ms....

 

CASE1:

/***************************************************/

debugVarFloat - Array

sprintf

debugVarString - Array

/***************************************************/

 

In the above code if I observe the debugVar contents, I can see that the input is OK. But the output is corrupted sometimes....randomly.

 

 

CASE2:

/***************************************************/

debugVarFloat - Array

DISABLE_INTERRUPTS

sprintf

ENABLE_INTERRUPTS

debugVarString - Array

/***************************************************/

 In this case, both the input and output are OK. But execution of sprintf takes 10ms on my platform. So my board will not be able to respond to an external interrupt. THis is fatal to our system.

 

I tried to use the following alternatives:

1. vsnprintf - It took almost the same time as sprintf....

2. stringstreams - The same behavior was repeated...

 

 

Is there a faster way to convert a float to string?

Is there any way that I could make sprintf, corruption proof??

Please guide me through this...

 

Thanks and Regards,

Venki

Outcomes