Sign in

username:

password:



Not a member?

Search msp430



Search tips

Subscribe to msp430



Ads

Discussion Groups

Discussion Groups | MSP430 | Why does int work but not float?

The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.

Why does int work but not float? - mpbwork - Aug 1 14:04:44 2008

I use sprintf to fill a character array then send it to a LCD.
It works with int but not float
same for printf and the i/o window in IAR
Any ideas?
in the declerations i made
static long a2dresult,temptest;
float datafloat;

if (present)
{
//sprintf(TxData3," S%d= %ld
uV ",sensor2+1,a2dresult);
// the above line works (when not commented out) and
displays "S1= 250465 uV"
datafloat = a2dresult * .001; // eg was 250465uV int, now
250.465mV float
sprintf(TxData3," S%d= %9.2f mV",sensor2+1,datafloat); //mV +
decimal so float
// the above line does not and displays "S1= 9.2f mV"
// I don't see anything wrong. Any ideas?
}

printf(" S%d= %9.2f mV\n",sensor2+1,datafloat); //also wrong in io
debug window
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )


Re: Why does int work but not float? - michelqv - Aug 3 8:19:07 2008

Sometimes, you have to explicitly enable support for floats in
sprintf, because sprintf is usually a memory hog, especially for
floats. Not sure what the default is for IAR.

--- In m...@yahoogroups.com, "mpbwork" wrote:
>
> I use sprintf to fill a character array then send it to a LCD.
> It works with int but not float
> same for printf and the i/o window in IAR
> Any ideas?
> in the declerations i made
> static long a2dresult,temptest;
> float datafloat;
>
> if (present)
> {
> //sprintf(TxData3," S%d= %ld
> uV ",sensor2+1,a2dresult);
> // the above line works (when not commented out) and
> displays "S1= 250465 uV"
> datafloat = a2dresult * .001; // eg was 250465uV int, now
> 250.465mV float
> sprintf(TxData3," S%d= %9.2f mV",sensor2+1,datafloat); //mV +
> decimal so float
> // the above line does not and displays "S1= 9.2f mV"
> // I don't see anything wrong. Any ideas?
> }
>
> printf(" S%d= %9.2f mV\n",sensor2+1,datafloat); //also wrong in
io
> debug window
>

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Why does int work but not float? - Anders Lindgren - Aug 4 4:48:05 2008

mpbwork wrote:
> I use sprintf to fill a character array then send it to a LCD.
> It works with int but not float
> same for printf and the i/o window in IAR
> Any ideas?
> in the declerations i made
>
> static long a2dresult,temptest;
> float datafloat;
>
> if (present)
> {
> //sprintf(TxData3," S%d= %ld
> uV ",sensor2+1,a2dresult);
> // the above line works (when not commented out) and
> displays "S1= 250465 uV"
>
> datafloat = a2dresult * .001; // eg was 250465uV int, now
> 250.465mV float
> sprintf(TxData3," S%d= %9.2f mV",sensor2+1,datafloat); //mV +
> decimal so float
> // the above line does not and displays "S1= 9.2f mV"
> // I don't see anything wrong. Any ideas?
> }
>
> printf(" S%d= %9.2f mV\n",sensor2+1,datafloat); //also wrong in io
> debug window

Hi Mpb!

The IAR libraries contain a number of different "printf" formatters, you
need to use the large variant to get support for printing floating-point
numbers. See the Options->General Options->Library Options->Printf
formatter.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Why does int work but not float? - mpbwork - Aug 5 9:34:24 2008

--- In m...@yahoogroups.com, Anders Lindgren
wrote:
>
> mpbwork wrote:
> > I use sprintf to fill a character array then send it to a LCD.
> > It works with int but not float
> > same for printf and the i/o window in IAR
> > Any ideas?
> > in the declerations i made
> >
> > static long a2dresult,temptest;
> > float datafloat;
> >
> > if (present)
> > {
> > //sprintf(TxData3," S%d= %ld
> > uV ",sensor2+1,a2dresult);
> > // the above line works (when not commented out) and
> > displays "S1= 250465 uV"
> >
> > datafloat = a2dresult * .001; // eg was 250465uV int, now
> > 250.465mV float
> > sprintf(TxData3," S%d= %9.2f mV",sensor2+1,datafloat); //mV +
> > decimal so float
> > // the above line does not and displays "S1= 9.2f mV"
> > // I don't see anything wrong. Any ideas?
> > }
> >
> > printf(" S%d= %9.2f mV\n",sensor2+1,datafloat); //also wrong in io
> > debug window
>
> Hi Mpb!
>
> The IAR libraries contain a number of different "printf"
formatters, you
> need to use the large variant to get support for printing floating-
point
> numbers. See the Options->General Options->Library Options->Printf
> formatter.
>
> -- Anders Lindgren, IAR Systems
> --
> Disclaimer: Opinions expressed in this posting are strictly my own
and
> not necessarily those of my employer.
>
Thank you that is likely the problem.
However if I set to large then I exceed the limits for this kickstart
package.
full printf is large.
Is there a smaller direct code option? maybe a tight float library?
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Re: Why does int work but not float? - Anders Lindgren - Aug 5 10:19:38 2008

mpbwork wrote:

> Thank you that is likely the problem.
> However if I set to large then I exceed the limits for this kickstart
> package.
> full printf is large.
> Is there a smaller direct code option? maybe a tight float library?

Hi Mpb!

No, only the large printf formatter can handle floating-point output.

However, it's not that difficult to hand-craft an output routine for
floating-point numbers, for a given format.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Re: Why does int work but not float? - Jon Kirwan - Aug 5 16:33:02 2008

On Tue, 05 Aug 2008 16:19:27 +0200, you wrote:

>mpbwork wrote:
>
>> Thank you that is likely the problem.
>> However if I set to large then I exceed the limits for this kickstart
>> package.
>> full printf is large.
>> Is there a smaller direct code option? maybe a tight float library?
>
>Hi Mpb!
>
>No, only the large printf formatter can handle floating-point output.
>
>However, it's not that difficult to hand-craft an output routine for
>floating-point numbers, for a given format.

If need be and if precise specs (with a few examples included) can be
provided and if I'm allowed to work at it as I feel the mood, I'd be
willing to write the output code without charge and provide it.

Jon

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )