# DC motor ‘servo’ position control

89 views

### Toby Vernon-Smith

Jun 18, 2023, 3:38:58 PM6/18/23
Im trying to understand simple PID control and I’m trying to control a Hella turbo actuator which consists of a DC motor with a gearbox and position sensor on the output shaft. The output is 1kHz PWM. I’ve scaled the output to 0-100% and use the same 0-100% set point as a set point. (I’ve actually used 0-1000 to give better resolution with out using floating points).
Control is an Arduino and dual H Bridge and to try and understand it, Ive written a very simple P only controller. I’ve got it working, but it’s very basic with the PWM signal proportional to the difference between the current position and the set point. I’ve constrained this up to 255 and also have a P term. Direction is determined as to if the set point is greater than or less than the current position.
I’m struggling to understand how to take the next step. The problem is, if there is a load on the shaft the torque can become insufficient to achieve the set point. But if the PWM value is scaled up to provide an increased torque, when there is no load it overshoots massively - often jamming the gearbox (limited rotational travel). I can use a PWM upper limit of about 120 with no load. It also doesn’t have enough torque for small movements unless the P term is quite large but this then causes occasions.
If I use the PID library, do I use the output as the PWM value (scaled 0-255) and direction based on the same principle as before? To achieve greater torque, do I need to use a larger P term but then ‘dial back’ the speed (overshoot) with the D term? And for small changes to the set point, I presume the Integral term will let me achieve these?
As you can tell, I’m very new to this!
Thanks! Toby

### Steve Edmonds

Jun 18, 2023, 4:58:59 PM6/18/23
Have you looked at servo control libraries which may be more appropriate
for motor position control.

### Toby Vernon-Smith

Jun 19, 2023, 3:20:59 AM6/19/23
Thanks for the reply…
I’ve just looked into servos but understand they are simply PWM controlled with a single signal wire - with all the feedback/control taking place internally in the servo.

I’ve basically got the same hardware but electrically wise, I have a position output (1kHz PWM) and two wires directly to a DC motor.

> On 18 Jun 2023, at 9:58 pm, Steve Edmonds <st...@edmondsfamily.co.nz> wrote:
>
> ﻿Have you looked at servo control libraries which may be more appropriate for motor position control.
> --
> You received this message because you are subscribed to the Google Groups "DIY PID Control" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to diy-pid-contr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/diy-pid-control/c94968e9-363e-6aab-0723-27e24117b3f3%40edmondsfamily.co.nz.

### Steve Edmonds

Jun 19, 2023, 5:47:39 PM6/19/23
I found some DC motor servo drive examples with DC motor +/- and H drive.
I also saw that Hella has different actuators, some with PWM input (3
wires) and CAN communications and some with DC motor (2 wire +/-
terminals). I assume you have the latter.

### Toby Vernon-Smith

Jun 20, 2023, 2:45:54 AM6/20/23
Yes, I haven’t been able to find very much on Hella actuators but there are two types - SREA (Smart Rotary Electronic Actuator) and REA. The ‘smart’ ones are supposed to work with both PWM input and also CAN Bus. The REA has no control hardware built in and is the type I’ve been trying to use.
I have bought a SREA but it refuses to work with PWM despite trying different frequencies etc. I even sent it to be tested and it’s came back as working OK. Normally they are operated by CAN Bus. I wonder if PWM input isn’t an option on some versions.

> On 19 Jun 2023, at 10:47 pm, Steve Edmonds <st...@edmondsfamily.co.nz> wrote:
>
> ﻿I found some DC motor servo drive examples with DC motor +/- and H drive.
> To view this discussion on the web visit https://groups.google.com/d/msgid/diy-pid-control/dc025d62-3b14-6a40-3c41-0b8d09564c02%40edmondsfamily.co.nz.

### Steve Edmonds

Jun 20, 2023, 8:30:17 PM6/20/23
Searching for "arduino servo dc motor control library" and "arduino dc
motor valve position control" I found a number of examples using PID and
possible H bridge. A number use the L298N but this may not have enough
drive for you.
I don't know if this library suits but some H bridge drive circuits.
https://projecthub.arduino.cc/ambhatt/dc-motor-controlling-library-c784c8

How fast do you want the actuator to respond?

### Toby Vernon-Smith

Jun 26, 2023, 2:48:54 PM6/26/23