Cycle by Cycle current limiting Microcontroller (Help) - Page 1
Forum section: electronics / projects

author: Glenn0010
author_rank: Regular Contributor
timestamp: March 15, 2018, 07:09:13 pm
content: Hi all,As part of my main thread shown below, I am implementing a BLDC motor controller, and as some users suggested cycle by cycle current limiting is the way to go and after reading up it is. So I have a current sensor on the DC link, after the DC link cap so what I am measuring is essentially phase current since I am using the trapezoidal commutation scheme.https://www.eevblog.com/forum/projects/bldc-motor-controller-rc-snubber-design-waveforms/So my question lies with my uC. I am using a fairly old ARM 7, the LPC2119. My question is say that I have set my duty cycle to 90% and I reach over current at 20% duty cycle how do I force my PWM to go low only for that cycle, and then proceed normally for the upcoming cycles?Below is a block diagram of the PWM module and its registers.I see my options as follows:1 - I cam disable and then re-enable immediately the PWM channel using the PWM Control register in hopes that it would be forced low for just that cycle.2 - I can check the timer counter's value and put it in the match register, however I do not think this will work since the value that it is comparing to is in the shadow register, which is only updated after the current cycle is completed.Does anyone see a better way that I can implement this?

author: fourtytwo42
author_rank: Super Contributor
timestamp: March 15, 2018, 08:45:20 pm
content: Unfortunatly your chosen PWM has no hardware interface for current limit. If your intention is mosfet protection then a software solution will almost certainly be to slow. Alternatives are to change MPU to one having a more complete pwm solution or add external logic to force the pwm output off till the next cycle.

author: Glenn0010
author_rank: Regular Contributor
timestamp: March 15, 2018, 09:17:04 pm
content: Well I have gate drivers with a disable pin so in case of a massive over current I could disable the drive with a normal GPIO pin. However that would turn of both high and low side fets which is undesirable for me since I'd like the low side fet to remain on for synchronous rectificationIn such a case if I were to disable the PWm channel certainly it would still be fast enough right using the PWM control register?I am running a switching frequency of 30khz. So I tought I'd run a sampling loop of the current at 300khz to regulate according to my desired set point max 20AIn case of a hard fault i.e. >20A my current sensor gives a fault output to an external interrupt and Id use the disable pins on my gate driver to disable the whole system as at that point something would have gone terribly wrong.

author: rstofer
author_rank: Super Contributor
timestamp: March 15, 2018, 09:51:08 pm
content: Allegro builds these chips for a living. Maybe take a look at their block diagram. For certain, they use a current sense resistor, an op amp and an analog comparator in the control loop. Maybe you can respond to a high priority interrupt fast enough if the error is detected in a similar way.https://www.allegromicro.com/~/media/Files/Datasheets/A3930-1-Datasheet.ashx

author: nctnico
author_rank: Super Contributor
timestamp: March 15, 2018, 09:59:23 pm
content: At 30kHz it is easy. Have the ADC sample during the time the MOSFET is conducting and measure the voltage across the MOSFET. On the LPC series you can fire the ADC sampling moment based on a timer. Been there done that at 300kHz with an LPC2103.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 15, 2018, 11:08:46 pm
content: Yeah, ideally you have an analog comparator input to reset the output latches. Failing that, an ADC running a few times faster than Fsw is needed. It doesn't need to be terribly fast if you're doing average current mode control (you have some leeway thanks to the filter inductance time constant), but if you need true within-cycle sensing then it's got to be fast enough.Mind that, for a large inductance time constant, you don't want peak mode control (fault detection that way is fine, of course), which causes chaotic behavior.With 300kS/s available for Fsw = 30kHz, it should be fine either way.Alternately, an external latch and/or disable, maybe triggered by a fixed (fault level) comparator, or a (DAC adjustable) threshold level, would be the hardware approach.Tim

