I'm trying to control a large stepper motor with high frequency pulses (eventually around 4kHz), but what I get out of the simulink scope is super different from what the Arduino is putting out. I'm using this variable frequency PWM block: www.mathworks.com/matlabcentral/fileexchange/48563-variable-frequency-pwm-block

enter image description here

(yes, I've tried it on pin 5/6, but if I do that there's no difference)

This is the output from the Simulink scope (period of 0.01s):output from scope

and the Arduino is putting out pulses with a period of ~4 seconds. This is on pin 6 of the Uno, by the way. Why won't the Arduino output the same frequency as the Simulink program?

  • 1
    Please amend your question and post the Arduino code. How can we tell what it might be doing without seeing the code? What did you get out of the Simulink scope?
    – Nick Gammon
    Commented Aug 4, 2015 at 23:32
  • I've added the simulink program (didn't use Arduino code)
    – mr.519
    Commented Aug 5, 2015 at 14:07
  • Why won't the Arduino output the same frequency as the Simulink program - I don't understand your question. You are asking why the Arduino won't output a certain frequency, but you are not using Arduino code? Well, without code it won't output anything. Perhaps if you clarify.
    – Nick Gammon
    Commented Aug 5, 2015 at 20:44
  • It is outputting something, because I'm using a physical oscilloscope to measure the output (and my stepper motor is moving, just really slowly). Not 100% sure how it works, but I think Simulink uploads code to the Arduino because the Arduino gives the same pattern of blinking light as it does when Arduino code is uploaded. If you've done this before, do you need to use Arduino code too?
    – mr.519
    Commented Aug 5, 2015 at 20:56
  • 1
    Yes, Simulink generates code from my block diagram. And I've been switching between pins 11 and 6, so the pictures aren't consistent, but the output is the same :(
    – mr.519
    Commented Aug 6, 2015 at 0:59

1 Answer 1


It seems clear from what you have described that this is a Simulink bug.

Why won't the Arduino output the same frequency as the Simulink program?

The Arduino can output quite a lot of frequencies. I have a page about Arduino timers which describes them in some detail.

However since Simulink is generating the code for the Arduino (which we are not being shown) and since it claims to be generating 0.01 s, and the code it is generating does not do this, that is a bug in Simulink.

I suggest you contact their customer support.

Alternatively you could attempt to program the hardware timers yourself. The page I linked could be a good starting point for such an exercise.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.