Remainder of a division operation in System Generator
10 views (last 30 days)
Show older comments
SUHANYA M S on 20 Jan 2023
Commented: SUHANYA M S on 30 Jan 2023
I have an integrator which gives the running value of angle theta. To find the sine/cosine of this angle using the SysGen ROM block, the value of theta is always required to be within the range 0-360, which can be obtained by finding the remainder of division of theta by 360.
As there is no direct block that gives the remainder after division operation in SysGen blockset, please suggest a way to do this.
Andy Bartlett on 23 Jan 2023
Consider restructuring your design to work in units of revolutions instead of in degrees. In that case you only need to perform modulo 1 which is nothing more that dropping the bits to the left of the binary-point.
FYI: when modeling with Simulink blocks instead of System Generator Blocks, Fixed-Point Designer's Modulo by Constant block can be used. It is design to give optimal handling of modulo by constants like 360, 2*pi, etc. But modulo of 1 revolution will still lead to the most efficient implementation.
More Answers (1)
Bharath Venkataraman on 20 Jan 2023
When you say "running value", what is the range of the update value? If the initial value can be set to the proper range of 0 to 360 and the update value is limited such that the accumulated value will be less than 720 degreees, you may be able to use an adder to add the value followed by a subtractor of added value-360. Then you can choose between those values to stay between 0 and 360 all the time.
So if you current value is 300 and you add in 75 degrees, you will end up with 375 out of the adder and 15 out of the subtractor. Seeing that 15 is a positive value (or knowing that 375 is greater than 360), you pick the subtractor output. Otherwise, you would pick the adder output. Whichever value you pick needs to be the next value used for the accumulation.
Find more on Speed and Area Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!