Need Help With Fractional Data Types

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Need Help With Fractional Data Types

2,313件の閲覧回数
Anewguy
Contributor I
I'm having trouble converting the results of an A/D conversion
into Frac16 type.
I Have:

#define FRAC16(x) ((Frac16)((x) 1 ? ((x) >= -1 ? (x)*0x8000 : 0x8000) : 0x7FFF))

void AD1_OnEnd(void)
{
word ADResult=0;
Frac16 ADVal=0;
errB=AD1_GetValue16(&ADResult);
if(GetFiFoCnt() FifoSize)
{
ADVal=(FRAC16(ADResult));
PutFifo(ADVal);
}
}
ADResult returns the expected values.
ADVal returns only 0 or 32767!

What am I doing wrong here?

Also, is there a macro to go the other way? Frac16 to int ?

Thanks!
ラベル(1)
0 件の賞賛
返信
2 返答(返信)

1,131件の閲覧回数
J2MEJediMaster
Specialist I
As written, your macro will only return one or the highest possible value. It needs to be modified as so:

#define FRAC16(x) (x < 1 ? ( x >= -1 ? x * 0x7FFF : 0x8000) : 0x7FFF)


If you'll look at your macro, you only have the value one, not a x < 1 test at the start of your macro logic.

---Tom
0 件の賞賛
返信

1,131件の閲覧回数
Anewguy
Contributor I
Tom,

I actuallly have:

#define FRAC16(x) ((Frac16)((x) "less then symbol" 1 ? ((x) >= -1 ? (x)*0x8000 : 0x8000) : 0x7FFF))

The posting seems to have droped the less then symbol in 2 places.
It was in my code.
But I will try your code.

Thanks!
0 件の賞賛
返信