Modo 'N' angle converters


About the writer: Harvey Morehouse is a contractor/consultant with many years of experience using circuit analysis programs. His primary activities are in Reliability, Safety, Testability and Circuit Analysis. He may be reached at harvey.annie@verizon.net. Simple questions for which I know the answer are free. Complex questions, especially where I am ignorant of the answers, are costly!!!

Summary: As a mechanical building block element, it is sometimes required to operate on a rotary angle. These device will convert the integral of omega, a shaft angular velocity in radians/second, into a shaft angle in radians modulo 2*PI and modulo 2*PI.

Why a Mod 2PI converter?:

Often when solving the equations of motion for a rotary system in a model, one arives at an result in terms of shaft angular velocity or omega. However, in a closed loo

simulation, the motor torque, is often dependent on motor shaft angle, and is required to be known in order to produce the drive to the rotary system. However if rotation occurs for very long in a simulation, the integral of this could be very large.

Now of course if one were to integrate the shaft angular velocity, one would get a result which would be usable with trigonometric operators, as the angle, which could exceed 2*PI in magnitude would provide correct results, however, in other cases an output angle representation which varies from zero to 2*PI (or 360 degrees, or some integer divisor of either) and repeats is required. And of course for rotation in the opposite direction, the 'negative' angle is required.

It is common to create a modulo converter using counters, but this can create modeling problems, if only in the complexity of the counters to be used in the device. And of course there is the problem of the 'granularity' of the output signal. That is to say, if there were for example 360 discrete counter outputs, a given 'count' could be no more accurate than plus or minus ½ count. And, the output could take time to compute, and in a complex modeling problem overall, this could slow down the solution times.

Consequently it was convenient for me to create several modulo counter versions. One would produce a modulo 360 degree signal, and the other a modulo 2*PI signal, and another variant, 'submodulo' outputs. Now of course it is easy to convert the input and outputs from degrees to radians or the converse, therefore it was chosen to have the input be expressed in radians per second. I chose to have the outputs expressed in radians for the same reason. If a degree representation is required, this is simple enough to arrive at.

Modulo 2*pi converter:

The good guys at B2SPICE provided the algorithm used to create this device to me. It came from "The Design Source Newsletter, January 1993. It takes the form of:

mod(a,b) = b*atan(tan((((a/(b))*PI- PI/2)) +PI/2)/ PI

Here 'a' is the value to be converted, and 'b' is the desired modulo output. In this case, we will use as 'a' an input signal, and 'b' will be equal to 2*PI.

A test circuit showing this device implementation, for both a modulo 2*PI and 'N', for N = 8, is shown in Figure 1 following.


Figure 1
Modulo test circuit 1

Generator B2 creates a voltage equal to PI volts. It multiplies the value of the arctangent of 1 (which is PI/2) by 4 resulting in a value of PI. Device V2 provides a constant velocity input of 10 radians per second. This is integrated by an x-spice integrator block with a gain of 1 to produce the angle value, in radians.

The inputs as shown are just the 'Velin' variable. Later we will parameterize the value of 'N', but by comparison with the 2*PI period defining voltage equation of the B1 generator, it is seen in this case that 'N' is 8.

A test simulation of the outputs is shown in Figure 2 following:


Figure 2
Modulo test circuit 1 output

From Figure 2 it can be seen that the input ramp is in blue. The modulo 2*PI curve in green, and it has a maximum value of 6.28 volts, or two radians. The purple curve, the modulo 'N=8' curve shows 8 cycles within the time of the modulo 2*PI curve.

Examination of the blue curve of the raw angle, one sees that it reaches a value of 10 in one second, and this of course is the value of the v1 test generator,

The next step is to test the circuit of Figure 1 to see if it performs as expected for negative rotational velocity. This is easily done by either changing the value of v1 to -10 volts, or 'flipping' the v1 generator. Doing this, the output graph becomes as shown in Figure 3.



Figure 3
Modulo test circuit 1 output with 'negative' rotation

Well, this seems unusual. Instead of the modulo 2*PI signal starting at zero, decreasing to -2*PI volts where it jumps to zero, it starts at zero, jumps to 2*PI volts and decreases to zero. The modulo 8 generator behaves similarly. This 'seems' at first to be an error, but then, as a positive angle of 359 degrees is equal to a negative one degree angle, perhaps it is not. Let's perform another test, taking the sine of the vmod2p and vmodN ouputs. The resultant output is shown in Figure 4 following:


Figure 4
Modulo test circuit 1 output with 'negative' rotation and sines

For the mod2p signal and its sine, green and blue traces respectively, the sine output appears normal. Certainly as the sin(-theta) is equal to -sin(theta) the output appears to be correct. The mod 8 signal needs some examination.

For small angles, the sine(theta) is approximately equal to theta, and the red curve of the sine of the modulo 8 signal is close to that of the yellow modulo signal. Looking at the curve from one of the abrupt vertical transitions, moving to the left, starting at zero, the angle increases. Whereas to the right, it jumps to about 0.7.85 or PI/4, then decreases. From a mathematical view this makes sense, as in a modulo 2*PI/8 signal, zero and PI/4 are the same point.

The remaining task now is to create two different subcircuits/devices. The first is just the velocity to angle converter, mod2p. The second, mod2pN consists of the mod2p converter which is passed a parameter 'N' that creates a modulo 2*PI/N output signal.

These two circuits to be converted are shown in Figure 5 following, with the modulo 2*PI circuit model above that of the modulo 2*PI/N signal.


Figure 5
Mod2p and modN subcuits

Figure 5 shows the two required subcircuts, with devices A1, B1 and B2 with associated components comprising the mod2p device. Generators B3, B4 and R1 with associated components comprise the modn device. The second device is passed a parameter 'N', which is the (normally) angular position of the rotation with time modulo 2*PI/N.

It is assumed that the two devices will be created by the user as needed, however, it is presumed these will be added to the B2SPICE libraries at some time.

Conclusions:

A means of creating modulo 2*PI and modulo 2*PI/N signals has been prepared. These functions can be useful in a variety of mechanical problem solutions. The outputs and inputs are expressed in radians, however, by multiplication of the outputs or inputs by appropriate constants these items can be be converted into other measurement systems.