Special time-shifted (phase-shifted) multi-channel PWM generator - Page 1
Forum section: electronics / projects

author: msimunic
author_rank: Contributor
timestamp: February 12, 2018, 11:10:49 pm
content: I'm need to generate N channel (N>1) PWM output in a such a way that one channel is main 'governor' lets saych0. Every other channel repeats the same duty, but with time shift of exactly pulse width.Ch1need to set pulse (ch0_duty) time duration afterch0set the pulse.Ch2need to repeat afterch1set the pulse (or2*ch0_dutyafterch0set pulse). Constraints are:duty_max <= 50%*2/N;N*Ton=T. Duty need to be regulated from0 to duty_max. Iv'e attached drawing to be more clarifying.Those PWM signals should drive N FETs.PWM frequency would be in range 25 - 100 kHz.Probably, I can achieve very good solution on any MCU equiped with enough PWM/counter/timer modules by using PWM, up and down counting, and some ISR software.Is there any microcontroller which can generate such kind of signals using only PWM/timer/counter module, without ISR?Or maybe ASIC or some kind of other integrated circuit which can generate such PWM signals?Maybe for N=2 I could use just 2 outputs from 4CH PWM configured for driving MOSFETs in a full-bridge (H-bridge) configuration?

author: ajb
author_rank: Super Contributor
timestamp: February 12, 2018, 11:27:34 pm
content: That looks like a job for a shift register or decade counter. If you only need three channels and don't want to use an external chip, There's almost certainly an MCU out there that can do this with a chainable timer or three. Or maybe use an MCU with a timer system designed for three phase motors. You could certainly do it with a PSoC. If you need more channels it depends how many. You might be able to do something like use one timer more than once, using an ISR to change IO MUXes so that timer drives a different pin at different points in the sequence. But based on your stated requirements, a shift register driven by a single timer seems like the way to go.

