The square wave output frequency on Arduino digital pin is different than the set frequency on Simulink model

9 次查看(过去 30 天)
I am running a 4.4V 2A stepper motor with 1.8 deg step angle using Arduino Uno with Geckodrive G201X as the stepper motor controller. As a step input to the motor controller I am generating a square pulse of 10kHz on Simulink and sending the signal to the digital output block from the support package. When I run this model on external mode, I used a picoscope to check the waveform on the digital pin and I see the square waves are not consistent and the frequency is much lower than what is set. I am new to this interface and therefore would appreciate any help on this. I am not able to run the motor at different speeds by changing the square wave frequency to the step input to the motor controller. Why does this difference in frequency occur between Simulink and Arduino?
I have attached an image which shows the square wave observed from picosope on the digital pin which was set to output a 10khz sqaure wave to the motor controller.

回答(1 个)

Saurav
Saurav 2024-2-16
编辑:Saurav 2024-2-16
Hey, Tariq Ali,
I understand that you are trying to control the speed of the stepper motor using an Arduino Uno in external mode using Simulink. You are facing issues with the actual frequency not being consistent with the set frequency and also not being able to vary the speed of the motor by varying the square pulse frequency.
I assume you are using the PWM block to vary the frequency. It is not possible to change the frequency via the PWM block; since the signal is generated from the PWM block, it is expected to be stable.
Changing frequency during run time requires significant overhead in re-programming the timer parameters, and the underlying infrastructure does not provide the support for this.
Please refer to the following workarounds for obtaining consistent frequency at the digital pin:
  • It depends on the sample rate of the model to determine what upper band of frequency can be realized. Generally, to generate the 10 KHz frequency, the sample time should be less than 50 microseconds.
  • There could be other latency due to the operating system being used. I would suggest playing with the model step rate, starting with the minimum frequency, and scaling up the value of frequency. Check the threshold at which things run out of order; that would be the defining point for the maximum frequency generation.
  • Ensure that the baud rate used for communication between Simulink and the Arduino is high enough to support the data throughput required for real-time operation.
For more information, you can refer the following documentation:
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by