Post Go back to editing

# decimal to 5.23 conversion

Category: Software
Software Version: Sigma Studio version 4.5 Build 1, Rev 17916/24/2020

Hi,

I am building FIR block in SigmaStudio which I intend to implement on ADAU1761.
I have FIR coefficients (from Matlab) in decimal format and I convert them to 5.23 format using to523 procedure (Microsoft Word - SigmaStudio.doc (amobbs.com)).

void To523( double _param_dec, BYTE* _param_hex)
{
int param223;
int param227;
//multiply decimal number by 2^23
param223 = _param_dec * (1 << 23);
//convert to positive binary
param227 = param223 + (1 << 27);
_param_hex[3] = (BYTE)param227; //get byte 3 (LSBs) of parameter value
_param_hex[2] = (BYTE)(param227>>8); //get byte 2 of parameter value
_param_hex[1] = (BYTE)(param227 >> 16); //get byte 1 of parameter value

_param_hex[0] = (BYTE)(param227 >> 24); //get byte 0 (MSB) of parameter value
_param_hex[0] = _param_hex[0]^0x08; //invert sign bit to get correct sign
}

The output of To523 procedure gives me values that are slightly different than I get in SigmaStudio.
For example when To523 procedure decodes decimal 0.000180319592330146051886718971957179747 it produces _param_hex 0x00 0x00 0x05 0xE8 while SigmaStudio gives 0x00 0x00 0x05 0xE8.

What is wrong with To523 procedure?

Wlodek

• I have modified conversion procedure and it seems to work OK

void To523( double _param_dec, BYTE* _param_hex)
{

int      param223 = 1 << 23;
int     intparam = round(_param_dec * param223);
_param_hex[3] = (BYTE)intparam ; //get byte 3 (LSBs) of parameter value
_param_hex[2] = (BYTE)(intparam >>8); //get byte 2 of parameter value
_param_hex[1] = (BYTE)(intparam >> 16); //get byte 1 of parameter value
_param_hex[0] = (BYTE)(intparam >> 24); //get byte 0 (MSB) of parameter value
}

• Hello,

I think the difference is that SigmaStudio performs rounding but To523 does not.

For example using Matlab:

a=0.000180319592330146051886718971957179747;
dec2hex(round(a*2^23),8)

ans =

'000005E9'

• another comment:

keep in mind that 23 bits is about 7 decimal places of resolution:

log10(2^23) = 6.92