author: amspire
author_rank: Super Contributor
timestamp: February 12, 2018, 11:30:09 pm
content: A FPGA can do this easily.For a micro, you could set up a PWM to have length Tp and have an output that is high for Tp/2 (it doesn't matter as long as it is less then Tp).Every time the PWM gets to 0, it generates an interrupt that is used to set one of N outputs high in a sequence. These are presets for a latch. Then with a simple 74HC latch (N of latches in total) use the PWM output as the latch clock and the preset outputs as the latch input.This would give exactly the same Tp width on all outputs and a Td of zero.This can work as long as Tp does not have to go too close to zero. If Tp does not have to go below, say, 1us, this could work.To get the T, during the interrups, a counter has to total the Tp and when the N pulses are complete, the PWM is set to run for T-(N x Tp) with all the latch preset outputs at zero. Again, you cannot go all the way to T = N x Tp. Micro-based PWM solutions usually have issues at one or both of the extreme PWM values. A FPGA solution can produce a perfect output from Tp=0 to Tp = T/N and it can control the pulse width with about 10 times more resolution then a micro.

author: filssavi
author_rank: Frequent Contributor
timestamp: February 12, 2018, 11:35:10 pm
content: It all depends on how big N isIf N is small, up to maybe 6/8 you can quite easily do it with a motor control specific MCU ( every manufacturer has a line of mcu’s with lots of advanced timers and pwm outs like for example NXP kinetis V series ) by employing one or two timers with synchronisationif n gets larger but not to much you could try taking a look to mcu’s like ti Hercules or NXP MCP5x series (the safety oriented ones) they are usually as High end an industrial (no multimedia/Hi speed comm protocols) MCU can get , they have very complex but very versatile timers and lots of them (since these devices are usually used in ECU’s they must be able in principle to drive at least 8/12 injectors minimum)But these parts are very difficult to use (orders of magnitude more than an Arduino)If N is big the only solution is writing your own own generator in a CPLD/FPGA this can scale to multiple hundred channels on the larger devices, also I suspect that using an FPGA will be easier than using a high end safety MCU

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: February 13, 2018, 12:05:29 am
content: The answer depends a lot on the value of N and the required resolution.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: February 13, 2018, 12:15:16 am
content: I did this for a job some years ago. In discrete logic:- Master CLK oscillator at Fout * N- Counter (mod N) + decoder- For each phase:* Ramp generator (CCS + cap + switch)* Decoder drive switch, discharging cap in desired phase* Compare threshold voltage to cap voltage --> PWM* PWM --> gate driver --> switch --> inductor, current sense resistor + current sense amp* Current error amp compares current sense to input current setpoint value (common to all channels)- Master voltage error amp sets current setpoint to regulate output voltage.Assuming a typical e.g. buck converter application. This implements average current mode control, which is quite nice.As you can see, it's rather tedious to do it by hand. Phase generator chips help (e.g. LTC6909), but you really should figure out if your application can use an off the shelf integrated controller instead.This can all be integrated into an FPGA or MCU. Some MCUs have vernier PWM generators with complex timing options, allowing an implementation of this fairly directly; an FPGA of course you only need to add external timing capacitors (if the FPGA has LVDS inputs, those will make fine comparators) for a continuous-time solution, or all integrated (using a much higher master clock frequency and longer dividers) if discrete-time is acceptable. Current sense can be implemented with a fast ADC (say >1MSa/s), and the error amps with PID functions.Tim

author: danadak
author_rank: Super Contributor
timestamp: February 13, 2018, 02:40:48 am
content: Do it in PSOC, either using Verilog capability on its fabric, or usingschematic capture.http://www.cypress.com/file/42161/downloadhttp://www.cypress.com/documentation/application-notes/an82250-psoc-3-psoc-4-and-psoc-5lp-implementing-programmable-logichttp://www.cypress.com/file/42156Lots of videos on Cypress website, or Youtube.https://www.youtube.com/results?search_query=psoc+verilogStart with PSOC 5LP, high end part, then look into doing it in PSOC 42xx low end to save costdepending on rest of design requirements.Regards, Dana.

author: danadak
author_rank: Super Contributor
timestamp: February 13, 2018, 02:44:51 am
content: The wall of text on PSOC -For me what stands out is -1) Routability2) Fast 12 bit SAR A/D and slow 20 bit DelSig3) DFB (Digital Filter Block) that is dual channel, handle FIR or IIR filters, or DFBcan be used as a GP fast processor block, similar to RISC block4) MSI logic elements GUI based and/or the UDB Verilog capability. Eg. the FPGAlike capability5) Onboard Vref6) IDAC, VDAC, OpAmps (up to 4), comparator, mixer, switch cap, analog mux....7) LCD, COM, UART, I2C, I2S, One Wire, SPI, Parallel, LIN, CAN, BLE, USB9) Custom components capability, create with schematic capture or Verilog10) DMA to offload processes like filters, COM, Display11) ARM M0 (PSOC 4) or M3 (PSOC 5LP) or 8051 core(PSOC 3) or M0+/M4 dual core PSOC 612) Extensive clock generation capabilities13) All components supported by extensive prewritten APIshttps://www.element14.com/community/thread/23736/l/100-projects-in-100-days?displayFullThread=truehttp://www.cypress.com/documentation/code-examples/psoc-345-code-examplesGreat video libraryAttached component list. A component is an on chip HW resource.Free GUI design tool with schematic capture, "Creator". Components have rich API library attachedto each component. Compilers free as well.PSOC 4 is low end of family, consider 5LP parts as well. PSOC 4 also has arduino footprint boards (pioneer) as well. PSOC 6 dual core M0+/M4.https://www.elektormagazine.com/labs/robot-build-with-cypress-psochttp://www.cypress.com/products/32-bit-arm-cortex-m-psochttps://brightcove.hs.llnwd.net/e1/uds/pd/1362235890001/1362235890001_5241352463001_2606504288001.mp4?pubId=1362235890001&videoId=2606504288001Regards, Dana.

author: danadak
author_rank: Super Contributor
timestamp: February 13, 2018, 02:50:00 am
content: The boards to consider -Hi end low cost -http://www.cypress.com/documentation/development-kitsboards/cy8ckit-059-psoc-5lp-prototyping-kit-onboard-programmer-andLow end -http://www.cypress.com/documentation/development-kitsboards/cy8ckit-042-psoc-4-pioneer-kitRegards, Dana.

