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.
What kind of logic could it be? - jeff...@gmail.com - Sep 6 12:54:56 2008
Hello everybody,
Im dont like this kind of question, but, two days ago im facing an unusual problem.
On the IAR interface (Version 5.0) i put this function, that was suposed to kill the
first four bits of the variable temp.
float INCLI_Converter_Temperatura(unsigned short int temp)
{
temp = temp - (temp%4095)*4095 ;
temp -= 1278 ;
return (float)(25 - temp*0.47) ;
}
Of course, i try to made it this way too:
temp &= 0x0FFF ;
But, none of then works. The compiler simply jumps the lines of calculation.
Anyone knows what could be the problem?
Best Regards,
Jefferson Sola de Haro
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: What kind of logic could it be? - old_cow_yellow - Sep 6 15:53:10 2008
Your line of code:
temp = temp - (temp%4095)*4095;
does not make any sense to me. What kind of logic is this?
--- In m...@yahoogroups.com, jefferson.sola@... wrote:
>
> Hello everybody,
> Im dont like this kind of question, but, two days ago im facing an
unusual problem.
> On the IAR interface (Version 5.0) i put this function, that was
suposed to kill the first four bits of the variable temp.
>
> float INCLI_Converter_Temperatura(unsigned short int temp)
> {
> temp = temp - (temp%4095)*4095 ;
> temp -= 1278 ;
>
> return (float)(25 - temp*0.47) ;
> }
>
> Of course, i try to made it this way too:
>
> temp &= 0x0FFF ;
>
> But, none of then works. The compiler simply jumps the lines of
calculation.
> Anyone knows what could be the problem?
>
> Best Regards,
>
> Jefferson Sola de Haro
>
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: Re: What kind of logic could it be? - Jon Kirwan - Sep 6 17:13:59 2008
On Sat, 06 Sep 2008 19:53:01 -0000, old_cow_yellow wrote:
>Your line of code:
> temp = temp - (temp%4095)*4095;
>does not make any sense to me. What kind of logic is this?
The 'almost' kind? Probably the OP plans to kill the upper four
(wrote "first" but I think meant high-order bits, especially given the
proposed attempt using "temp &= 0x0FFF;" ) bits and wanted to kind of
"down-shift" to get the upper four and then re-shift them back and
completely messed it all up. The % doesn't shift like that and the
constant is screwed up, anyway.
The OP may misunderstand the problem faced and even if the expression
had been written correctly would still fail to get the desired result.
(The &= expression used was just fine to clear off the upper bits and
apparently that didn't work as desired.) For example, if the bits to
be cleared are the least significant ones and the upper 12 should be
shifted downwards to achieve that, both expressions used by the OP
would fail terribly, whether expressed rightly -or- wrongly.
We don't see the code used by the caller, either, so no way to know
what is being "observed" by the OP. I also doubt that the compiler
"jumps [over] the lines of calculation."
Jon
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: Re: What kind of logic could it be? - Firat Kocak - Sep 6 17:31:10 2008
Hi,
I have never written code for msp series mcu's. But after having a look
at your code, i have some dark sides in my mind.
Your input parameter for the function is unsigned short int. So, as much
as i know, msp430 series mcu's are 16-bit wide mcu's. I mean unsigned
short int should represent for a variable of 8-bit wide. If i am not
wrong, ANDing that input parameter with 0x0FFF will never change its
initial value.
I would like to ask you ... What is the returning result that you get
after executing the functon ? Are the returning results same all the time ?
Best regards,
Firat Kocak
old_cow_yellow wrote:
>
> Your line of code:
> temp = temp - (temp%4095)*4095;
> does not make any sense to me. What kind of logic is this?
>
> --- In m...@yahoogroups.com
,
> jefferson.sola@... wrote:
> >
> > Hello everybody,
> > Im dont like this kind of question, but, two days ago im facing an
> unusual problem.
> > On the IAR interface (Version 5.0) i put this function, that was
> suposed to kill the first four bits of the variable temp.
> >
> > float INCLI_Converter_Temperatura(unsigned short int temp)
> > {
> > temp = temp - (temp%4095)*4095 ;
> > temp -= 1278 ;
> >
> > return (float)(25 - temp*0.47) ;
> > }
> >
> > Of course, i try to made it this way too:
> >
> > temp &= 0x0FFF ;
> >
> > But, none of then works. The compiler simply jumps the lines of
> calculation.
> > Anyone knows what could be the problem?
> >
> > Best Regards,
> >
> > Jefferson Sola de Haro
> >
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: Re: What kind of logic could it be? - Joe Radomski - Sep 6 17:36:10 2008
on msp 430 short and int are same size..
from limits.h
#define SHRT_MAX=A0=A0 32767
#define SHRT_MIN=A0=A0 (-32767 - 1)
#define USHRT_MAX=A0 65535
=A0
#define INT_MAX=A0=A0 32767
#define INT_MIN=A0=A0 (-32767 - 1)
#define UINT_MAX=A0 65535U
=A0
--- On Sat, 9/6/08, Firat Kocak
wrote:
From: Firat Kocak
Subject: Re: [msp430] Re: What kind of logic could it be?
To: m...@yahoogroups.com
Date: Saturday, September 6, 2008, 5:30 PM
Hi,
I have never written code for msp series mcu's. But after having a look=20
at your code, i have some dark sides in my mind.
Your input parameter for the function is unsigned short int. So, as much=20
as i know, msp430 series mcu's are 16-bit wide mcu's. I mean unsigned=20
short int should represent for a variable of 8-bit wide. If i am not=20
wrong, ANDing that input parameter with 0x0FFF will never change its=20
initial value.
I would like to ask you ... What is the returning result that you get=20
after executing the functon ? Are the returning results same all the time ?
Best regards,
Firat Kocak
old_cow_yellow wrote:
>
> Your line of code:
> temp =3D temp - (temp%4095)* 4095;
> does not make any sense to me. What kind of logic is this?
>
> --- In msp430@yahoogroups. com ,=20
> jefferson.sola@ ... wrote:
> >
> > Hello everybody,
> > Im dont like this kind of question, but, two days ago im facing an
> unusual problem.
> > On the IAR interface (Version 5.0) i put this function, that was
> suposed to kill the first four bits of the variable temp.
> >
> > float INCLI_Converter_ Temperatura( unsigned short int temp)
> > {
> > temp =3D temp - (temp%4095)* 4095 ;
> > temp -=3D 1278 ;
> >
> > return (float)(25 - temp*0.47) ;
> > }
> >
> > Of course, i try to made it this way too:
> >
> > temp &=3D 0x0FFF ;
> >
> > But, none of then works. The compiler simply jumps the lines of
> calculation.
> > Anyone knows what could be the problem?
> >
> > Best Regards,
> >
> > Jefferson Sola de Haro
> >=20
=20
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: What kind of logic could it be? - jeff...@gmail.com - Sep 6 17:38:59 2008
Hello Jon,
You are correct about the intent to clear the four bits.
The real intent is to clear the first four bits of data (uper four), and woks with the
last 12 bits.
I dont know why, but when it enter on the funcion, it goes directly to the return line
(at the debbuging) and the value of temp is showed has unchanged.
Im a bit concerned about what is happening. The equation
temp = temp - (temp%4095)*4095 ; was a try to solve it, concerning about the possibly
impossibility to use integers with logic (since the value was unchanged early).
I will try any suggestion.
That its a simple linear equation to determine (in percentage) the amount of a battery
based on the voltage curve (here is only one step of the curve), many linear aproximations
had been done.
Hello everybody,
>Im dont like this kind of question, but, two days ago im facing an unusual problem.
>On the IAR interface (Version 5.0) i put this function, that was suposed to kill the
first four bits of the variable temp.
>
>float INCLI_Converter_Temperatura(unsigned short int temp)
>{
> temp = temp - (temp%4095)*4095 ;
> temp -= 1278 ;
>
> return (float)(25 - temp*0.47) ;
>}
>
>Of course, i try to made it this way too:
>
>temp &= 0x0FFF ;
>
>But, none of then works. The compiler simply jumps the lines of calculation.
>Anyone knows what could be the problem?
>
>Best Regards,
>
>Jefferson Sola de Haro
>
>------------------------------------
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: What kind of logic could it be? - jeff...@gmail.com - Sep 6 17:43:20 2008
Hello Jon,
You are correct about your observation.
The real intent here is to clear the first 4 bits (MSbits) of the value of temp.
The other line: temp = temp - (temp%4095)*4095 ; was an intent to make it, concerning
about the impossibility to use a int with boolean logic (oh man, i dont said that, sory
everyone) cause it doesnt work, and the value was unchanged.
I will try any suggestion to solve this (unless put your computer on the oven of course
=) )
Sorry by the jokes guys, but this is serious, im not kidding about the problem.
Thanks everyone,
Best Regards
Hello everybody,
>Im dont like this kind of question, but, two days ago im facing an unusual problem.
>On the IAR interface (Version 5.0) i put this function, that was suposed to kill the
first four bits of the variable temp.
>
>float INCLI_Converter_Temperatura(unsigned short int temp)
>{
> temp = temp - (temp%4095)*4095 ;
> temp -= 1278 ;
>
> return (float)(25 - temp*0.47) ;
>}
>
>Of course, i try to made it this way too:
>
>temp &= 0x0FFF ;
>
>But, none of then works. The compiler simply jumps the lines of calculation.
>Anyone knows what could be the problem?
>
>Best Regards,
>
>Jefferson Sola de Haro
>
>------------------------------------
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: Re: What kind of logic could it be? - Firat Kocak - Sep 6 17:44:48 2008
Ok. Sorry for this.
So please try the code below and tell me what is the result.
return ( 25.0 - ( (float) ( ( temp & 0x0FF ) - 1278 ) * 0.47 ) );
Best regards,
Firat Kocak
Joe Radomski wrote:
>
> on msp 430 short and int are same size..
>
> from limits.h
> #define SHRT_MAX 32767
> #define SHRT_MIN (-32767 - 1)
> #define USHRT_MAX 65535
>
> #define INT_MAX 32767
> #define INT_MIN (-32767 - 1)
> #define UINT_MAX 65535U
>
>
> --- On Sat, 9/6/08, Firat Kocak
>
> wrote:
>
> From: Firat Kocak
> >
> Subject: Re: [msp430] Re: What kind of logic could it be?
> To: m...@yahoogroups.com
> Date: Saturday, September 6, 2008, 5:30 PM
>
> Hi,
>
> I have never written code for msp series mcu's. But after having a look
> at your code, i have some dark sides in my mind.
>
> Your input parameter for the function is unsigned short int. So, as much
> as i know, msp430 series mcu's are 16-bit wide mcu's. I mean unsigned
> short int should represent for a variable of 8-bit wide. If i am not
> wrong, ANDing that input parameter with 0x0FFF will never change its
> initial value.
>
> I would like to ask you ... What is the returning result that you get
> after executing the functon ? Are the returning results same all the
> time ?
>
> Best regards,
>
> Firat Kocak
>
> old_cow_yellow wrote:
> >
> > Your line of code:
> > temp = temp - (temp%4095)* 4095;
> > does not make any sense to me. What kind of logic is this?
> >
> > --- In msp430@yahoogroups. com ,
> > jefferson.sola@ ... wrote:
> > >
> > > Hello everybody,
> > > Im dont like this kind of question, but, two days ago im facing an
> > unusual problem.
> > > On the IAR interface (Version 5.0) i put this function, that was
> > suposed to kill the first four bits of the variable temp.
> > >
> > > float INCLI_Converter_ Temperatura( unsigned short int temp)
> > > {
> > > temp = temp - (temp%4095)* 4095 ;
> > > temp -= 1278 ;
> > >
> > > return (float)(25 - temp*0.47) ;
> > > }
> > >
> > > Of course, i try to made it this way too:
> > >
> > > temp &= 0x0FFF ;
> > >
> > > But, none of then works. The compiler simply jumps the lines of
> > calculation.
> > > Anyone knows what could be the problem?
> > >
> > > Best Regards,
> > >
> > > Jefferson Sola de Haro
> > >
> >
> > [Non-text portions of this message have been removed]
>
>
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: What kind of logic could it be? - jeff...@gmail.com - Sep 6 19:07:42 2008
Good shoot,
Now something have to be calculated =).
Well, i tryed and the answer was:
-3.07529492E+4, when it was supposed to be like 4.89xxxxxE+1
At this point, i try to select every single part of the equation and see the result. It
shows me the correct value, but when returned from the function, was wrong (and
diferent).
Now i have the second part of the mystery. I tryed to put the code directly on the main,
and kazam, the same wrong value, so, there must be some conversion problem or something
like that.
If anyone want to test, here it goes, put this code on the main and try to see the
result:
float test = 25.0 - ( (float) ( ( temp & 0x0FFF ) - 1278 ) * 0.47 );
if(test>0)
__low_power_mode_off_on_exit() ;
(the last lines was just to force the calculus, cause if you dont use the variable for
something, it will not be created)
Best Regards
Hello everybody,
>Im dont like this kind of question, but, two days ago im facing an unusual problem.
>On the IAR interface (Version 5.0) i put this function, that was suposed to kill the
first four bits of the variable temp.
>
>float INCLI_Converter_Temperatura(unsigned short int temp)
>{
> temp = temp - (temp%4095)*4095 ;
> temp -= 1278 ;
>
> return (float)(25 - temp*0.47) ;
>}
>
>Of course, i try to made it this way too:
>
>temp &= 0x0FFF ;
>
>But, none of then works. The compiler simply jumps the lines of calculation.
>Anyone knows what could be the problem?
>
>Best Regards,
>
>Jefferson Sola de Haro
>
>------------------------------------
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: What kind of logic could it be? - jeff...@gmail.com - Sep 6 19:21:05 2008
On the code bellow, put a value of your choice on the variable temp. My test value was
suppose to be 13515.
float test = 25.0 - ( (float) ( ( temp & 0x0FFF ) - 1278 ) * 0.47 );
if(test>0)
__low_power_mode_off_on_exit() ;
Best Regards,
Hello everybody,
>Im dont like this kind of question, but, two days ago im facing an unusual problem.
>On the IAR interface (Version 5.0) i put this function, that was suposed to kill the
first four bits of the variable temp.
>
>float INCLI_Converter_Temperatura(unsigned short int temp)
>{
> temp = temp - (temp%4095)*4095 ;
> temp -= 1278 ;
>
> return (float)(25 - temp*0.47) ;
>}
>
>Of course, i try to made it this way too:
>
>temp &= 0x0FFF ;
>
>But, none of then works. The compiler simply jumps the lines of calculation.
>Anyone knows what could be the problem?
>
>Best Regards,
>
>Jefferson Sola de Haro
>
>------------------------------------
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: Re: What kind of logic could it be? - Firat Kocak - Sep 6 20:05:02 2008
Hi,
I have an Ez430 usb development stick. Checked the code. And found where
the problem is. Namely, your input parameter, temp, is unsigned. temp &
0x0FFF is unsigned. unsigned - signed is unsigned. So there is a math
error here. To correct this, you should define temp variable as signed,
not unsigned.
Best regards,
Firat Kocak
j...@gmail.com wrote:
>
> On the code bellow, put a value of your choice on the variable temp.
> My test value was suppose to be 13515.
>
> float test = 25.0 - ( (float) ( ( temp & 0x0FFF ) - 1278 ) * 0.47 );
> if(test>0)
> __low_power_mode_off_on_exit() ;
>
> Best Regards,
>
> Hello everybody,
> >Im dont like this kind of question, but, two days ago im facing an
> unusual problem.
> >On the IAR interface (Version 5.0) i put this function, that was
> suposed to kill the first four bits of the variable temp.
> >
> >float INCLI_Converter_Temperatura(unsigned short int temp)
> >{
> > temp = temp - (temp%4095)*4095 ;
> > temp -= 1278 ;
> >
> > return (float)(25 - temp*0.47) ;
> >}
> >
> >Of course, i try to made it this way too:
> >
> >temp &= 0x0FFF ;
> >
> >But, none of then works. The compiler simply jumps the lines of
> calculation.
> >Anyone knows what could be the problem?
> >
> >Best Regards,
> >
> >Jefferson Sola de Haro
> >
> >------------------------------------
> >
> >
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: What kind of logic could it be? - jeff...@gmail.com - Sep 6 21:52:19 2008
Very thanks,
You are totaly right =). I need to learn all about this operations.
Now its working.
Problem solved thanks for Firat Kocak.
Best Regards,
Hello everybody,
>Im dont like this kind of question, but, two days ago im facing an unusual problem.
>On the IAR interface (Version 5.0) i put this function, that was suposed to kill the
first four bits of the variable temp.
>
>float INCLI_Converter_Temperatura(unsigned short int temp)
>{
> temp = temp - (temp%4095)*4095 ;
> temp -= 1278 ;
>
> return (float)(25 - temp*0.47) ;
>}
>
>Of course, i try to made it this way too:
>
>temp &= 0x0FFF ;
>
>But, none of then works. The compiler simply jumps the lines of calculation.
>Anyone knows what could be the problem?
>
>Best Regards,
>
>Jefferson Sola de Haro
>
>------------------------------------
------------------------------------

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