Please critique my custom SMPS controller strategy! - Page 1
Forum section: electronics / general

author: MagicSmoker
author_rank: Super Contributor
timestamp: January 30, 2017, 06:05:42 pm
content: For the last couple of years or so I've been kicking around the idea of using a model-based development environment (e.g. - Matlab/Simulink; Simplis; etc.) to create the raw code (either C or HDL) for an advanced PWM generation/SMPS controller running on either a microcontroller or a small FPGA. The reason I am contemplating this is because I'm strictly an analog/power electronics guy so don't really understand the nitty gritty of C or HDL, while, conversely, precious few programmers seem to understand SMPS function or even basic control theory. Also, there have been times where some of the more exotic SMPS topologies would have been a perfect fit but weren't practical (or possible) to try out because they needed, for example, two complementary pairs of switches running above 50% duty cycle (e.g. - current-fed isolated topologies like the Weinberg and Boost Full-Bridge) and I didn't have enough time/budget to come up with an ugly kludge using, say, a commercial SMPS IC and a bunch of glue-logic.Some of the functions I want my digital smps controller to have are 1, 2 or 3 complementary pairs of synchronizable/phase-shiftable PWM channels with full control over switching frequency, maximum duty cycle, the deadtime (voltage source topologies) or overlap (current source) of complementary switches in each pair, minimum on-time + pulse skipping ("runt" pulses are murder on the switches) and the ability to easily try out different control strategies (e.g. - Proportional-Resonant).By synchronizable/phase-shiftable PWM channels I mean the ability to offset the on time of the switches in successive pairs to, for example, make a phase-shift full bridge (requiring 2 complementary pairs running at a fixed duty cycle but with 0-180 degrees of overlap in the on time of either the upper or lower switches in each leg) or a 3-phase fixed frequency inverter (which needs 3 variable duty complementary pairs but with a fixed 120 degrees of phase shift).My immediate goal is to see if this old dog can learn some new tricks rather than make anything specific, much less a commercial product. If I do achieve a modicum of success then that would go a long way towards convincing me (and my business partner) to pony up for the full version of, say, Matlab + Simulink + Simscape Electronics + Fixed-Point Designer (or HDL or Embedded Coder), which last time I checked pricing cost well north of $25k; the home license version for all this would cost around $330, which is just expensive enough to ensure I will put some effort into learning itIf doing this on an FPGA makes more sense (which I will determine in part from comments I hope to get here) then a SPICE-based development environment with HDL code generation would probably make more sense; I am much more familiar with SPICE, if not HDL, so could get up to speed much quicker. From what I understand, an FPGAs should be better at the PWM generation duties, whereas a microcontroller should be better at implementing feedback loops (and often come with good enough ADCs for the job, too).

author: capt bullshot
author_rank: Super Contributor
timestamp: January 30, 2017, 07:19:46 pm
content: I've never used model based code generation tools, nor anything like matlab oder spice to HDL, so I can't give advice here ... but I've done some simple digitally controlled SMPS on microcontrollers - coded on my own in C and got the control loop stable :-)From my point of view and experience, using a microcontroller would be my choice. But it is difficult to find the right one for your project. I doubt you'll find one that fulfills all your ideas, a better approach would be to select the best match for a particular SMPS topology. Usually one can build a single chip solution (except for the voltage / current sensing and power stage) with a microcontroller. I have seen many PWM units providing dead time for its outputs, but none providing an overlap. I think you'll need some tricks or external hardware here.Thats where the FPGA kicks in, being very flexible, but more complex. You'll have to add an external ADC, there are very few FPGAs offering an internal ADC that is useful. Most FPGAs require two or three supply rails.Maybe something like the Red Pitaya would be useful as the hardware, there are outputs from the FPGA that should be able to provide the PWM and two reasonably fast and high resolution ADC inputs. Don't know if there's a way from your tools to the Red Pitayas Zync chip. The Red Pitaya is quite a versatile piece of hardware, but there are very few people that are able to make use of it. The out-of-the-box Apps are nice demos but rather useless.If I had to build an universal SMPS control board, maybe I'd use a powerful microcontroller (having a Cortex-M4 or Cortex-M7) for the ADC and control loop part, and a smaller size FPGA for the universal PWM unit. Best of both worlds: The FPGA can provide all the fancy PWM modulation schemes, the uC does the parts that run better in software and usually has plenty of ADC channels for free.

