User Manual
MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
131
This will warn the operator if the arm angle exceeds approximately 8 units (11.25 degrees) and shut
down the equipment if the arm angle exceeds approximately 16 units (22.5 degrees). Most control
examples don’t need to work in actual degrees or decimal values of sine or cosine. To nd the sine of
a 60 degree angle, rst convert the angle to MBasic units by multiplying by 256 and dividing by 360.
For example:
angle = 60 * 256 / 360
will result in a value of 42. (It should actually be 42.667, which rounds to 43, but with integer
arithmetic the decimal fraction is ignored, and the integer is not rounded up.) Then nd the sine
of this angle:
ans = sin angle
This will give a result of 109. Dividing this value by 128 will give the decimal value of 0.851
(compared to the correct oating point value which should be 0.866). You can not directly get
the decimal value by doing this division within MBasic (you would get a result of 0). However,
you could rst multiply by 1000, then divide by 128 to get 851 as your result.
SQR (Square Root)
SQR returns the integer portion of the square root of the argument. Increased precision can be
obtained by multiplying the argument by an even square of 10, such as 100 or 10000.
If the value of “num” is 64, the following statement will return the value of 8 (which is the
square root of 64).
answer = sqr num
If the value of “num” is 220, the following statement will return the value 14, which is the
integer portion of 14.832..., the square root of 220.
answer = sqr num
If more precision is required, multiply the argument by 100 or 10000. Using the example where
“num” = 220 a value 148 is returned, which is 10 times the square root of 220.
answer = sqr (num * 100)
Alternately,
answer = sqr (num * 10000)
the above example will return the value 1483, which is 100 times the square root of 220.