Help with PWM object, and Spin - Solved
JasonDorie
Posts: 1,930
I have·a simple PWM motor driver that I downloaded from the Obex which I'm using to drive the enable pin on a dual H-bridge.· Initially I included the PWM object in my top-level spin file, set the output ports, ran the PWM object, and all was well.
I've moved the PWM object into another object which will handle both direction and speed in a single call, but it doesn't work.· I'm guessing it's something very trivial, and I'd love another pair of eyes on it.
In the attached 'MotorControl.spin' file, the SetSpeed() function is currently hardcoded to call PWM.SetDuty() with a constant value.· This works as expected.· If I change that line to use the absolute value of the 'Speed' variable instead, it no longer works.· I have verified with SimpleDebug that the 'Speed' value being passed is correct.· Can anyone spot anything wrong with this?
Thanks in advance,
Jason
Post Edited (JasonDorie) : 2/3/2009 5:55:36 AM GMT
I've moved the PWM object into another object which will handle both direction and speed in a single call, but it doesn't work.· I'm guessing it's something very trivial, and I'd love another pair of eyes on it.
In the attached 'MotorControl.spin' file, the SetSpeed() function is currently hardcoded to call PWM.SetDuty() with a constant value.· This works as expected.· If I change that line to use the absolute value of the 'Speed' variable instead, it no longer works.· I have verified with SimpleDebug that the 'Speed' value being passed is correct.· Can anyone spot anything wrong with this?
Thanks in advance,
Jason
Post Edited (JasonDorie) : 2/3/2009 5:55:36 AM GMT
Comments
If anyone spots anything I'll be grateful.
Thanks,
Jason
anywhoo, if I add a couple of lines to the motorcontrol object, does it work as you expect?· I've added the variable "Kevin", and the Setspeed argument now makes it thru to the Setduty method.
·This is from a total prop newbie, maybe one of the forum heavies will put this straight....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Bad spellers of the world untie!
·...so I changed it to this, which also doesn't work:
...however if I change it to this, now it works:
All I did was move the AbsSpeed assignment above the if, instead of below, and it does what it's supposed to.· Am I misunderstanding something, or is this indeed a PropTool compiler bug?· This is with both V1.1 and V1.2.5
Jason
·
"a >= b" means "a := a > b"
I think you want to use => ("greater than or equal")
While this is probably going to sound like sour grapes, making operators that are visually equivalent to another language (C/C++) that have dramatically different meaning seems like a bad idea. At the very least, a compiler warning that I was doing an assignment in a conditional statement might've offered a clue.
I also recently discovered that >>= is shift right, while ~>= is arithmetic shift, as opposed to doing them the other way around and following the C/C++ convention for the arithmetic shift. I understand that it's too late to change this (existing code written to spec would break) but again, a compiler warning could be useful here too.
Complaints aside, thanks for telling me that - It explains a lot, and hopefully I'll remember for next time. [noparse]:)[/noparse]
Jason
Besides, Spin is just taking C's op= notation to its logical conclusion.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
I'm not really complaining - I expect a learning curve, but I've been bitten by a few things like this that seem like obvious no-no's to me.· I'm also biased because I know C/C++/C# quite well, and all of them have very similar operators.· I'm not familiar with other languages that might have influenced the design of Spin, so maybe there are solid reasons I'm not aware of.
Jason
·