author: MagicSmoker
author_rank: Super Contributor
timestamp: January 30, 2017, 09:32:02 pm
content: Quote from: capt bullshot on January 30, 2017, 07:19:46 pmAn inability to overlap and phase shift the PWM timers has been the issue, yes, which I find incredible/perplexing. I mean, I understand why very few dedicated PWM controller ICs allow this* but why should a timer in an MCU care what its registers are set at as long as the number is valid? Then again, the last MCU I used in a digital power application had a bizarre bug in which the ADC could only be read when the PWM outputs were low (some issue with the DMA; MCU is the LPC1769).Quote from: capt bullshot on January 30, 2017, 07:19:46 pmThis is also my understanding - generating any conceivable switching pattern is trivial with an FPGA, while implementing a standard PI controller or other "analog-ish" functions is somewhat cumbersome compared to coding them in C for an MCU.The Red Pitaya is an interesting bit of kit. I don't think it's quite right for the job, but the Zynq hybrid FPGA + MCU looks very interesting and there seems to be lots of other dev boards out there which use it or a similar part. Thanks for the reply, btw!* - the only common application for overlapping/phase-shifted PWM is a multiphase buck controller, which is commonly used to convert 12V down to ~1.5V/100A for modern x86 CPUs)

author: BrianHG
author_rank: Super Contributor
timestamp: January 30, 2017, 09:52:05 pm
content: Would you consider using something like a dsPIC. My friend uses them for complex PWM motor controllers, monitoring both current and external voltages with sophisticated math to correctly manipulate multiple 3 phase motor's controls for multi axis arm/joint robots. As for the overlap of the high and low drive, you can just use 2 PWM channel, one to drive the high and the other for the low, time synced, disabling all features defining your desired on and off duty cycles. The MCU wont care how you overlap your timing, the outputs will be under your 100% manual control. This means you would have to calculate the wanted positive or negative dead time yourself and set the 2 parallel PWMs manually. This should be nothing more than an add/or/subtract with a limit check to make sure you don't exceed to PWM's set loop limit, otherwise you may leave 1 channel permanently on, blowing up your bridge.In your case, this would mean using 6 PWM channels for your fully customized 3 positive channels, 3 negative channels.

author: rx8pilot
author_rank: Super Contributor
timestamp: January 30, 2017, 09:58:14 pm
content: joining the conversation.......

author: MagicSmoker
author_rank: Super Contributor
timestamp: January 30, 2017, 11:04:23 pm
content: Quote from: BrianHG on January 30, 2017, 09:52:05 pmI'll consider any MCU, DSP or FPGA that I can generate (functional!) code for using amodel based development environment. To reiterate, I am immensely frustrated by the impasse created when I can't understand the code and the programmer can't understand the circuit.Quote from: BrianHG on January 30, 2017, 09:52:05 pmSo far in my (admittedly limited) experience, the PWM timers in MCUs that are intended for 3 phase motor inverters tend to be the least adaptable to other SMPS applications. I don't know why that is the case, or if this is merely a matter of me not having much experience, but it has been true with many 8b AVRs and 32b ARMs. Actually, the timers in the AVRs have been more flexible, as I recall, it's more that the processor is so slow [and has no divide instruction!?] that you can't run a decent SMPS control loop at more than a few kHz. Also there was some strange dependence on the number of duty cycle steps vs. switching frequency.Quote from: BrianHG on January 30, 2017, 09:52:05 pmI'm not sure if what you are describing is the same as what I want to do... I want the complementary pairs to remain complementary, but with the ability to overlap the on time of each switch up to a maximum of 100% overlap (in the case of a multiphase buck converter), but usually to a hard-limited value which is greater than 50% but less than 100%. There are commercial PWM controller ICs intended for multiphase buck converters, but they are tailored to VRM (CPU "Voltage Regulator Module") applications so are restricted in many other ways while the latter capability - programmable duty cycle limit above 50% - is usually only found on single output controller ICs intended for boost or flyback converters; duty cycle on controllers with dual complementary outputs (for forward/bridge converters) is invariably limited to less than 50%, to enforce some dead time between the complementary switches. That's fine - indeed, necessary - for voltage source converters, but absolutely verboten for current source topologies (can't open-circuit an inductor while current is flowing same as you can't short-circuit a charged capacitor).Also, I really want to be able to do this configuring in software, rather than rely on ANDing together two complementary outputs to make a single wide duty-cycle range output, because that will be the most flexible (and least kludgy...). It is, however, a possible solution.***In a previous thread I started about model-based development environments (sort of the precursor to all this) someone recommended Simplis as it can generate HDL code... I revisited the web site and it looks very promising - it uses a SPICE interface which I am fairly competent at already, but can also incorporate model-type building blocks (e.g. - a PI controller with anti-windup). However, you have to email them for the price, which I tend to file under "if you have to ask the price you can't afford it"... Ah well, I'll ask anyway.