author: ajb
author_rank: Super Contributor
timestamp: March 16, 2018, 03:34:53 am
content: Some MCU ADCs also have an analog watchdog function, where you can trigger an interrupt if an ADC result is out of a particular range, which would be slightly better than than monitoring your ADC in software but not as good as a proper analog comparator. If you want a robust with few external parts, there are MCUs with very powerful PWM modules designed specifically for motor control that could be worth looking into, if you have the option of switching. I've seen such features in the Atmel SAMD series, and looking back at the datasheet you can definitely use the analog comparators to trigger a "recoverable fault" in one of the TCC modules, which can clear the PWM output for a single timer cycle.As far as your specific questions with your current MCU, the answers wil depend on the specific design of the PWM module and the mode of operation, so you'll have to study the datasheet carefully and maybe try some experiments. My guess would be that you'll need to disable the PWM or change the match value and leave it for the remainder of the entire cycle, then maybe run an interrupt on timer overflow or something to reset for the next cycle--but this may be difficult in dual slope PWM modes. You'll probably need to bypass any shadow registers if possible.

author: Glenn0010
author_rank: Regular Contributor
timestamp: March 16, 2018, 06:54:22 am
content: Quote from: rstofer on March 15, 2018, 09:51:08 pmI am actually using one of their chips, the ACS 733 a hall effect based sensor. It has a programmable over current protection FAULT pin. So I set that to 25 A (my max being 20) and connected it to an External interrupt pin set at highest priority so once I exceed 25A a fault will trigger and I can disable the whole system so that should work.Quote from: nctnico on March 15, 2018, 09:59:23 pmI've taken a look at the datasheet of the LPC2103 as you said and it is very similar to the 2119 how did you fire the adc sampling based on the PWM timer?As seen below, you can fire it based on timer 0 or 1. However I can not find any reference to fire it with the PWM timer.Quote from: T3sl4co1l on March 15, 2018, 11:08:46 pmThat is what I am going to improve in the future since all my hardware is set.Quote from: ajb on March 16, 2018, 03:34:53 amYes for the purposes of this project I am stuck with my current controller but I will look to switch in the future thanks for the MCU recommendation.I'll try some experiments and I'll see what I come up with. Thanks

author: Poe
author_rank: Frequent Contributor
timestamp: March 17, 2018, 02:48:16 am
content: Tim and others pretty much summed it up. Software overhead keeping the ADC busy or hardware to temporarily override the uP.For a uP recommendation, I've used a Microchip PIC16F882's ($1.50USD) enhanced capture compare module for cycle by cycle control of motor controllers and SMPS in the past. I've used the comparator to prevent hard commutation and keep a flyback at resonant frequency.All in hardware, it auto shutdowns and auto restarts each cycle so there's no software overhead once setup.

author: Glenn0010
author_rank: Regular Contributor
timestamp: March 18, 2018, 05:49:04 pm
content: I have started looking at some MCUs to switch to them in the future. Looking at the STM series of MCUs some where in the STM32L as they also have an onbard EEPROM as that will allow me to save settings and alter them. They have a special timer for mtoor control including dead time a XOR gate for the hall sensors etc, but Ill look more into it so see all the features they have and something like what you said above for the cycle by cycle limiting.

author: nctnico
author_rank: Super Contributor
timestamp: March 18, 2018, 05:52:55 pm
content: Quote from: Glenn0010 on March 16, 2018, 06:54:22 amThe PWM timer uses the same MATch signals so you can create an extra match event to position the ADC samplepoint.

author: Glenn0010
author_rank: Regular Contributor
timestamp: March 18, 2018, 06:29:36 pm
content: Quote from: nctnico on March 18, 2018, 05:52:55 pmThat's awesome! But to be honest I do not really understand which channel to choose. I think the best way to go about it is to trigger on a match 0 event of the PWM timer, however which MATch signal is connected to this? MAT0.0?From the channels in the START field which one do I choose as I cannot find any reference in the datasheet to which match channels are connected to the PWM timerThanks so much for your help