Control a Servo with Speedgoat IO135

9 visualizzazioni (ultimi 30 giorni)
Alex
Alex il 5 Mar 2025
Commentato: Alex il 6 Mar 2025
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!

Risposta accettata

Dimitri MANKOV
Dimitri MANKOV il 5 Mar 2025
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

Più risposte (1)

Alex
Alex il 5 Mar 2025
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 Commenti
Dimitri MANKOV
Dimitri MANKOV il 6 Mar 2025
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 il 6 Mar 2025
Yes, that makes sense. Thanks for your answers!

Accedi per commentare.

Categorie

Scopri di più su Hardware-in-the-Loop Simulation with Simulink Real-Time in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by