author: BrianHG
author_rank: Super Contributor
timestamp: January 31, 2017, 12:30:01 am
content: Ok, just so we are on the same page as to how to use an MCU pwm and what it can do:For simplicity sake, say we set the CPUs pwm1 & pwm2 loop size to 1000 clocks.if I set pwm1 to 0, un-inverted, it's output will always be low.if I set pwm1 to 1, un-inverted, it's output will be high for 1 clock, off for 999 clocks.if I set pwm1 to 512, un-inverted, it's output will be high for 512 clocks, off for 511 clocks.if I set pwm1 to 1000, un-inverted, it's output will be high for all 1000 clocks.now if I set the invert bit for pwm1, it's output will be upside-down with all the above clocks.Setting pwm2 with the same setting as pwm1, but inverted, I will have a mirror image of pwm1 outputting on pwm2.If I were to set pwm2 value a little less or a little more than pwm1's value, it will trigger earlier or late compared to pwm1.I can also saturate pwm2 to 0 or 1000 to keep it on or off.As you can see, you can individually drive pwm1&2 to be 100% on, or 100% off, mirrored or phased anyway you like. What you cant do effectively is have 1 of these skew around inside the margins of the pll loop length. At lease I never attempted to do such a thing since it involves setting on and off points for each pwm. I would have to look at the data sheets of a modern dsPIC to see if on/off zones have been added as a new feature.Now, to regulate/control your output voltage,Now, for control regulation. The feedback from your hardware is resistor divided down and fed into the ADC inputs. Use multiple inputs if you want to measure multiple points, being most likely voltage and current feedback, to control your pwms. You should be using a PIC with a >=1msps ADC. This can work with 1Mhz pwm loops, but, your response will be a few pwm cycles delay. Your should be able to respond within a single pwm loop working with 200khz or lower frequencies.Your software will be doing nothing more than:Setup PWM loop size defaults.loop forever {Read all ADC channels,Calculate the change you want based on the input, feed pwm1&2&3&4&5&6.wait for PWM loop to finish.}Thanks to C language, reading the ADCs,multiply the voltage factor to get the voltage reading,adjust the pwm according to the target voltage you want, based on an earlier previous reading overshoot if you want to predict and correct for an inductive/cap load.Now, with the FPGA, you might have the ability to start and stop each output to generate that custom randomly skewing pattern, however, reading an ADC and doing the math to set even the FPGA pwm will still boil down to the above loop programed in the dsPIC, except now you have the FPGA, BOOTPROM, multichannel ADC, a processor core to do the administration software control and math.

author: BrianHG
author_rank: Super Contributor
timestamp: January 31, 2017, 01:24:21 am
content: I've taken a quick look at a modern dsPIC30F2020 and they now have separate timer period high and timer period low settings for the PWM, both capture and output, however I have not used these modern PICS and you would need to do the research to see if they offer the 0% to 100% range of the old PICs I used to use. Now remember, you will not be using the internal dead time generator, or any of the special advertised features since you want 100% manual control. You will be using 1 full PWM channel just for the high drive and a second PWM channel just for the low drive, not the usual 1 pwm with a high and low output pins with the built in dead time setting features in the PWM module. You can now synthesize any on/off time at any point you like just with the 1 main pwm setting control for each output.Going the FPGA route, writing your own loop counter in verilog with a set of on and off periods for each PWM output + interrupt pulse on the cycle reset isn't difficult at all, something like 2 pages of code, integrating a control MCU, with compiler and simulator and ADC might be where things get sophisticated compared to an all in 1 28 pin DIP device.

author: BravoV
author_rank: Super Contributor
timestamp: January 31, 2017, 01:29:12 am
content: Not an expert, just curious have you take a glance at TI C2000 class mcus ?For example just browse this brochure ->TI C2000 MCUor the portalC2000 32-bit microcontrollersReading your quest, remembered few jargon words from those TI marketingthat I "guess" maybe this fits in , such as ..For examples at the pwm capabilities :• Achieve unprecedented precision with unparalleled high resolution duty-cycle control down to 55ps time steps• Reduce power-switching loses with high-resolution and configurable deadband support• Protect your system and add safety features with direct PWM tripping from comparator or trip zone pin inputs• Flexible PWM outputs configurations, including dual-edgeasymmetric and symmetric PWM generation• Programmable or hardware-locked PWM time and phase synchronization

author: rx8pilot
author_rank: Super Contributor
timestamp: January 31, 2017, 01:34:31 am
content: The C2000's are in my cross hairs for some of my new PE designs. So far, it appears they could be a choice for your project.Sent from my horrible mobile....

author: BrianHG
author_rank: Super Contributor
timestamp: January 31, 2017, 01:57:17 am
content: Quote from: BravoV on January 31, 2017, 01:29:12 amThat's all he needs.....

author: BravoV
author_rank: Super Contributor
timestamp: January 31, 2017, 02:10:36 am
content: Quote from: BrianHG on January 31, 2017, 01:57:17 amI guess so , and also complementing above PWM's capabilites and coupled with the mcu capabilities that able to control the whole control loop tighly cycle by cycle such as this example (quoted from C2000 datasheet)

author: Phoenix
author_rank: Frequent Contributor
timestamp: January 31, 2017, 06:27:30 am
content: I specialise in microcontroller based power electronics. The C2000 range from TI are my bread and butter, their Piccolo range have very flexible ePWM modules. E.g. each module has a single timer and two comparators. The two outputs can either be synchronised off one comparator or by independent comparators. Also configurable deadtime (and im pretty sure it can do overlap if you configure the inversions in the right spot). Also easy synchronisation between the PWM and ADC for synchronous sampling. They can also come with floating point support making the control loop implementations that much easier (no more delta operator for the proportional+resonant controller woo).If you can sketch the waveforms/switching patterns you want I could help you with the configuration of the peripheral. I tend to ignore the examples they provide in the manual as everyone uses slightly different terminology for PWM methods and of course it's never quite what I want.The other part is working out what can be done in the peripheral and what can be done in software ie.phase shift at the switching frequency (eg. multi-channel buck) can be done in the peripheralphase shift for the fundamental frequency (eg. 3 phase sinusoidal) can be done in software independent of the topology/pwm method.

author: nano
author_rank: Contributor
timestamp: January 31, 2017, 06:32:01 am
content: Infineons XMC4200 MCUs also look interesting for this application.They have high resolution PWM and very flexible timer units:Power Conversion PresenatitonFurthermore they offerSIMULINK models for embedded coderwhich I think is exactly what you are looking for. Unfortunately I have no experience with those simulink models and cannot comment on the practability of those.

author: timb
author_rank: Super Contributor
timestamp: January 31, 2017, 06:53:51 am
content: Cypress PSoC 3/5LP MCUs might be worth looking into. They have some *very* nice PWM components that are fully customizable (and you can have as many as needed). They support all the normal stuff like dead time, complementary outputs, count down, count up, compare, etc.If that's not enough, you can further customize them any way you want, since they're implemented in the programmable logic fabric (UDB blocks). There's also TIA amps, op-amps, comparators, SAR and DelSig ADCs, VDACs, IDACs and various other analog blocks onboard.I've been using one to create a very low noise Zeta converter (I'm doing voltage and current slew rate control of the switching transistor using the onboard IDACs as variable current sources, with instantaneous switch current feedback via two of OPAmps. It's very slick and almost all the analog and digital logic contained in the PSoC!)

author: Phoenix
author_rank: Frequent Contributor
timestamp: January 31, 2017, 11:10:35 am
content: Quote from: timb on January 31, 2017, 06:53:51 amThey look interesting. Might have to download the software and see what sort of PWM it can configure.

author: parasole
author_rank: Contributor
timestamp: January 31, 2017, 11:21:13 am
content: I am busy with induction heating full bridge design and going trough the same questions about what to use, dedicated ICs, micros or fpga... then I read tons of ieee papers on this subject and so far I find myself that use of specialised shifted phase IC (like uc3875) and simple micro for service functions looks to be the most efficient approach... then it is all about your target, if there is a plan for production then designing from scratch all in one advanced controller could be reasonable, otherwise if this is a hobby one of a kind unit then adapting the available building blocks could be a better approach...

