I need programming help

Hello everybody,

I'm a hobby cinematographer and currently building a Steadicam rig. It's a mechanical system on which the camera gets balanced and it is used to archieve very steady shots - hence the name. However, it is really important to not touch the camera once it is mounted on the rig, which makes pulling focus really hard. To solve the focus problem I am now building a remote controlled focus motor which grips into the followfocus gears on the lens by mounting a rc-motor on a modified manual followfocus knob. For the motor I plan on using a sensored brushless motor with a low kv-rating and high torque (I can't gear it much because it needs to stay as quiet as possible). A brushless motor obviously needs an ESC and I need an arduino to translate the standard rc-pwm signal which corresponds to a possition on the focus scale (so basically a position where the motor has to be) to a motor output by looking at where the motor is and where it has to be and calculating said output. So far the theory of the project.
The motor I look forward to using:
5053 125kv Sensored Brushless Motor

Now on to my problem: I am very much a hardware guy and while I have basic knowledge of arduino programming, this project kinda goes over my head. While researching I have found out that it makes most sense to implement the ESC aka motor controller into the arduino, which would also mean that the sensor of the motor can be used also as a sensor to find out where the focus is in relation to where it should be based on the rc-receivers pwm-signal. I have found out that someone has already programmed a sensored ESC in an Arduino: BLDC motor control with arduino

So in short: I need someone who can program me a program that will, when powered up, run the motor in any direction 'till it recognizes that the motor doesn't turn anymore, than run the motor in the other direction 'till it hits the other end of the focus scale on the lens, then map the distance between the two stops to the rc-pwm input coming from the rc-receiver (1000-2000us) so that if the input pwm signal has a pulswidth of 1000us it will drive the motor all the way to one side and if the input pwm signal has a pulswidth of 2000us it will drive the motor all the way to the other side, and at 1500us it will drive the motor to the middle and so on. Oh and the motors PWM-signal needs to be so high that the "whining sound" of the motor is inaudible (so above 20.000Hz) (see the video in the second link above to hear what sound I mean).

It would be really awesome if someone could help me and I'd be super grateful.
Regards, Timo

The behaviour you describe is more akin to a servo, they do use pulse length to set the direction. Brushless motors just don't work that way.

What the software would have to do is count revolutions, which looking at the code you linked to appears feasible. The motor has the hall effect sensors that are normally used to know which of the coils to power, but of course it's quite easy then to start counting how many revolutions one has done. End of rotation could then be sensed by a stopped motor and no new sensor input.

So basically turn one way until no sensor input (motor stalled). Then turn the other way, counting sensor triggers along the way, until again motor stalls. That way you know how many rotations of the motor for a complete movement. It'd have to be geared down seriously, as you have only three positions per rotation, so there is no way to get any closer to a setpoint than that.

About how many rotations will there be for the motor to turn your lens from one end to the other?

As you want PWM control I suppose you want to have the motor run at different speeds (fast if you make a big change, slowing down as it gets closer to its setpoint).

Yes, I am very much aware that the behaviour is basically the one of a servo, however I can't use a normal servo because the gearing makes way to much noise. I plan on gearing it about 6:1 to 10:1, somewhere in that ballpark, with just one set of gears. Since most lenses rotate the focus ring about 180° that would make about three to five rotations for the motor. However, you do have 12 positions of the motor for every rotation as it has a set of four coils for each of the three phases (or even more actually, depending on the motors construction). And if I find out that 60 positions for the whole focus scale is not enough I could always add more gearing and make it more precise.

wvmarle:
What the software would have to do is count revolutions, which looking at the code you linked to appears feasible. The motor has the hall effect sensors that are normally used to know which of the coils to power, but of course it's quite easy then to start counting how many revolutions one has done. End of rotation could then be sensed by a stopped motor and no new sensor input.

So basically turn one way until no sensor input (motor stalled). Then turn the other way, counting sensor triggers along the way, until again motor stalls. That way you know how many rotations of the motor for a complete movement.

That is exactly what I intendet, but you described it way more understandable than me haha.

wvmarle:
As you want PWM control I suppose you want to have the motor run at different speeds (fast if you make a big change, slowing down as it gets closer to its setpoint).

Yeah, kinda. I guess it would be enough to just program a linear correlation between the motors distance to the setpoint and the motors power.

I have never opened up a brushless DC motor (I should really do that the next time one of my water pumps fails - those come with built-in controls, just connect it to 12V DC and it runs) but the schematic drawings of the things that I have seen all show just three coils, so that would make for three positions per rotation. It's the minimum to have a motor start and run, of course it's possible to have more coils but that would add quite a bit to the cost of such a motor. Stepper motors do have those great number of coils of course, and could be an alternative option but not sure how to get movement feedback from those.

For the speed control, that's another thing. PWM doesn't work on BLDC motors with built-in controls, it may work with motors that the Arduino does the control of.

Just look around here, lots of motors on which you can see they have at least three coils per phase. The variations in torque during one rotation would be to high if you only had one coil per phase. T-Motor Website

Makes sense. As said I never dismanteled one, only seen the schematic drawings :slight_smile: That's enough to understand the working principle.

This incoming PWM signal - what frequency is it running at? How fine are the gradiations in pulse width? Will the sketch need to read that signal, or do you have some sort of hardware thing that converts the PWM signal into a digital value?