Need additional help on "Secrets Of Arduino PWM"

I'm controlling two $400.00 linear actuators for a senior project and I'm wanting to give this actuator the best PWM signal it can possibly have. I'm reading up on "Secrets Of Arduino PWM" and I really need some extra help and additional examples to increase my learning curve on these Timer Registers. I've busted out the datasheet for the ATmega328P and at points its very hard to follow. The author of the article even admits there needs to be an official write up on these paramters.

Can anyone help point me in the direction of more verbose information on controlling these timer registers and how to PWM with this option. Although the author goes to great extents in explaning "FAST PWM", "REGISTER CONTROLLING , etc ,etc" I could really use more resources and its been hard finding that information so far.

Here is the link to the Article if you need to refer to it.

my actuators.

Quite a bit of information here: Gammon Forum : Electronics : Microprocessors : Timers and counters

If you still have questions come back with something specific, not just wanting "the best" signal. Talk about frequencies, duty cycles, that sort of thing.

You can do a lot of stuff with the hardware, some of it is a trade-off between frequencies, and duty cycle resolutions.

Perhaps it would be better to approach the problem from the other end. What do your linear actuators need? Do you have a model number and make for your actuators?

In answer to your last question...

Here are the specifications of my servo

Looks like you overpaid - they are shown there as only 1$130.
Maybe replace the pot in the controller with a digital pot that you can control.

Yea not for sure what happen there. They were priced at 180 and we bought two for a total close to $400.00. I believe they require a 25% duty cycle on and 75% off. I can't find out much on the frequency. Also is there any way I can achieve a faster speed besides the obvious of going up in Voltage and Current?

Hi, from what I see you will be using an arduino to control the speed and direction of the motor, using the actuator pot as the position feedback.
You will also have an input indicating the required position.Am I right?

If so;
Why do you need to play around with the PWM, use a PWM library in the arduino sketch.
Or built or buy a motor controller for actuator motor and connect it to the outputs of the arduino.

If you think it is not the best PWM you can offer? What is your criteria?
Have you checked if the supplier of the actuator has a suggested controller?

Or have I got it wrong.

Tom… :slight_smile:


You have it right. I will control it with a Arduino Uno and I do have a motor shield. However, for learning purposes I was really wanting to experiment with the timer registers. I will though test out the actuators using the servo library for starters.

To control it, you need to make an H-bridge, which is what the Digital Manual Controller provides.
Pretty hefty one at that:
Current drain (12V): 3.8A operating full load
Current drain (12V): 15A at stall

You can check out what's involved in that from these controllers:

It's not a servo:
"All you need to do in order to get your actuator up and running is apply 6-12VDC to the positive (red) and negative (black) wires."
You supply voltage to Red & one black wire, it moves one direction.
Swap the red & black wires, it moves the other direction.
That's what they are illustrating with the switch in the middle of the page.

I pasted in the wrong actuator.

Here is the correct link. Apologies

You guys really gave me alot of information so thanks. I will take a look into the links and get back with yall when I have more specific questions. Right now I just need to do more tinkering and reading on your suggestions. Thanks again everyone.

Hi, that changes the situation completetly.
The PWM signal you need you will get from the servo library, it outputs the PWM signal suitable for a servo, the unit you have has the motor control driver inside.

It only needs the servo control from the arduino set with something like a pot control to an analog input of the arduino.
Changing PWM frequency will not effect the motor response.
It looks like the servo you are using uses the 150mS as neutral the same as the arduino servo library.

Tom..... :slight_smile:


Could you explain that setup with pot and analog pin out a bit more. Maybe a sketch or example. Not quite understanding why i'm incorporating a pot and exactly where i'm suppose to do that.


Will get you started, also google arduino servo will give you examples of how to control a servo.

Tom....... :slight_smile:

As it is a senior project, you will have to do the work, we can supply advice and guidance but it has to be your work.
Consulting your tutor, lecturer, teacher will also help.

I’m getting a 24kHz pwm signal and I have a 20k pot that I can successfully dial in any duty cycle I want. The datasheet for my actuator requires the following or you can refer to the above links as well.

Control System: PW Control 1500us is Neutral
Required Pulse: 3-5V PP
Fully Retracted: 2000us Pulse Width
Half Extended: 1500us Pulse Width
Fully Extended: 1000us Pulse Width
Dead Band Width: 8us
Pot: 10Kohm
Duty Cycle: 25% (25%on, 75%off)


I’m not understanding these parameters because with a 24kHz pwm signal I can’t achieve a pulse width above 41.67us since obviously my period is this.

Secondly, say I do achieve a pwm signal to extend or retract the actuator how am I suppose to maintain a 25%on and 75% off pattern while changing up the pulse width.

I’m missing something here and could use an explanation to clear this up.

Below are pics on what I have already with a 24kHz signal at 25% duty cycle. Again I have a 20k pot hooked up to A0,gnd,5V and i’m using PWM pin 9. Below you will also find my code. I’m using a different library which performs on a lower level from what i’m understanding. You can view the library here…,117425.0.html

Also i’m not understanding why I should divide my analog value by 4. I thought this was only if you want to save the value to EEPROM memory?!?!

#include <PWM.h>
int32_t frequency = 24000; //Frequency in Hz

void setup()
	InitTimersSafe(); //initialize all timers except for timer0, to save time keeping functions
	bool success = SetPinFrequencySafe(9, frequency); //set the frequency for the specified pin
	if(success) //if the pin was set correctly do this so i can visual confirm the results of the previous funtion
    pinMode(13, OUTPUT);
    digitalWrite(13, HIGH);    

void loop()
	int sensorValue = analogRead(A0);
	pwmWrite(9,sensorValue/4); //using this function instead of analogWrite
	delay(30); //don't understand why i need to delay this but doing it anyways

Secondly, say I do achieve a pwm signal to extend or retract the actuator how am I suppose to maintain a 25%on and 75% off pattern while changing up the pulse width.

Change the frequency, keeping the output on-time at 25%.
If that's what's needed.

The signal that of a rc servo variety is used to POSITION the device.

For the duty cycle you will have to keep a running tab. If the arm is stationary then that does not add to the duty cycle.

Only when the arm is MOVING does the duty cycle come in.

How often do you plan on moving this?

There are two actuators that are connected to a metal frame. They raise and lower the frame together acting as one kind of like a hydraulic bed on a truck. I need to incorporate some kind of trigger (push button, joystick, etc..) to raise and also lower the metal frame in increments or too a position that is desired. Probably will need two buttons. One to raise in increments and another to lower in increments.

If the 2 actuators are to act as one then do like some of the 3d printers do for the Z axis. drive them from the same signal.

Beware when hooking them up to the Arduino- the units hace a BEC that PUTS voltage on the plus line of the servo cable.

Hi your analog input is 0 to 1023, I the pwm output is 0 to 255, hence div by 4.
You could also have used the map function but div should work

can you post a copy of your circuit please can you see the voltage at A0 changing as you adjust it?

A CAD or hand drawn pic in jpg, png or pdf would be okay.

Tom..... :slight_smile: