1

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?

  • 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. – BrettAM Jan 10 '15 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. – user3081123 Jan 11 '15 at 0:24
  • 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. – Gerben Jan 11 '15 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.