author: jbb
author_rank: Super Contributor
timestamp: February 13, 2018, 05:54:28 am
content: Quote from: msimunic on February 12, 2018, 11:10:49 pmThe Texas Instruments C2000 series processors can do it. There is quite a range (32b fixed point single core @ 60MHz up to 32b floating point dual core @ 200MHz) - you can sort them by number of PWM channels.

author: JPortici
author_rank: Super Contributor
timestamp: February 13, 2018, 07:14:11 am
content: In order from 8 bit to 32 bit:PIC16F1789(it has the Programmable Switch Mode Controller)Product Page:http://www.microchip.com/wwwproducts/en/PIC16F1789Datasheet:http://ww1.microchip.com/downloads/en/DeviceDoc/40001675C.pdfErrata:http://ww1.microchip.com/downloads/en/DeviceDoc/80000575B.pdfdsPICs with the *complete* high speed PWM module. Each HSPWM channel has 2 PWMs which can be independent or complementary outputs, with dead time, fault inputs, overcurrent inputs and yada yada yada.For example the MU series (e.g: the dsPIC33EP512MU814) has up to 7 channels (total 14 PWMs, 5 fixed position 2 remappable).the GS series (such as dsPIC33EP64GS504) has 5. GS Series is designed with digital SMPS in mind so even if no DMA controller, ADC,comparators,timers,PWM,Current source have additional interconnections.MU Page:http://www.microchip.com/wwwproducts/en/dsPIC33EP512MU814MU Datasheet:http://ww1.microchip.com/downloads/en/DeviceDoc/70616g.pdfMU Errata:http://ww1.microchip.com/downloads/en/DeviceDoc/80000526g.pdfGS Page:http://www.microchip.com/wwwproducts/en/dsPIC33EP64GS504GS Datasheet:http://ww1.microchip.com/downloads/en/DeviceDoc/70005127d.pdfGS Errata:http://ww1.microchip.com/downloads/en/DeviceDoc/80000656G.pdfRelevant Reference Manual, but be sure to double check with the datasheet for gotchas:http://ww1.microchip.com/downloads/en/DeviceDoc/70000323h.pdfThere should be other dsPICs families with the high speed PWM module that can do what you want but i haven't used them myself.The PIC32MK Series (such as PIC32MK0512GPD100) should be able to do what you want but i haven't used it much yetPage:http://www.microchip.com/wwwproducts/en/PIC32MK0512GPD100Datasheet:http://ww1.microchip.com/downloads/en/DeviceDoc/60001402D.pdfErrata:http://ww1.microchip.com/downloads/en/DeviceDoc/80000737C.pdfIn my experience the dspics are the most pleasant to deal with, i use them daily.Currently i am developing a big project around the MU814 (which come in a handy 20x20mm TQFPabout 1/5th of the testing PCB area) and i suggest you read the datasheet carefully because there ARE some gotchas:- For example ADC2 is 10 bits only, it's written on a side note in the ADC chapternothing wrong on writing it on the front page, come on. But that wasn't a problem.- only IC1 through 4 can trigger a DMA transfer. I thought about it and decided that wasn't a problem either because i can use the buffer and trigger the interrupt ever 2-3-4 events instead.- ICx can't reset themselves reliably because there isn't an option to reset the internal timer on interrupt event (yes, each IC and OC module has its own independent timer, and period registers) while other dspic families can. so if you want absolute time, you have to reset the timer manually at each capture.On the good side, there isn't something as idiotic as "you can use either CAN or USB" a-la stm32f1 so that's goodand the canbus is the kvaser-based ECAN MODULE.

author: msimunic
author_rank: Contributor
timestamp: February 13, 2018, 10:54:37 am
content: So many useful informations! Thank you all.The N isn't supposed to be big, up to 4 or 5. But, hey, you never know what you will need.I'm aware of FPGA solution and I thought that this would be expensive solution.Now, those PSOC4 and PSOC5 are looking very handy. For other projects, also.Although there are great PIC devices, I'm far more aligned to ARM solution then to Microchip. Reason for this are Microchip tools.I'm a student and I can't afford 200+ USD for proper debugger/emulator (RealICE) which by the way comes with sheaty telephone cable (it breaks frequently). They offer JTAG extension cable for something like 50 USD, which IMO should be in package with RealICE and cost something like 5 USD. MPLAB IDE is good IDE, but toolchain is locked to MPLAB. Also, I'm not sure what are the licensing options for compilers and software packages I would need.I will need some time to check everything.

