Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Implementing software division in DSP

Status
Not open for further replies.

kirgizz

Member level 2
Joined
Sep 7, 2004
Messages
52
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
644
l_sub(l_num,l_denom);

Hi,

could someone give me a tip or a pair of approximation formulas for implementing division in software? (-> using assembler)

About application:
I need to acquire the frequency of an input TTL-signal. I use a timer and measure period of the input signal. Then the measured value is divided by reference value (DSP clock). My design is using 32 bit fixed point data. Measured value and the divider are unsigned integers.
I think, my DSP has a ROM-based table of reciprocal values, but it's not accurate enough. I suppose, it can be implemented by shifting,addition and multiplication.
Does it???

Thank you in advance
 


Thank you Akorostel,

it was useful. I know the right direction now.
 

See this c code.

Word32 L_div_s(Word32 var1, Word32 var2)
{
Word32 var_out = 0;
Word32 iteration;
Word32 L_num;
Word32 L_denom;

if ((var1 > var2) || (var1 < 0) || (var2 < 0))
{
printf("Division Error var1=%d var2=%d\n",var1,var2);
exit(0);
}

if (var2 == 0)
{
printf("Division by 0, Fatal error \n");
exit(0);
}

if (var1 == 0)
{
var_out = 0;
}
else
{
if (var1 == var2)
{
var_out = MAX_32;
}
else
{
L_num = var1;
L_denom = var2;

for(iteration=0;iteration<31;iteration++)
{
var_out <<=1;
L_num <<= 1;

if (L_num >= L_denom)
{
L_num = L_sub(L_num,L_denom);
var_out = L_add(var_out,1);
}
}
}
}

return(var_out);
}

Word32 L_sub(Word32 L_var1, Word32 L_var2)
{
Word32 L_var_out;

L_var_out = L_var1 - L_var2;

if (((L_var1 ^ L_var2) & MIN_32) != 0)
{
if ((L_var_out ^ L_var1) & MIN_32)
{
L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;
Overflow = 1;
}
}
return(L_var_out);
}

Word32 L_add(Word32 L_var1, Word32 L_var2)
{
Word32 L_var_out;

L_var_out = L_var1 + L_var2;

if (((L_var1 ^ L_var2) & MIN_32) == 0)
{
if ((L_var_out ^ L_var1) & MIN_32)
{
L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;
Overflow = 1;
}
}
return(L_var_out);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top