R
rickman
I am converting an integer equation to use numeric_std data types and
it looks rather awkward. Here is the equation...
PhaseStep <= (IntgrPhase + (PROPGAIN * DataCount) + FreqStep) mod
MODULUS;
The names in caps are integer constants, PhaseStep and FreqStep are
unsigned while IntgrPhase and DataCount are signed, all four the same
length, 16 bits. The true range of DataCount will be very limited so
it is invalid that it will cause an overflow of the result. In fact,
it is considered an operational error if any of this causes an
overflow in the result... that is the inputs must have been out of
whack, not the circuit. So I'm not worried about the math at that
level. I'm concerned about how to get the circuit I want without a
lot of difficult typing of syntax.
I just want this stuff to be added to produce a 16 bit result. When
doing this using integer arithmetic it all works well. In simulation
it only barfs if a value exceeds its range and the synthesis result
uses the correct number of bits in the implementation. I don't see it
using any extra bits in the calculations which makes sense, why
calculate bits you aren't using in the end?
To add the signed and unsigned values, I believe I will have to add a
bit to the unsigned FreqStep before adding to the signed values. The
significant bits will not flow into the added bit, so it can be
dropped in the end. But this will complicate the result a lot.
PhaseStep <= resize(unsigned(IntgrPhase + (PROPGAIN * DataCount) +
signed(resize(FreqStep,STEPWIDTH+1)) mod MODULUS), STEPWIDTH);
Am I making this more complicated than it needs to be? If I just
convert FreqStep to signed without the resize, it will treat the msb
as a sign bit and corrupt the value, right? I guess the fact that I
call it a signed value doesn't change the circuit, but it will change
the simulation, right?
The other thing I could do is to convert them all to integer and then
back, but that is no less messy.
Any ideas on a way to make this expression simpler?
Rick
it looks rather awkward. Here is the equation...
PhaseStep <= (IntgrPhase + (PROPGAIN * DataCount) + FreqStep) mod
MODULUS;
The names in caps are integer constants, PhaseStep and FreqStep are
unsigned while IntgrPhase and DataCount are signed, all four the same
length, 16 bits. The true range of DataCount will be very limited so
it is invalid that it will cause an overflow of the result. In fact,
it is considered an operational error if any of this causes an
overflow in the result... that is the inputs must have been out of
whack, not the circuit. So I'm not worried about the math at that
level. I'm concerned about how to get the circuit I want without a
lot of difficult typing of syntax.
I just want this stuff to be added to produce a 16 bit result. When
doing this using integer arithmetic it all works well. In simulation
it only barfs if a value exceeds its range and the synthesis result
uses the correct number of bits in the implementation. I don't see it
using any extra bits in the calculations which makes sense, why
calculate bits you aren't using in the end?
To add the signed and unsigned values, I believe I will have to add a
bit to the unsigned FreqStep before adding to the signed values. The
significant bits will not flow into the added bit, so it can be
dropped in the end. But this will complicate the result a lot.
PhaseStep <= resize(unsigned(IntgrPhase + (PROPGAIN * DataCount) +
signed(resize(FreqStep,STEPWIDTH+1)) mod MODULUS), STEPWIDTH);
Am I making this more complicated than it needs to be? If I just
convert FreqStep to signed without the resize, it will treat the msb
as a sign bit and corrupt the value, right? I guess the fact that I
call it a signed value doesn't change the circuit, but it will change
the simulation, right?
The other thing I could do is to convert them all to integer and then
back, but that is no less messy.
Any ideas on a way to make this expression simpler?
Rick