author: JPortici
author_rank: Super Contributor
timestamp: February 13, 2018, 11:22:05 am
content: well i use ICD3 but it's the same price area. (who use the real ICE, which is not an ICE for anything else than the basic chips anyway??) i don't care for the connector because i do my own cables.Keep in mind that original Microchip tools are buy once - have them forever and ever. If the programmer breaks you just have to open a ticket and they send you a new one. we got a bunch of them replaced for free. Yes, also if you are a private and not a business.As for cheap programmers/debuggers.. I actually found the PICKIT 3 to be more reliable than STLINK or the equivalent for NXP and ATMEL when it came to debugging. They would hang much more frequently. I have no experience with higher quality programmers but they still are in the ICD3 price range.. and UP!Re: Licences, XC16 and XC32 are GCC. there are a number of topics in the Microcontroller section regarding the sofware license to unlock optimizations greater than -O1 (but -O1 is good enough as the debugger don't get crazy because of optimized code) and how to disable the license check, because it's GCC and in theory you CAN do that. but again, -O1 is good enough IMHO, generated code is harder to debug with higher optimizationsKeep in mind that something like PSOC ties you to them a lot more, because you must use their PSOC Creator, which is windows only if you use a different OSand even if the ARM compiler is GCC the FPGA part is not, the binary blob is generated by PSOC creator only (or that is my understanding)

author: amspire
author_rank: Super Contributor
timestamp: February 13, 2018, 12:04:50 pm
content: Quote from: msimunic on February 13, 2018, 10:54:37 amAs I described before, you can do this with a single microcontroller PWM + a latch chip like a 74HC374 or 74HC574 (better pinout) octal buffer chip.You probably will need to do some ARM assembler for the PWM interrupt handling to optimize minimum and maximum Tp widths. If you need Tp to go down to zero, you probably should look at a FPGA or Cyprus solution. The minimum Tp with a micro may be in the 0.5 to 1us range.If you do attempt to do this with a micro, you cannot let other interrupts interfere with the PWM interrupts so it may be you need a second microcontroller to do other tasks like communication.FPGA doesn't mean expensive. You can get small demo boards that you can build into a project at a cost of $10 to $30. I have only used the free Altera Quartus IDE, but it is very good. For programming, I used the cheap Chinese USB Blaster which costs about $4.https://www.aliexpress.com/item/New-Mini-System-Development-Board-ALTERA-FPGA-CycloneII-EP2C5T144-Learning-Board-Drop-Shipping/32835916598.htmlhttps://www.aliexpress.com/item/EP4CE6-altera-fpga-development-board-USB-Blaster-fpga-kit-altera-kit-fpga-board-altera-board/32812957811.htmlhttps://www.aliexpress.com/item/altera-Mini-Usb-Blaster-Cable-For-CPLD-FPGA-NIOS-JTAG-Altera-Programmer/2038559613.htmlAnyway, you have a lot of options even if you are on a tight budget.

author: msimunic
author_rank: Contributor
timestamp: February 13, 2018, 12:15:06 pm
content: Whoooaaaawww!Thnx

author: ahbushnell
author_rank: Frequent Contributor
timestamp: February 13, 2018, 12:16:26 pm
content: Quote from: jbb on February 13, 2018, 05:54:28 amI agree on the C2000. The Piccolo has 8 channels of PWM and runs at 60 MHz with an internal clock. There are more advanced versions that operate up to 200 MHz.

author: danadak
author_rank: Super Contributor
timestamp: February 13, 2018, 12:17:27 pm
content: If you are looking for dead band PSOC Creator/PWM component implementsthis. See attached and -http://www.cypress.com/file/131736/downloadAnd phase shift -http://www.cypress.com/documentation/application-notes/an76439-psoc-3-and-psoc-5lp-phase-shift-full-bridge-modulation-andRegards, Dana.

author: JPortici
author_rank: Super Contributor
timestamp: February 13, 2018, 12:44:30 pm
content: Another option may be infineon? C166 (16bit) and XMC4000 series (Cortex M4)I was looking at their 16 bit parts for my current task but in the end i went for the dsPIC as i have a ton of code already written and tested