author: MagicSmoker
author_rank: Super Contributor
timestamp: January 31, 2017, 01:59:36 pm
content: Holy frijoles, I wasn't expecting such an enthusiastic response so I'll forego my usual quoting of individual lines!I do appreciate the part number/series suggestions but it is my understanding that getting code created by a model based development environment to function on an MCU or DSP requires a lot more customization on the part of the modeling software compared to getting HDL to run on a FPGA, and that means I have to know ahead of time that a particular MCU/DSP family will do what I want (and I don't mean just relying on what the datasheet says!).This is, of course, a classic "chicken or the egg" kind of problem: I can't know for sure if the MCU choice is good until the software is written for it, and by that time I've either spent serious money on the modeling software, or else designed all of the hardware for a specific product and paid a programmer for weeks to months worth of work. I learned this the hard way with the LPC1769 where both the programmer and I determined from the datasheet that it could do exactly what we wanted, only to find out after I designed an entire product around it that it had (still has, actually) a nearly-fatal bug in DMA transfers (the first conversion result from the ADC is garbled and subsequent conversions can only be done during the switch off time).Which I guess is a roundabout way of saying I am leaning towards an FPGA solution, but failing that, the suggestion made by @nano is more what I am looking for, but better still would be others' experience - good or bad - using model based development software in the real world (as compared to, say, academia... no offense to any professors or grad students here, but in my experience lies can be ranked in the following order of severity: politicians' promises; datasheet specifications; claims in IEEE papers).@timb - I looked up the Cypress 5LP - interesting little chip, and the dev boards are dirt cheap, too. On first glance they appear to be aimed more at HMI applications (based on the capacitive sensor and LCD interfaces) but your comment about their timer capabilities is enough for me to look a little more into the datasheet.@parasole - I don't have a project or product in mind, I just want to try a different approach to SMPS development which frees me from the tyranny of manufacturers discontinuing a beloved SMPS controller IC and/or programmers that don't understand how an SMPS functions. As for induction heating, I would not attempt to use a fixed-frequency controller IC like the UC3875; you really need to dynamically adjust the switching frequency to match the resonant tank and load, and that means either using a PLL or a self-resonant circuit topology (e.g. - Royer). Also, if using MOSFETs for the switches you'll want to run them in ZVS, while IGBTs prefer ZCS.

author: Throy
author_rank: Regular Contributor
timestamp: January 31, 2017, 04:18:40 pm
content: Have you taken a look at the STM32F334 MCU?http://www.st.com/en/microcontrollers/stm32f334.html?querycriteria=productId=LN1820Here's an eval board that they did for a 2kW AC-DC converter.http://www.st.com/en/evaluation-tools/steval-isa172v2.html

author: timb
author_rank: Super Contributor
timestamp: January 31, 2017, 08:14:28 pm
content: Quote from: MagicSmoker on January 31, 2017, 01:59:36 pmOh yeah, they're in no way just for HMI stuff. In fact, I recently saw a PSoC 5LP inside a Parrot Bebop quadcopter. It's used as the BLDC controller/sensor fusion device. Basically it's responsible for taking all the sensor data and translating it to motor commands to keep the quad level and flying. The onboard Linux based SoC simply sends it directional commands.Apparently they created a custom state machine in the programmable logic fabric that works with the Cortex M3 for the real time control, which is a pretty complex task!The PSoC 3/5LP is also used quite often for power supply control, trim and margin. There's a built-in module that can be used to monitor and control up to 32 external DCDC or LDO converters (using high resolution PWM and a connection to each converters feedback pin through a LPF).Most MCUs these days have pins capable of LCD drive and quite a few are capable of CapSense, the MSP430 and STM32 spring to mind (besides, the PSoC 4 actually have more advanced CapSense support, being capable of Mutual Capacitance (CSX) sensing by way of specialty hardware onboard; the PSoC 3 and 5LP rely on the onboard IDACs, ADCs and analog muxes to do the job, making them capable of CSD only).What sets the PSoC apart and makes it truly flexible is the plethora of analog peripherals *and* onboard programmable logic fabric, which is essentially somewhere between a CPLD and an FPGA.Sent from my iPhone using Tapatalk

author: parasole
author_rank: Contributor
timestamp: January 31, 2017, 09:37:01 pm
content: Quote from: MagicSmoker on January 31, 2017, 01:59:36 pmOh yes, all of these aspects are well known and considered, and possible you won't be surprized to find out that ICs like uc3875 are widely used on such application (pahse shift full bridge resonant load) and succesfully could be included in pll loops (internal osc is easy transformed in VCO) and even in direct sync mode by use of resonance tank feedback signal... Then uc3875 is used as a core function for bridge control having two control inputs, one for ferquency and another one for phase shift, respectivelly power regulation... So do any required computation in microcontroller/FPGA and act on those two inputs, without the need to implement all the logic for full bridge phase shift control...From what you describe about your wishes, then my sugestion is to go with STM32F3xx or F4xx, cheap discovery boards, free tool chain, good investment in learning modern ARM controllers... And invest in C programming learning, any simulation will produce the code wich is intended to be used as a particular function, however you still need to write all the other parts and glue them toghether as one functional program...

author: MagicSmoker
author_rank: Super Contributor
timestamp: January 31, 2017, 11:31:04 pm
content: Quote from: timb on January 31, 2017, 08:14:28 pmI've been skimming through the datasheet and from what I can tell so far these chips look like they've used FPGA hardware to emulate an MCU (what I understand are usually called "soft cores" by other FPGA vendors). That said, PSoC Creator looks pretty f'ing cool, so maybe I don't care if the ARM is emulated or there aren't a bunch of FPGA/CPLD macrocells left to play with...Quote from: parasole on January 31, 2017, 09:37:01 pmHmm... I should learn C, huh?Please read at least the first couple of sentences in the original post!As for the UC3875, I see how you are intending to use it, and can't help but think you are attempting to solve the same problem as me but in a different fashion (that is, avoid hand-coding the PWM generator).

author: timb
author_rank: Super Contributor
timestamp: January 31, 2017, 11:33:13 pm
content: Quote from: MagicSmoker on January 31, 2017, 11:31:04 pmNo, it's a real 100% hardware ARM Cortex M3 core, no emulation at all.Here's the analog subsystem:Any analog component can be routed to *any* GPIO! Digital pins are fully configurable as well (the only fixed function pins are two hardware I2C blocks, which you have to use if you want to use the chip as a slave and have it wake from sleep on address match; otherwise you can use any pin you want).Edit: Here is what are included as fixed function digital blocks: 2xI2C, 1xCAN, 1xUSB, 4xTimer/PWM. You can add additional or more complex implementations through UDB blocks. As an example, the PWM implemented in programable logic is much more powerful than the fixed function PWM.There's individual datasheets for all the components which you can access through PSoC Creator. They're also available on the Cypress website. (Basically the datasheet for the actual part only scratches the surface of what's available; for the PSoC 5LP there's over 100 different functional blocks available, you can also implement your own custom ones by hooking existing blocks (or logic gates) together, using the UDB editor *or* writing VHDL!)

author: MagicSmoker
author_rank: Super Contributor
timestamp: January 31, 2017, 11:55:22 pm
content: Quote from: timb on January 31, 2017, 11:33:13 pmI was just going to correct my previous post to say that I found out about the UDBs, which can be used to make custom PWM timers. Also started reading the manual for PSoC Creator and so far it seems too good to be true... is it really a manufacture-provided SPICE/model-like development environment with no/minimal hand-coding required?!?

author: timb
author_rank: Super Contributor
timestamp: February 01, 2017, 12:02:18 am
content: Quote from: MagicSmoker on January 31, 2017, 11:55:22 pmI thought the same thing, however it's really as good as it seems! Basically it's schematic style entry for all your hardware (PWM, logic gates, analog, SPI, I2C, etc.) and there's a very nice integrated IDE for coding the MCU.Let's say you want to setup a PWM. You drag it to the schematic, double click and setup all the default values, draw wires to connect it to other blocks or GPIO pins, then in your main.c file you simply call PWM_1_Start() and that's it!They literally have the best HAL libraries I've ever seen. It's quite magnificent!

author: nctnico
author_rank: Super Contributor
timestamp: February 01, 2017, 01:44:15 am
content: Quote from: MagicSmoker on January 30, 2017, 11:04:23 pmThe newer SCT (event driven PWM) timer in NXP's microcontrollers is pretty nifty and it can do protection in hardware as well but it isn't particulary easy to use (which shows in the useless cookbook examples). I have used it in a couple of projects though and I'm starting to get the hang of it.

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 01, 2017, 12:26:35 pm
content: Quote from: Phoenix on January 31, 2017, 06:27:30 amSelecting an MCU or DSP isn't the problem, rather, the point of this thread is whether I can get them to what I want without spending the next 5+ years learning C by using software like Matlab/Simulink/Embedded Coder or the like.Quote from: Phoenix on January 31, 2017, 06:27:30 amSure, attached is an example (pulled from Kepco's website) of a type of converter and its associated waveforms that most "PWM timers" can't handle (ignore the aux. switch, Qa for now, though driving it would certainly be easier with an MCU or FPGA). The switches in each bridge leg (e.g. Q1 & Q2; Q3 & Q4) are both operated at >50% duty cycle to ensure there is some overlap so that the boost inductor, L1, isn't open-circuited while current is flowing. Increasing the overlap increases the boost ratio, same as a non-isolated boost PFC stage, but reduces the active power transfer time of the bridge transformer so voltage regulation is usually performed by varying the phase shift of the left and right bridge legs.This converter can operate exactly like a common phase shift full bridge except that it needs the on time to overlap for the upper and lower switches in each bridge leg, and most (if not all) commercial PWM ICs don't allow that. Unfortunately, most PWM timers in MCUs and DSPs, especially if aimed at motor control applications, assume (and enforce) the use of deadtime between the upper and lower switches as well, so can't be set up to produce complementary outputs that are each high for 50% of the PWM period, much less for more than 50%.Original pictures obtained fromhttp://www.kepcopower.com/bpaper.htm

author: nctnico
author_rank: Super Contributor
timestamp: February 01, 2017, 02:06:16 pm
content: Quote from: MagicSmoker on February 01, 2017, 12:26:35 pmI think what Phoenix is hinting at is hiring someone who knows how to implement the algorithm you propose. But still you'd need a simulated model (which can be made using Matlab) so you can verify the algorithm before testing on real hardware and even then it is advisable to have a software layer between the algorithm and the hardware (PWM, DAC, control signals, etc) which checks whether the parameters are valid.

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 01, 2017, 02:19:04 pm
content: Quote from: nctnico on February 01, 2017, 02:06:16 pmYes, that is the usual refrain around here - if you don't know how to do something then hire someone to do it. It's as if learning something new is not even possible...If I had a specific application with a tight deadline then of course I would hire someone with the requisite expertise, but this is purely an educational/exploratory pursuit at the moment. I used to be really skeptical about SPICE but during a break between projects a few years ago I downloaded LTSpice and started tinkering with it and slowly but surely I was convinced that it (at least LTSpice) can be useful. Now I am thinking that maybe model-based development software like Matlab or Simplis might also be useful, and allow me to implement in code - which I could not write myself - the actual EE-related functions that most C programmers have no knowledge of, much less a good enough understanding to translate concepts into code.EDIT: I should note that I expect I will have to hire someone to make some example-but-functional code to help bootstrap my learning because I tend to learn new things best when I have something to work with at first. So phoenix (at al.) may end up getting a job out of this yet.

author: parasole
author_rank: Contributor
timestamp: February 01, 2017, 06:35:42 pm
content: Quote from: MagicSmoker on February 01, 2017, 02:19:04 pmHmm, I told you better start to learn C and perhaps some DSP, yet you deny my advise as impossible task for you ;-)I would assume you don't need to become very proficient, just to the level you may help and guide your programmer on how to do the things...

