Control a Servo with Speedgoat IO135
조회 수: 19 (최근 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!
댓글 수: 0
채택된 답변
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
댓글 수: 0
추가 답변 (1개)
Alex
2025년 3월 5일
댓글 수: 2
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Real-Time Deployment and Code Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!