# Division / Mod

Is there a simple way to program a division procedure to divide numbers?

I am programming something to limit a range and if it exceeds this range, it is divided and brought back into the range.

Is there a simpler way to do this because the variables are integers and you can’t divide them…

Any help or info is greatly appreciated.

Jeremy Phan

You can divide integers, it’s just that the result is another integer (e.g. 3/2=1). Can you please explain what you’re doing this for, however, becasue I’m having trouble seeing what you are trying to do. My initial thought is that if all you want to do is keep a value inside a range just use
myVal = myVal MIN lower_bound MAX upper_bound
But I don’t know if that’s what you need, so I’d appreciate it if you could clarify your question, unless by some struck of luck I just ansered it

Stephen

I’m trying to output 2 values (a, b) taking 2 other values (x, y).

The problem is that over a certain range, the excess has to be carried over to the 2nd variable. Then addition and subtraction have to be done to the 2 variables to produce the 2nd set of variables.

The problem I am encountering is that I need to program an extreme region which would be exempt from this and 2 regions which are “more sensitive”. The math is really driving me nuts right now… and the approach I’m trying to do is to use the number and calculate the slope of X and Y to the limit and then using the slope as a identifier to the region, go to a specific procedure.

[JPTN]

In that case, you shouldn’t need any kind of special procedure to divide. Just use the division ("/") operator; if the result is a non-integer, it should be truncated (I believe). This should be good enough for what you’re trying to do.

If you’re willing, I’d be interested to hear the specifics of what you’re trying to do.

I’m trying to program a free-floating arm controlled by a joystick.

It’s 3-dimensional movement and I need to program different areas of sensitivity for its different ranges.

The problem is that there are 2 motors controlling a single device and they have to be pulling at different strengths. It’s just math but any help is appreciated.

[JPTN]

Use a data table in the EEPROM. Then, using C++ (or some other language like that), do all the calculations. make sure to only have integers (since PBASIC truncates), and load it into the EEPROM using the “DATA” command. then, when you take the values, you can read them from the EEPROM using the “READ” command. very simple, and it works just as fast (or fast enough) as if you’re doing the calculations on the fly. Just don’t let Joe Ross help you program that part.

Ex.

to put something into EEPROM

Joe’s Way (The Not-Right Way)
EEPROM 1,2,3,4,5…

The Right Way
DATA 1,2,3,4,5…

The numbers are then placed in the EEPROM starting from the first spot, and working to the last. There’s ways where you can get fancy with it, but i’m not sure of them. Check the manual, under DATA. Hope this helps, and if you need any more help, come over to team 810 at nats.

doing anything with the eeprom is considerably slower than doing it mathematically. If i remember back to the CODEX meeting correctly you told us all how you reduced something to 85% of it original value with the eeprom. try saying x=x17/20. or, if you want to do it only if it is below 127, try x = x/127127*17/20+(127/x max 1 *x)

do the math, not the eep