3

I'm very new to arduino related stuff so this question might be really easy to answer. I don't understand how multiple PWM outputs are supposed to work. Look at the pic. enter image description here

In the first(1) case we are using short signal width which would be close to motor staying still. In this case, as can be seen, short pulses follow each other, so does the code.

motor1.writeMicroseconds(shortWidth);
motor2.writeMicroseconds(shortWidth);
motor3.writeMicroseconds(shortWidth);
motor4.writeMicroseconds(shortWidth);

when motor4 ended it's output, motor1 starts it's pulse again causing non-problem consequent pulses.

In the second(2) case pulse is wider which corresponds to setting motor speed close to maximum. After motor1 finishes generating width, it's time for motor2 to generate one. But when it does, motor1's period comes to end and it has to start generate width again, but arduino is busy generating pulse of motor2.

How does PWMs work in this case?

asked Jan 10, 2015 at 21:36
3
  • are you trying to understand how the servo library manages multiple ppm/pwm signals at once? Those writeMicroseconds calls don't directly relate to any change in the output state of a pin. They just reconfigure the servo lib's signal generator that uses interrupts to change the pin when a certain amount of time has passed. Commented Jan 10, 2015 at 23:23
  • Thanks, that actually clears some things up. Still it's interesting to dig a little deeper and to know how same timer manages to make a pwm signal at once. Commented Jan 11, 2015 at 0:24
  • 1
    The timer interrupts routine get called every X microseconds. This routine increments an counter. Loops through all servos and sees if the PWM value for that servo is greater of less than the counter value. If less, write a HIGH to the pin associated with that servo, otherwise write a LOW. The actual code is a bit more difficult, but that is the gist of it. Commented Jan 11, 2015 at 12:38

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.