author: nctnico
author_rank: Super Contributor
timestamp: February 01, 2017, 06:45:45 pm
content: Quote from: MagicSmoker on February 01, 2017, 02:19:04 pmLearning to program C at a good enough level and the additional knowledge to implement control / DSP algorithm on a microcontroller or DSP (there is little difference nowadays) will take a while. I disagree with your assesment of C programmers though. What you need is a C programmer which has experience with implementing DSP algorithms (usually these kind of programmers have an EE background) and not someone who writes GUI or data processing software. After all a brain surgeon won't be able to replace your knee.

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 01, 2017, 11:32:59 pm
content: Quote from: parasole on February 01, 2017, 06:35:42 pmLearning "C and perhaps some DSP" would be a lot more difficult than learning how to connect together functional blocks in a model based development program like Matlab... I'm quite willing to put in a few months of work to make a better SMPS controller; I am not at all willing to spend severalyearson the project.Quote from: nctnico on February 01, 2017, 06:45:45 pmYes, I know just enough about C to understand how difficult it would be to get good at it! Also, I feel it takes a special mindset to write good software, especially for real-time/embedded applications. You have to break a problem down into just the right set of tasks in just the right order to really optimize things, and that is not something you can learn in any way except by doing it over and over again (ie - experience).Which is why I thought it might be a good idea to use Matlab or Simplis, etc., to "write" the code for the more "circuit-specific" function in a switchmode controller like PWM generation, feedback filtering and control loops; then I could use a knee surgeon to operate on my brain... or something like that.

