Welcome! Log In Create A New Profile

Advanced

How to control servo from Duet board

Posted by burnpanck 
How to control servo from Duet board
May 05, 2015 11:42AM
I would like to control a number of standard servos (as commonly e.g. in remote controlled model vehicles) with my Duet.
I will try to do the modifications to the Duet firmware myself. I do have some experience with Atmel microcontrollers, but
mostly with their 8bit AVR's. Since I neither know the ATSAM3X nor the firmware, I'm looking for some pointers into
what hardware is currently used and what is still available.
These servos take a pulse between 1ms and 2ms in length to indicate the desired position, this pulse has to be repeated every 20ms,
though the repetition period is non-critical. Ideally, one would use a hardware PWM for this, but with the Duet+Duex4 combination,
it seems they are essentially all reserved for the 6 heaters and the fan. Alternatively, a software PWM could be enough, though
the 1ms tick certainly does not give enough resolution for the pulse width. Is there another interrupt running at a higher rate? Or is there
a free hardware timer that one could use for this purpose? The last option would of course be to simply add a dedicated
8bit microcontroller attached to one of the serials or SPI ports.

Thanks for hints!
Re: How to control servo from Duet board
May 05, 2015 12:28PM
If you are going to modify the firmware anyway, then unless you are actually using all 6 heaters, I suggest you repurpose some of the heater PWM pins to drive your servos. The last 4 heater mosfets live on the DueX4 expansion board, so the corresponding PWM outputs appear on the expansion connector, where you can easily connect to them. They are 3.3V logic level, so you may have to level-shift them to whatever voltage your servo control inputs need.

To program them, if a resolution of 1 part in 255 is sufficient, you can just call the analogWrite function in the Arduino core.

Hope this helps!



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: How to control servo from Duet board
May 05, 2015 02:24PM
I should certainly do that. I was intending to upgrade to three or four hot-ends at some point, and at the same time have say space for four servos. Since Expansion1 on the Duex still carries some general-purpose pins, I thought I could software-PWM them. Also, I was thinking of sacrificing the fifth and last extruder for it's four stepper motor control pins. But currently I'm learning my second extruder, so for first experiments the heater PWM would certainly do. In any case, I'd need to build a modified Duet-Duex4 ribbon cable that cuts some of the higher extruders. One question though: I thought the hardware PWM's share their timer, at what frequency are the heater PWM's running? I'm afraid they run in the kHz range, which would be too fast for the servos...
Re: How to control servo from Duet board
May 05, 2015 04:33PM
There are 2 clocks to the PWM subsystem. In my fork, one is set to give 1kHz PWM for the heaters, and the other for 25kHz PWM for a 4-wire fan. These are the frequencies you get when the PWM period is 255, which is what the heaters and fan use. But you can use higher periods, up to 65535, and the PWM frequency will be correspondingly lower. This means that you could get PWM frequencies down to about 4Hz if you use the clock that is set up for 1kHz operation. Or, if you don't plan to use 4-wire PWM-controllable fans, you could change the clock meant for 25kHz PWM to something lower.

There are also three CTC channels which can be used for PWM, but I've not checked whether the corresponding output pins are available on the expansion connector.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: How to control servo from Duet board
November 09, 2015 07:55PM
Hey Dave - thanks for the information above - ZPL has been working with me and I am nearly done getting my Prusa - Krakken to come to life - one of the very last topics is the Z Probe for my machine. Since this was built as a Prusa I replicated what I knew which was all Marlin style.... Now with a Duet I need to figure out how to setup the auto-bed leveling for this machine....

First part before anything can happen is the servo to get connected - Chris has suggested exactly what you said here - so I am going to use Extruder 4's heater connection. I just need a little hint on something.... The little micro servo like what Burnpanck writes about is what I am using as well. It rotates down and has a little limit switch attached. Probes how ever many points I tell it and then the firmware will need to use that number minus the Z height differnce etc etc. All stuff you know better than I do.

My question is the servo has 3 wires - a red (pos/Power) - a black (neg/Ground) and lastly a White wire - which I can only assume is signal. I may be wrong but can you tell me which three pins on my Duex4 expansion to plug these into? Also a sample of gcode to use to test and work with to rotate it up/down?

Appreciate all that you have helped with so far!
James
Re: How to control servo from Duet board
November 10, 2015 03:42AM
I can't help you with servo wiring because I have never used them. If you are only using the servo to deploy a Z probe, have you considered using one of my IR sensor Z probes instead? E3D originally planned to use a servo deployed switch for their BigBox printer, but now they are supplying this instead. See [miscsolutions.wordpress.com].

Edited 1 time(s). Last edit at 11/10/2015 03:45AM by dc42.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: How to control servo from Duet board
November 10, 2015 04:50AM
I'm not sure, if a simple PWM signal would work.
A servo needs 1-2ms signal length, not a "duty cycle" of x.xx%
You would need a timed signal that fits in the general interrupt service routine.
-Olaf
Re: How to control servo from Duet board
November 10, 2015 08:57PM
For all the trouble it will be worth on that little limit switch - yep I am going to convert to the IR Sensor Probe - placing order now! Might get a second one for the other printer too!

Going to need to dig thru the manual to understand how I should set this up.
James


Quote
dc42
I can't help you with servo wiring because I have never used them. If you are only using the servo to deploy a Z probe, have you considered using one of my IR sensor Z probes instead? E3D originally planned to use a servo deployed switch for their BigBox printer, but now they are supplying this instead. See [miscsolutions.wordpress.com].
Re: How to control servo from Duet board
July 19, 2016 10:14AM
Any updates on this ? Anybody managed to control a servo with the Duet ?

I would also like to do some plotting with my printer, and a servo controlled pen would be much faster than moving the 8Kg Z axis up and down all the time.
Re: How to control servo from Duet board
July 19, 2016 02:26PM
Why not use a linear actuator to move the plotter pen up/down? This would be much easier to implement.
Re: How to control servo from Duet board
July 20, 2016 09:25AM
Quote
o_lampe
Why not use a linear actuator to move the plotter pen up/down? This would be much easier to implement.

Maybe electronically. Mecanically it's way easier with a servo. And the servo are already lying in the drawer. Maybe would be easyer to interface an ATTiny between the servo and the Duet ...
Re: How to control servo from Duet board
July 20, 2016 11:38AM
The ATtiny would be handy, since the analogWrite function doesn't work for servos. You'd need one of the many servo.h lib's.
Re: How to control servo from Duet board
July 20, 2016 01:57PM
Just use one of these: [www.sparkfun.com]
Re: How to control servo from Duet board
July 21, 2016 12:40PM
Quote
o_lampe
I'm not sure, if a simple PWM signal would work.
A servo needs 1-2ms signal length, not a "duty cycle" of x.xx%
You would need a timed signal that fits in the general interrupt service routine.
-Olaf

Somebody has used one of the two PWM fan outputs on a Duet 0.8.5 to control a servo, by setting the frequency to a suitable value (about 50Hz AFAIR) and then adjusting the PWM factor to get the 1 to 2ms pulse. The resolution was quite low because the PWM resolution is only 8-bit. In a future firmware release I'll either increase the PWM resolution, or add a facility to re-purpose one of the fan outputs as a servo output, using one of the two existing M-codes that control servos.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Sorry, only registered users may post in this forum.

Click here to login