Dave Bryner

Need Help With Fractional Data Types

Discussion created by Dave Bryner on Jul 20, 2006
Latest reply on Jul 24, 2006 by Dave Bryner
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!

Outcomes