sending pulse width signals to an HB-25 in Propeller C
doug.taylor
Posts: 31
I haven't found in the forums an example of sending pulse width signals to an HB-25 in Propeller C.
Doug
Doug
Comments
Another option is to use spin2cpp to convert a Spin PWM object to C.
You may also want to browse the learn libraries. You can find some servo control code here that might work.
http://www.parallax.com/news/2013-12-23/run-activitybot-c-code-arlo
Ken Gracey
SLRM, thanks for the reply. I appreciate ANY reply so don't be shy. Your approach using the C++ solutions looks promising, but I'd like to try the path that Andy suggested first since it is more out-of-the-box. If it doesn't work, I'll revisit this.
Andy, Thanks for the reply. I had gone down this path and could not get it to work. One of my test programs looked just like your sample but when I ran it the HB-25 never put any voltage out of the motor leads. Then out of desperation I copied your code over mine and behold, it worked. Now I can't go back to mine to see what I was doing wrong. It must have been something stupid.
By the way, I could never get servo_setramp() or servo_get() to do anything. Should these work in continuously rotating servos like that which the HB-25 emulates?
Thanks,
Doug
Thanks for the update, that's great news.
I usually let my program run for a few seconds to make sure the servo pulses are present before turning on the HB25 power. If the HB25 wakes up and sees control pulses immediately, it will work. If it does not see control pulses, it has a built-in safety feature that makes it unresponsive until you restart with control pulses applied.
Not sure, but maybe the HB25 was already not responding by the time you tried out the program that matched mine. Maybe the power-up sequence was more favorable the second time around.
The servo_setramp function is a way to set the largest change in angle/speed per 20 ms. It defaults to 2000 (no limit). If you reduce it and then set your servo for a significant speed, change, the resulting change should be slow instead of sudden. You only need to set it once.
The servo_get function should tell you the current setting, in pulse width microseconds. So, int pulse = servo_get(14) should give you the pulse width of the servo signal going to P14. That should be 1500 + speed.
Here is a program that sets the ramp step to 1 us/20 ms, then very slowly goes from 0 to +500. It uses servo_get to get the current pulse width, and displays it with print. The pulse width should run from 1500 to 2000 in steps of 1 per 20 ms. The samples are taken every 100 ms (plus serial communication time, so slightly slower), so they should increase by about 4 or 5 per measurement. Your motor speed may stay at 0 and then suddenly start turning because DC motors will stay still up to a point, and then start turning.
After the loop gets to 2000, another setramp call changes the ramp step to 10 us/20 ms, and so the speed change will be a little quicker, but still comparatively gradual.
Andy