Hi all,
I'm faced with a problem - some friends and I are building a semi-autonomous airship (only a little one) and I've been given the electronics and programming to do, but I'm having trouble getting the pwm commands to work properly.
I'm using a little joystick with 2 pots to control it, the y-direction one controls the overall speed and direction of both motors and the x-direction one puts a left/right bias on them to turn the thing.
Here's the bit of test code I've got with just the one pot being used
[code]
symbol zero1 = b1
symbol zero2 = b2
symbol value1 = b3
symbol value2 = b4
symbol diff1 = b5
symbol diff2 = b6
symbol offset1 = b7
symbol offset2 = b8
init:
readADC 1,zero1
readADC 2,zero2
main:
readADC 1,value1
readADC 2,value2
if value1 > zero1 then
diff1 = value1 - zero1
offset1 = diff1 * 16 / 10
hpwm 0,0,%0001,96,offset1
hpwm 0,0,%0100,96,offset1
elseif value1 <= zero1 then
diff1 = zero1 - value1
offset1 = diff1 * 16 /10
hpwm 0,0,%0010,96,offset1
hpwm 0,0,%1000,96,offset1
endif
goto main
[/code]
The binary strings in the hpwm commands correspond to the direction of each motor (0001 is A forward, 0100 is B forward, 0010 is A back and 1000 is B back)
My problem is that when both motors are controlled by the one command (0101, 1001 etc) everything works fine, but when they are separated like this, one motor goes a lot faster than it should and the other barely moves, it's the same in both directions.
The faster motor corresponds to the 00xx binary position.
I'm stumped, can anyone help?
Mike