Forum Discussion
Altera_Forum
Honored Contributor
13 years ago --- Quote Start --- Without seeing your actual design, my guess is you are not taking into account the dynamic range of the values. IE If you are considering the initial numbers as integers, but the results of the divide are only fractional, you'll get a result of zero plus a remainder.. If you are only using the resultant register in the multiply your answer will be zero. If you have control over the divide, in that you can limit the dividend to power's of 2, I would highly recommend you just use a programmable shift. Pete --- Quote End --- All of the megafunctions have been set to 14 bits because.... The value i am reading in is 14 bit (max unsigned int 16383). At the moment i've set the division coefficient to 4 to make things simple. So that reduces the number to a 12 bit value (max unsigned int 4095). I've set the multiply coefficient to 2 to make things simple. So this increases the number to a 13 bit value (max unsigned int 8191). I'm only using the quotient output of the dividing megafunction because i don't care for the precision of a decimal value for this application. The multiply only has a result output which i assume is an integer since i'm multiplying 2 integers together. All values have been set to unsigned ints for the inputs and megafunctions. Below is a sample of my code. I've set the variables to outputs so i can monitor them on the simulator. I get the correct values at the flip-flops and after the division but not after the multiply. Like i say i get a result of 0 after the multiply functions.
input Clock;
input In;
output In0;
output In1;
output DivRes0;
output DivRes1;
output MultRes0;
output MultRes1;
//Storage.
LPM_FF Value0(.data(In), .q(In0), .clock(Clock)); //Using default FF megafunction.
defparam Value0.lpm_width = 14;
LPM_FF Value1(.data(In0), .q(In1), .clock(Clock)); //Using default FF megafunction.
defparam Value1.lpm_width = 14;
//Divide with the divide coefficient.
LPMDivide Div0(.clock(Clock), .clken(1'd1), .numer(In0), .denom(3'd4), .quotient(DivRes0)); //Custom divide megafunction.
LPMDivide Div1(.clock(Clock), .clken(1'd1), .numer(In1), .denom(3'd4), .quotient(DivRes1)); //Custom divide megafunction.
//Multiply with the multiply coefficient.
FIR_Multiply Mult0(.clock(Clock), .dataa(DivRes0), .datab(1'd1), .result(MultRes0)); //Custom multiply megafunction.
FIR_Multiply Mult1(.clock(Clock), .dataa(DivRes1), .datab(1'd1), .result(MultRes1)); //Custom multiply megafunction.