PASM adds and subs
Duane Degn
Posts: 10,588
I'm not sure if I understand signed add and subtract.
I want to adjust privateTarget0 up or down based on the change in targetSpeed0.
targetSpeed0 can be positive or negative (so can privateTarget0).
In this portion of the program, I save the earlier targetSpeed0 to previousSpeed0. I use the temporary variable "difference" to calculate, what I think should be, the change in targetSpeed0.
I plan to modify privateTarget0 in a another part of the program so it wont stay equal to targetSpeed0. But for now, the two values should match (or so I think). Both values start at zero. This is the only place targetSpeed0 is changed (by reading value from hub).
For now, I'm writing privateTarget0 to hub RAM for debugging. I don't think I'll need access to it in the final version of the program.
When I watch the variables from a different cog I see privateTarget0 increase when targetSpeed0 is increased but privateTarget0 doesn't decrease when targetSpeed0 is decreased.
Is there an error in my understanding of subs and/or adds or is my problem hiding somewhere else?
Thanks,
Duane
I want to adjust privateTarget0 up or down based on the change in targetSpeed0.
targetSpeed0 can be positive or negative (so can privateTarget0).
In this portion of the program, I save the earlier targetSpeed0 to previousSpeed0. I use the temporary variable "difference" to calculate, what I think should be, the change in targetSpeed0.
I plan to modify privateTarget0 in a another part of the program so it wont stay equal to targetSpeed0. But for now, the two values should match (or so I think). Both values start at zero. This is the only place targetSpeed0 is changed (by reading value from hub).
updateTarget mov previousTargetSpeed0, targetSpeed0 rdlong targetSpeed0,targetAddress0 mov difference, targetSpeed0 subs difference, previousTargetSpeed0 ' has target speed changed? adds privateTarget0, difference ' adjust privateTarget speed to reflect change wrlong privateTarget0, privateTargetAddress0
For now, I'm writing privateTarget0 to hub RAM for debugging. I don't think I'll need access to it in the final version of the program.
When I watch the variables from a different cog I see privateTarget0 increase when targetSpeed0 is increased but privateTarget0 doesn't decrease when targetSpeed0 is decreased.
Is there an error in my understanding of subs and/or adds or is my problem hiding somewhere else?
Thanks,
Duane
Comments
This should help me find the problem.
Thank you for this additional information. I didn't understand the difference between signed and unsigned add and subtract.
I'm trying to control four motors with encoders from within one cog.
Duane