Anyone use Matlab + Simulink + HDL Coder to make real products? - Page 1
Forum section: electronics / general

author: MagicSmoker
author_rank: Super Contributor
timestamp: December 06, 2015, 04:33:56 pm
content: Or is it just for publishing papers of questionable utility on IEEE Xplore?I ask because I am contemplating trying out this package (plus a few more relevant modules like SimPowerSystems, SimElectronics etc.) to make FPGAs that control switchmode power converters of various topologies. More than likely I would get the home edition myself, and then if I can actually make something useful it would go a long way towards convincing my business partner to ponying up for the real thing.Right now I'm just looking for success or horror stories from others.

author: 6thimage
author_rank: Regular Contributor
timestamp: December 06, 2015, 05:14:31 pm
content: You might find some people using it, perhaps for initial prototypes. But a lot of FPGA work falls into two categories - super easy, i.e. replacing discrete logic or simple interfacing between two systems, or very specialist, such as something you will find in test and measurement equipment or where their is a requirement for either high performance or low power from an unusual application (i.e. something you can't do with a microcontroller).In the first case, it is probably simpler to just write the HDL yourself (or if it is really simple, use schematic entry). For both high performance and low power, you really need to design for the particular FPGA you are using, taking advantage of its specialist hardware, which I don't think simulink etc. can do and more to the point I don't think I could trust it to do it reliably.An example of this is a complex multiplier (which I have been using for part of my work), if implemented as simple HDL it will consume a lot of resources and be fairly slow, but if you are using a Xilinx FPGA you can pipeline it a little so that it will map to one of the DSP48A slices. With 1 cycle of latency, you can use a 150 MHz clock, but pipeline it a little more so that you have 3 cycles of latency and you can get 450 MHz (btw these are figures for a spartan 6, not anything particularly high end).Now will matlab do this? If not you are throwing away performance for the sake of laziness, which no company will do. Hence why I think you might find it being used for prototypes, but not for real world products.It is also worth mentioning that university based research doesn't normally care how well something works (unless of course the end product is part of a larger project), just that it shows the novelty they are trying to demonstrate.

author: MagicSmoker
author_rank: Super Contributor
timestamp: December 06, 2015, 08:04:31 pm
content: @6thimage - thanks for the reply. I tried not to sound too skeptical with the wording of my post, but my uninformed opinion matches yours. That said, I am not too concerned with highly optimized HDL which minimizes FPGA resources, rather, I am simply trying to offload a lot of the nitty gritty of controlling switchmode power converters (plasma power sources, locomotive traction drives, etc.) from our embedded C programmer because he struggles to translate such into C code. It took him 9 months to iron out all the bugs on our last project and this is on hardware that is both very expensive and very dangerous.Thus, the solution I've been contemplating the last couple of weeks is for me to implement the core switching strategy functions in an FPGA and then have him handle all the "housekeeping" type functions such as external communications, operating envelope supervision, parametric setting, etc.A more specific, though not exact, example of what I would like to actually use FPGAs to do would be here:https://www.altera.com/solutions/industry/automotive/applications/electric-vehicles/motor-inverter.htmlYes, you can do Field Oriented Control of an AC motor with a microcontroller that costs 1/5th as much as an FPGA, but to do so your programmer needs to understand how to translate some serious math (math I am not ashamed to admit I have mostly forgotten myself) into C, and to structure the code so that loop delay is minimized AND consistent. Since we make products that are very expensive and sold in the range of 10's of units per year, it is economically justifiable to spend more on parts (ie - an FPGA) if it shortens (and de-risks!) development.However, I am unlikely to ever get proficient enough at hand-coding HDL (or even desire to) to make anything more complicated than a multiphase buck converter with an FPGA (and even then the multiphase part might be stretching it) hence why I am contemplating a model-based development environment like Matlab + Simulink etc. But I would really like to hear of others' experiences with such before I start buying dev boards and burning the midnight oil getting an LED to blink.

author: legacy
author_rank: Super Contributor
timestamp: December 06, 2015, 08:27:54 pm
content: I happened to use their DSP builder for a Job task

author: nctnico
author_rank: Super Contributor
timestamp: December 06, 2015, 08:36:22 pm
content: Quote from: MagicSmoker on December 06, 2015, 08:04:31 pmAn FPGA usually is a more risky approach than just using a big fat DSP. I'm pretty sure that libraries for motor control are also available so I'd go that route if price-per-unit isn't a big issue but development time is.

author: 6thimage
author_rank: Regular Contributor
timestamp: December 06, 2015, 09:21:49 pm
content: If you are only shifting a small number of units, and you're not going to shoot yourself in the foot with costs, then it might be a solution for you - what does it matter if no one else uses it? You just need to make sure that the extra costs do not hamper any business growth or that you have a backup plan for if it doesn't work. I have never used simulink, but if your requirements are towards its limits, you might find yourself fighting with it to make your system work. So don't rush the decision and make sure you try it properly.I have no idea of the controlling you are doing and how complex it is, but the way you said that your embedded C guy is struggling makes me wonder if it is more the programmer than the task. Perhaps, before jumping to an FPGA based solution, it might be worth reviewing his code to see its quality, to see if he is making life hard for himself or if the current hardware (or software) is hampering his work. If this is the case, then a different programmer or set up might move things along quicker. If your product has a legacy, it might be worth considering recreating the design from scratch to make life easier.I am not even going to pretend I know what field orientated control is, but your search for a consistent and minimal loop delay is something I understand. If you are using an RTOS, it will always add jitter, but I have come across time triggered systems, where the microcontroller's processing is split based on a fixed (or semi-fixed) schedule. One way is to do the time sensitive task in an interrupt (from a timer) and then always ensure that the microcontroller enters its sleep state prior to the interrupt running - then the jitter is minimised as it only relies on the time the microcontroller takes to wake up (which is pretty fixed for a lot of microcontrollers).I completely understand you wanting to find peoples experiences of matlab/simulink/hdl, but you might struggle. It might be worth trying to sweet talk the field engineers at mathworks or altera to see if you can get a demo board for a few weeks, rather than taking the plunge straight away.

author: Boscoe
author_rank: Frequent Contributor
timestamp: December 06, 2015, 09:35:00 pm
content: Surely, if you're products are high risk (high power) you should really get someone who knows what they are doing? Not just slapping an FPGA on it and auto generating code?

author: Someone
author_rank: Super Contributor
timestamp: December 07, 2015, 02:47:58 am
content: Quote from: MagicSmoker on December 06, 2015, 08:04:31 pmThe Matlab flow only takes out the effort in producing the implementation of the algorithm, you'll still need to produce quality HDL code to get the data in and out of the FPGA and do basic housekeeping tasks.

author: MagicSmoker
author_rank: Super Contributor
timestamp: December 07, 2015, 12:45:59 pm
content: Quote from: legacy on December 06, 2015, 08:27:54 pmThanks for the comment! I'm assuming you can't say too much about the job itself, but could you comment on the experience of using Matlab + Simulink + DSP Builder? Were you able to implement every function on the FPGA you needed to using the software alone, or did you have to resort to the manufacturer supplied development environment to hand-code some things?Quote from: nctnico on December 06, 2015, 08:36:22 pmYes, all the major ARM MCU manufacturers supply libraries for FOC of an AC motor, and I suspect that some of those libraries might even work halfway decently by now (they certainly didn't several years ago when I last tried using them), but the major FPGA manufacturers also supply "libraries" (aka "IP cores") to do the same, and I suspect an FPGA will run circles around a DSP in this sort of application. So I don't really see one as being more risky than the other right now, but that was the point of this thread: to inquire about the experiences of others who have used Matlab + Simulink + HDL Coder (and/or Altera's DSP Builder).Quote from: Someone on December 07, 2015, 02:47:58 amThis is the primary thing I am worried about - that I can make a lovely, elegant model-based implementation of a complex switchmode converter... and have no way to use it. Surely it isn't too difficult to implement, say, an SPI bus or specify which pins on the FPGA go to which switch driver, no?

author: MagicSmoker
author_rank: Super Contributor
timestamp: December 07, 2015, 01:37:59 pm
content: Quote from: 6thimage on December 06, 2015, 09:21:49 pmNo doubt the problem is with the programmer, but replacing him is not a great option for various reasons. He does a very good job with all the "ancillary" functions like the HMI (human machine interface), supervision/fault management, etc., but struggles with "engineering" functions like PI loops, FIR filters, etc.Quote from: 6thimage on December 06, 2015, 09:21:49 pmOh, I'm not jumping into anything - I'm merely pursuing the option of using FPGAs because it seems to make a lot of sense on paper. More specifically, I see three potential outcomes here:1. Best case: I achieve success after success controlling ever more complex switchmode converter topologies using Matlab + Simulink + HDL Coder and/or DSP Builder (Altera).2. Okay case: I achieve success controlling simple switchmode converter topologies (e.g. - buck, boost) but reach my level of incompetence soon after (ie - the Peter Principle); this tells me that using FPGAs is likely a viable solution, but I will either have to hire someone who is competent, or else spend a lot more time than I really have learning.3. Worst case: I can't even get an LED to blink and therefore am no better off than I am now.Quote from: 6thimage on December 06, 2015, 09:21:49 pmYep, you've nailed it. We are using an RTOS and running the switch control strategy for a high power DC drive system within it as a high priority interrupt driven process. This inevitably results in a varying/inconsistent response time to line and load perturbations. This wasn't a big problem by itself, but when more than one drive is online (which is normal), huge oscillatory currents circulated between them. This is a known problem in switchmode converter design (Middlebrook stability criteria) which could be solved entirely in software, but I had to do it in hardware because the programmer simply couldn't understand what needed to be done. Of course it is easy to blame the programmer here, but it is equally valid to argue that the problem could also be solved if I just understood C better. But since I am part owner of the company I can't be fired (though there are times when I wish to...).Quote from: 6thimage on December 06, 2015, 09:21:49 pmI learn best when I actually have an application, and spending money to pursue it is especially motivating! I'm not even the tiniest bit willing to drop ~$10k on this experiment, but the home license for Matlab is $145 and each additional module is $45, so I could try things out for a few hundred, max. That's still more than I would like to spend on something that may end up gathering figurative dust on my hard drive, hence why I am asking about the experience of others here.

author: magicsmoke
author_rank: Regular Contributor
timestamp: December 08, 2015, 06:13:24 am
content: What sort of specifications or design documents are you providing to your programmer? Discrete time implementations of the control system or actual rough procedural pseudo code? I haven't used MATLABs HDL Coder tool but I have used the Embedded Coder products with a fixed point DSP several years ago. Using the autocode generation from Simulink has definite plusses and minuses. For fixed point DSPs it is nice because you can hide much of the scaling complexity. The major aspect I don't like about it is that Simulink is signal flow based so it is difficult to understand without looking at the generated C code what the exact order of operations will be. This can be important for things like observers and more advanced electric machine control techniques. The other difficulty is implementing logic or state machines. I didn't have Stateflow at the time and that might have made it much better versus using Simulink switch blocks. Some of the peripheral drivers were crap and had to be rewritten.

author: MagicSmoker
author_rank: Super Contributor
timestamp: December 09, 2015, 04:08:53 pm
content: Quote from: magicsmoke on December 08, 2015, 06:13:24 amDiscrete time implementations in outline format along with flowcharts/decision trees where applicable.Quote from: magicsmoke on December 08, 2015, 06:13:24 amInteresting, and valuable, comments. Order of operations could be a considerable problem with HDL, but I have to imagine the generated code can be piped back to, e.g., Quartus II and run in its simulation environment to check for stuff like that, no?

author: SimonWasAnEngineer
author_rank: Contributor
timestamp: January 31, 2017, 08:16:57 am
content: Okay, its been over a year since this thread started, but I´m really interested in the outcome.Did you use Matlab/Simulink/HDL Coder for your project?Did it work out for you/ what are your experience with it?Or did you find another approach?

author: MagicSmoker
author_rank: Super Contributor
timestamp: January 31, 2017, 02:07:27 pm
content: Quote from: SimonWasAnEngineer on January 31, 2017, 08:16:57 amI did not get enough independent information about the usefulness of the Matlab development environment to convince me to buy it, and apparently neither the HDL or Embedded (C for MCUs) modules are available in the home license version which means I'd have to get the full professional version of the package (>$25k) to evaluate it. I am revisiting this now, though, since there is a module called "Fixed Point Designer" which generates C code for MCUs, just not as optimized, if I understand correctly, as would be produced by Embedded Coder (and obviously without floating point numbers, but that sort of restriction can be good).

author: parasole
author_rank: Contributor
timestamp: January 31, 2017, 10:14:02 pm
content: Now I understand better your thread regarding SMPS:-)Considering you have a programmer, what I see he need some dsp learning, and instead of mathlab you may use Octave, it is free and have almost all mathlab functions implemented with regard to signal processing. Most important for your programmer and perhaps you, it is to have basic understanding for digital PID or FIR, for example how many taps you need for a FIR and why, what is the normalised sampling freq and so one.You do not need to go into to the complex math behind dsp, understand the relative simple functions and how to use the tools (Octave in my case) for designing your algorithm and finding out the transfer function and required coeficients...Next implementing them in HDL or C would not be that difficult and you or your programmer always will find plenty of examples for particular functions wich definetelly will help to integrate in your project what you need... Having basic dsp knowledge would be a great help while implementing the required control algorithms in your projects...I did this by myself, as I mentioned in other thread for my IH project, basically I learned most of DSP processing I need (and it is FIR and PID first of all) due of that need... and all because I don't want a basic pll IH but some thing fancy with real time impendance calculation which would be incensitive to pll phase jump and associated problems :-)

author: bghende
author_rank: Contributor
timestamp: February 01, 2017, 03:10:19 am
content: I have worked on projects where the Mathworks toolchain was being used to generate HDL. In my experience, it works very well in the application area for which it was intended: filter design. Use it to implement your crazy 1000-tap FIR filters and crazy control loops. You still need FPGA knowledge and systems knowledge to glue it all together and interface with the outside world.

author: Someone
author_rank: Super Contributor
timestamp: February 01, 2017, 07:08:31 am
content: Quote from: parasole on January 31, 2017, 10:14:02 pmThe code its not challenging, its getting the right balance of precision and optimisation for the task. Adding in the modelling of fixed point arithmetic and trying to quickly assess changes to signal ranges is very slow (computationally and effort) outside of the packages which are designed for this. They have their place but are a huge investment for a single project or a small company.

author: SimonWasAnEngineer
author_rank: Contributor
timestamp: February 01, 2017, 08:14:06 am
content: Quote from: MagicSmoker on January 31, 2017, 02:07:27 pmI´m approaching this topic from another direction. I get access to a Matlab license from my uni. So if I get the chance to play around with a 25k$ piece of software I want to use it,but at the moment I don't have an idea what to do with it. Since I never have worked with FPGAs I thought I could combine it but with this huge amount of toolboxes an possibilities I don't really know where to start