Control a Servo with Speedgoat IO135

17 次查看(过去 30 天)
I am trying to control a simple servo motor (FS90R) using MATLAB Simulink and a Speedgoat IO135 machine, but I can't figure out how to output the appropriate PWM signal. The built-in Simulink PWM block does not compile for the IO135 machine. Does anyone have any tips on generating a 50Hz signal with 5-10% duty cycle for controlling the servo? Thanks!

采纳的回答

Dimitri MANKOV
Dimitri MANKOV 2025-3-5
Hi Alex,
The best way to generate PWM signals with a good time resolution in Simulink Real-Time is to use one of Speedgoat's configurable FPGA I/O modules together with an FPGA configuration file (bitstream) containing the PWM code module. The reason for that is the following: even if the switching frequency of your PWM signal is low, you need to sample it at a significantly higher rate to obtain a good timing resolution.
For example, if you have a PWM signal with a period of 20ms (which seems to be your use case) and want to obtain a duty cycle resolution of 1% or below, you need to sample your signal at least 100x faster, i.e. every 0.2ms (5kHz). In your specific case, 5kHz should be still be manageable to run on the CPU/model level to set/reset the digital output signal of your IO135 module every 0.2ms (for example using a "Pulse Generator" block), but the precision will be limited. If you are interested in sampling frequencies in the 50-100kHz range and above, your CPU will not be able to keep up with the sampling rate of the model and you will need to delegate the sampling of the PWM signal to a configurable FPGA I/O module.
I hope this is helpful!
Dimitri

更多回答(1 个)

Alex
Alex 2025-3-5
Hi Dimitri (or another responder),
Thanks for your response, that makes sense to me. It seems like there is no way to use the Digital IO pins on my IO135 machine to generate the required PWM signal. However, is there a way to use an Analog Output pin to generate the PWM instead, even though it is a digital signal? The IO135 Analog Output pins have 200 kSPS which is plenty fast enough.
Thanks!
Alex
  2 个评论
Dimitri MANKOV
Dimitri MANKOV 2025-3-6
Hi Alex,
It feels wrong to mis-use an analog output channel this way. Besides sampling rate considerations, there is also the quesiton of synchronization, i.e., of making sure that the frame of "high/low voltage" values passed to the IO135 module is generated correctly and output without any time shifts. Moreover, this approach would require you to use DMA, which will generate a 1 model step delay in your algorithm. While it might work, it just doesn't feel like a clean solution.
Dimitri
Alex
Alex 2025-3-6
Yes, that makes sense. Thanks for your answers!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Real-Time Deployment and Code Generation 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by