**Frac16**or

**Frac32**, and

**int**o

**long**numbers. As I know to convert a real number to fractional I must use FRAC16(

*real*) included in the dspfun.h. How I can obtain the real number giving a Frac number?

Hi,

I'm new with the 56F801 DSP and I'm confusing about the conversion between fractional numbers, **Frac16** or **Frac32**, and **int** o **long** numbers. As I know to convert a real number to fractional I must use FRAC16(*real*) included in the dspfun.h. How I can obtain the real number giving a Frac number?

Can anyone tell me where a can find an application note, code example, etc?

Sorry to all for this silly question.

Thanks

- I'm not familiar with and don't have time to test, but Tom, are you saying that it is like a fixed point where the value is always less than one? Also looks like signed type.

The answer to the original question in other words would be if I say FRAC16(0.75) it will give me 24575.25 (0x5fff). If I store that as 16-bit (short), Then I can say the value means a positive (0x5fff/0x7fff)? Or is it better (0x5fff/0x8000)?

I used this for calculator experimenting. It does say alot, thanks

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

Hello Tom,

J2MEJediMaster wrote:

The difference between the binary representations of fractional and integer numbers is where that implicit binary point lies. The easiest way to explain this is with the attached diagram, which will be clearer and more concise than the thousand words it would take to explain things. What this means is that you can convert between the two formats by multiplying or dividing by 32767.0 for 16-bit numbers. For conversion to fractional values, the following macro was originally used:

#define CFF(x) (x * 32767.0)

There was a one-bit error in that computation, so now the Frac16 conversion macro is:

#define FRAC16(x) (x < 1 ? ( x >= -1 ? x * 0x7FFF : 0x8000) : 0x7FFF)My limited understanding of a signed fractional number representation suggests that the effective magnitude of the fraction will always be less than 1, i.e. a maximum represented value of 32767 / 32768 for integer size.

By this reckoning, the multiplier/divider value should be 32768 ($8000), rather than 32767. Therefore, a value of 0.75 would be represented by $6000.

Regards,

Mac

Message Edited by bigmac on 05-06-200605:16 PM

Having used the Motorola DSPs for years, first the DSP56002 and currently the DSP56303, I can verify that what Mac says is correct and cast in silicon.

bigmac wrote:By this reckoning, the multiplier/divider value should be 32768 ($8000), rather than 32767. Therefore, a value of 0.75 would be represented by $6000.

bigmac wrote:My limited understanding of a signed fractional number representation suggests that the effective magnitude of the fraction will always be less than 1, i.e. a maximum represented value of 32767 / 32768 for integer size.

By this reckoning, the multiplier/divider value should be 32768 ($8000), rather than 32767. Therefore, a value of 0.75 would be represented by $6000.

I think you are saying that the CW macro is wrong. It multiplies by 0x7fff.

- The Frac16() macros which uses a multiplier of 0x8000, is the way to go. Explaining that it's a divide by 32768 (instead of 32767, my mistake), makes what's going on in the conversion more apparent.

Both macros (and the mention of the bit error) were given to me by a Motorola engineer working on the Suite56 DSP libraries.

Sorry for the confusion.

---Tom

#define CFF(x) (x * 32767.0)

There was a one-bit error in that computation, so now the Frac16 conversion macro is:

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

To convert back to ints, you'd use a divide operation. Double-check the header files and see if this conversion macro is already done for you.

One final note: be very careful and ensure that you're not mixing fractional variables with integer variables in a computation. You'll definitely get garbage out.

---Tom

Message Edited by J2MEJediMaster on 05-04-2006 03:06 PM

Message Edited by J2MEJediMaster on 05-04-2006 03:16 PM