Controlling a large motor with a 28X2


Senior Member
;This is Test circuit for the DC Motor Driver MD20A copied from page 173 in Manual 2 covering the pwmduty command

;C.4 connects to direction pin on MD20A
;C.2 connects to PWM pin on MD20A
;pmduty is 0 to 1023
#picaxe 08m2

init:    pwmout C.2,100,150    ; start pwm

main:  high C.4        ;CCW Rotation
    pwmduty C.2,300        ; set pwm duty
    pause 3000        ; pause 3 s
    low C.4        ;CW Rotation
    pause 3000        ; pause 3 s
    goto main    ; loop back to start
Here is the link to the video test.

We're pretty happy with the test. It actually works!
Here we want to change up to a 28X2...........
Pictured below is the 5k slave pot mounted at the pivot point of the large gear. The three leads can also be seen;


With 5 volts across the slave pot, the wiper reads 1.2 volts (1.12k) full left side, 2.5 volts (2.41k) center, and 3.7 volts (3.65k) to the far right side.
The plan is to move the slave pot (B.0) with a 5k control pot (B.1) using a pwmduty command to the MD20A motor driver (C.1)
The MD20A also has a direction pin (B.7) which is high for CCW and low for CW rotation.
Last edited:


Technical Support
Staff member
If I have understood what you have and want correctly; I presume you want to be able to move your mechanical contraption such that it points how your target pot is set. So you set the desired position on the control pot and turn the motor until the feedback pot matches.

There are going to be a number of parts to that. You won't need to use a comparator input because the pot control and matching will be done in software.

The first thing which needs to be done is to read both pots and normalise those, so both have the same values when fully left, centred and fully right. The desired position pot should be simple enough as it will have full range 0 to 1023 when read with READADC10. The feedback pot reading will need processing to normalise it because it has a restricted range.

Once normalised the two pot values can be compared and which direction the motor has to be turned in can be determined. The motor can then be turned with speed control and stopping overlaid on top.

There are going to be a number of program parts to all that but it can be approached from a top-down perspective where the parts can all be added and tested incrementally. The main program will probably be something like -
  Gosub ReadDesiredPostion
  Gosub ReadCurrentPosition
  Select Case currentPosition
    Case  < desiredPosition : Gosub TurnClockwise
    Case  > desiredPosition : Gosub TurnAntiClockwise
    Else                    : Gosub StopTurning
  End Select
Then it's just a matter of creating the routines to do those things and adding the variables used to do it.

The first step would be to create the ReadDesiredPostion and ReadCurrentPosition routines, check they work. I will have a think about the maths required to normalise the feedback pot value.