author: rx8pilot
author_rank: Super Contributor
timestamp: February 02, 2017, 08:16:01 am
content: I believe you are on a track that could take a couple of years. A few months seems unrealistic to get very far in your stated goals.Sent from my horrible mobile....

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 02, 2017, 02:27:42 pm
content: Quote from: rx8pilot on February 02, 2017, 08:16:01 amNo doubt it will take me longer than expected to create a custom PWM generator block with model based software, but if it really does take a couple of years then such software doesn't seem to provide much value add, especially considering the price.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 02, 2017, 09:05:49 pm
content: If I were you I would have use these little friends from ST STM32F030K6T6, They cost no more than 0.5USD they are very nice beast in their own price realm! 4 phase PWM on timer 1 with dead time insertion and a 1MSPS ADC, they are so damn cheap that If I need an extra function I would easily add them to the project replacing many things including MUX's and gates!!!Actually we are designing a fairly complex SMPS (800w) with the aid of 3 of them.

author: Phoenix
author_rank: Frequent Contributor
timestamp: February 02, 2017, 10:09:09 pm
content: Quote from: MagicSmoker on February 01, 2017, 12:26:35 pmLooks just like a set of waveforms I already employ on a converter. Very easy on the ti epwm. I'll whip something up later tonight. What's the behaviour or Qa? Does it need to synchronise with the rest like it shows?

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 03, 2017, 12:04:51 am
content: Quote from: Phoenix on February 02, 2017, 10:09:09 pmHuh... I guess TI wasn't kidding when they say that the C2000 series is ideal for power conversion applications...Qa is just used to ensure zero voltage switching of the bridge switches, which is very helpful if MOSFETs are used; less so for IGBTs (which benefit more from ZCS). I highly recommend reading the link to Kepco I provided in the previous post for more details about this clever circuit which can both do power factor correction and isolation/voltage conversion in a single stage (with the usual caveat that single stage converters must have a low voltage loop bandwidth to achieve high power factor). Thanks for the reply!

author: Phoenix
author_rank: Frequent Contributor
timestamp: February 03, 2017, 08:31:40 am
content: Quote from: MagicSmoker on February 03, 2017, 12:04:51 amI think this looks like what you want using only a single ePWM module. This is running on a TMS320F28069 but the Picollo family and others with the same ePWM module will have the same setup and capabilities.Source code snippet to setup the ePWM for those playing at home:Code:#define PERIOD_PWM 3000#define PERIOD_PWM_2 1500#define OVERLAP 300EALLOW;SysCtrlRegs.PCLKCR1.bit.EPWM2ENCLK = 1;GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;EPwm2Regs.TBCTL.bit.PHSDIR = 1;EPwm2Regs.TBCTL.bit.PRDLD = 0;EPwm2Regs.TBCTL.bit.CTRMODE = 2;EPwm2Regs.TBCTL.bit.PHSEN = 0;EPwm2Regs.TBCTL.bit.HSPCLKDIV = 0;EPwm2Regs.TBCTL.bit.CLKDIV = 0;EPwm2Regs.TBPRD = PERIOD_PWM;EPwm2Regs.TBPHS.all = 0x0000;EPwm2Regs.TBCTR = 0x0000;EPwm2Regs.CMPA.half.CMPA = PERIOD_PWM_2 - OVERLAP;EPwm2Regs.CMPB = PERIOD_PWM_2 + OVERLAP;EPwm2Regs.AQCTLA.bit.CAU = 2;EPwm2Regs.AQCTLA.bit.CAD = 1;EPwm2Regs.AQCTLB.bit.CBU = 1;EPwm2Regs.AQCTLB.bit.CBD = 2;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;EDIS;The frequency is adjusted with PERIOD_PWM and PERIOD_PWM_2. The amount of overlap is adjusted with OVERLAP.

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 03, 2017, 10:42:57 pm
content: Quote from: Phoenix on February 03, 2017, 08:31:40 amYes, that's it. I just d/l'ed the datasheet for one of the least expensive Piccolos (F28020) and the Enhanced PWM Module reference guide. I see in the latter document that there is a register for setting the phase relationship between two ePWM modules, so that takes care of the other big difficulty: phase shift modulation.I still would very much like to be able to do something similar with Matlab or the like - and would really prefer to implement this on an FPGA or CPLD - so I am still going to pursue that for now but it is good to know there is at least one MCU family that can do overlapping/complementary PWM without resorting to kludges like ORing it with another pulse (even kludgier - getting that pulse from a monostable [kludgiest - using a 555!]).

