何时在嵌入式处理器中使用 Simulink
我们正在 dsPIC 上开发电机控制器。我们打算使用 Simulink 对电机控制算法进行建模,并通过 Real Time Embedded Workshop 将 Simulink 模型转换为 C 代码。
我们的固件还会有一些其他的小逻辑操作,但它的主要功能是电机控制。我们想知道是否应该尝试在 Simulink 中完成所有固件,或者将逻辑运算分离到 C 代码中,而电机控制算法留在 Simulink 中? 有人建议我们应该从哪条道路开始吗?
谢谢, 布伦特
We are developing a motor controller on a dsPIC. We intend to use Simulink to model the motor control algorithm with Real Time Embedded Workshop to convert the Simulink model into C code.
Our firmware will have some other minor logic operations, but its main function is motor control. We are wondering if we should try to do all the firmware in Simulink or seperate the logic operations into C code, while the motor control algorithm stays in Simulink?
Does anyone have a recommendation on which path we should start down?
thanks,
Brent
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅供参考,我刚刚构建了一个与您类似的系统,但使用了 TI DSP。
我假设你正在做一些复杂的事情,比如矢量控制。如果是这样,您要做的就是:在您的模型中,为您需要的每项任务/每个时间段制作一个块。这可能只是带有控制的 PWM 中断。定义每个任务所需的所有 IO - 尝试将每个信号保持为 16 位,这在 DsPIC 上是原子的(这消除了大多数速率转换)。获取 simulink 以使每个顶级块成为函数调用。仅执行此/这些块内的控制,并将所有硬件配置、任务调度和其他逻辑留给 C 代码。 Simulink 可以生成 C 和 H 文件,您只需将其与其他代码一起包含在项目中即可。您将填写输入结构,调用函数,并返回包含输出的结构。保持模型不包含所有硬件依赖性。
不要相信 Mathworks 的营销人员。他们希望您在 Simulink 中完成所有工作。不要误会我的意思,它对于某些类型的事情来说是一个很好的工具。但对于模型中无法执行的操作(例如 hello world),他们建议使用“遗留代码工具”,就好像任何不是模型的东西都“完全是老式的”。将您的模型限制为控制循环和信号流(这很有用),这样就可以了。
FYI I just built a system like yours but with a TI DSP.
I'm assuming you're doing something complex like vector control. If so, here's what you do: In your model, make one block for each task / each time period you need. This may just be the PWM interrupt with control in it. Define all the IO each task will need - try to keep each signal to 16 bits which are atomic on the DsPIC (this eliminates most rate transitions). Get simulink to make each top-level block a function call. Do only the control inside this/these blocks and leave all hardware configuration, task scheduling, other logic to C code. Simulink can generate a C and H file that you just include in the project with the other code. You'll fill out a structure of inputs, call the function, and get back a structure with the outputs. Keep the model clean of all hardware dependencies.
Do not believe the Mathworks marketing folks. They want you to do everything in Simulink. Don't get me wrong, it's a great tool for certain types of things. But for stuff you can't do in the model (like hello world) they suggest using the "legacy code tool" as if anything that's not a model is "like totally old-school". Restrict your model to control loops and signal flows - which it's good for - and it'll be fine.
逻辑运算是否与电机控制相互作用,或者它们只是不相关的运算?互动的程度可以帮助做出决定。
如果它们不相关,那么为了可维护性,最好将它们排除在模型之外。然后,您可以更新逻辑,而无需为整个 SimuLink 模型重新生成 C。出现回归问题的可能性会较小。
如果它们与模型相关或交互,那么当然可以将它们保留在模型中,这样您就不会将不兼容的版本链接到构建中。
Do the logic operations interact with the motor control or are they just unrelated operations? The degree of interaction could help make the decision.
If they are unrelated then for maintainability it might be best to keep them out of the model. Then you can update the logic without having to regenerate the C for the entire SimuLink model. There would be less chance of a regression problem.
If they are related to or interact with the model, then of course it is a case to keep them in the model so that you don't get incompatible versions linked into a build.