views:

113

answers:

2

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

+1  A: 

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.

Amardeep
A: 

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.

phkahler