author: timb
author_rank: Super Contributor
timestamp: February 03, 2017, 11:00:02 pm
content: Quote from: MagicSmoker on February 03, 2017, 10:42:57 pmThe PSoC can also do overlapping/complementary PWM.

author: jbb
author_rank: Super Contributor
timestamp: February 05, 2017, 04:24:45 am
content: Hi allI've worked with automatic code generation a bit. There are some things to be aware of:It will be a bit less (or sometimes a lot) efficient than hand-coded.You will have to do some manual tweaking to get the code to look reasonable. For example, you may have to add type declarations all through your Simulink model / Matlab code to make it stop using 64 bit double precision floating point everywhere!The Mathworks demo materials (in person at least) have all been carefully designed to make it look as easy as possible. This can be misleading if you want to run fast or large loops.It's really hard to configure Real Time Workshop for a new chip.On the chip side, I can say the following:The TI C2000 series cost more but are really well suited to power electronics. Good PWM control, and good synch to ADCs. Downside is that getting your first project to compile used a ####ing nightmare. Might be better these days with example projects.Some kind of ARM core with appropriate PWM + ADC peripherals will likely do the trick.PSoCs might be a bust when you look at how hard it is to configure the Real Time Workshop tools.You should probably pick a shortlist of MCUs, then cross out any chip that doesn't have a recent support package for Real Time Workshop.A final comment: coding up the filters / controllers etc. generally isn't too bad. What kills you is the complexity of start up / mode transition / shut down. This is a difficult design problem, and Model Based Design doesn't make it magically go away.

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 05, 2017, 01:34:55 pm
content: Quote from: jbb on February 05, 2017, 04:24:45 amThanks, jbb - this is exactly the sort of commentary I was fishing for in this thread!Quote from: jbb on February 05, 2017, 04:24:45 amI expected #1, and don't think that will be too much of an issue given the huge difference in MCU clock and PWM switching frequencies (e.g. - 25MHz and 100kHz, respectively)as long as the MCU isn't bogged down performing other tasks!I had heard of #2 years ago; it's somewhat amusing, somewhat concerning that this is still an issue, but I suppose there are bound to be lots of little details like this which are glossed over or hidden when using model based software to generate C code.As for #3, that sounds a lot like autorouter demonstrations on high end EDA software, where a complex multi-layer board is routed in a few minutes, conveniently omitting that it took several hours to set up the router rules for that particular board, and that you have to tweak the rules for every other board you have autorouted, too.#4, however, is quite disconcerting in that it sounds like you need to have a deep understanding of the inner workings of each target MCU to get RTW (now called Simulink Coder, apparently) to work properly; in other words, you practically need to be an expert at C which defeats the purpose here. It's reasonable to expect an RTW user would have to know that a particular MCU has, say, sufficient PWM timers for an application; it's quite another to require they know how to set up the registers to use those timers...Quote from: jbb on February 05, 2017, 04:24:45 amHmm... good points, especially about the PSoC (though to be fair, Cypress' PSoC Creator software looks really powerful and, of course, the price is right - free!). All of this, as well as other research I have been doing, is steering me more towards going with a CPLD or FPGA for the SMPS control functions (ie - at least the compensator and PWM generator, the ADC might best be located externally or in the associated MCU that handles the rest of the product functionality).Quote from: jbb on February 05, 2017, 04:24:45 amAlso fault management, but those are functions that our existing C programmer handles very well (in concert with me telling him what needs to be done, that is); where our otherwise excellent working relationship fails is in me explaining and/or him understanding how to do the core functions in running an SMPS (especially the compensator).

author: MagicSmoker
author_rank: Super Contributor
timestamp: February 06, 2017, 01:16:55 pm
content: I just found out about Scilab & Xcos, which are fairly advanced FOSS alternatives to Matlab & Simulink, respectively. Things just got really interesting.