Author Topic: Cycle by Cycle current limiting Microcontroller (Help)  (Read 4439 times)

0 Members and 1 Guest are viewing this topic.

Offline Glenn0010Topic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: mt
Cycle by Cycle current limiting Microcontroller (Help)
« on: March 15, 2018, 07:09:13 pm »
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?
« Last Edit: March 15, 2018, 07:33:53 pm by Glenn0010 »
 

Offline fourtytwo42

  • Super Contributor
  • ***
  • Posts: 1201
  • Country: gb
  • Interested in all things green/ECO NOT political
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #1 on: March 15, 2018, 08:45:20 pm »
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.
 

Offline Glenn0010Topic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: mt
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #2 on: March 15, 2018, 09:17:04 pm »
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 rectification

In 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 20A


In 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.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9935
  • Country: us
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #3 on: March 15, 2018, 09:51:08 pm »
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
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 28013
  • Country: nl
    • NCT Developments
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #4 on: March 15, 2018, 09:59:23 pm »
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.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22434
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #5 on: March 15, 2018, 11:08:46 pm »
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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2733
  • Country: us
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #6 on: March 16, 2018, 03:34:53 am »
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.
 

Offline Glenn0010Topic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: mt
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #7 on: March 16, 2018, 06:54:22 am »
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

I 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.

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.

I'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.




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

That is what I am going to improve in the future since all my hardware is set.


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.

Yes 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


 

Offline Poe

  • Frequent Contributor
  • **
  • Posts: 250
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #8 on: March 17, 2018, 02:48:16 am »
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.

 

Offline Glenn0010Topic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: mt
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #9 on: March 18, 2018, 05:49:04 pm »
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.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 28013
  • Country: nl
    • NCT Developments
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #10 on: March 18, 2018, 05:52:55 pm »
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.

I'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.


The PWM timer uses the same MATch signals so you can create an extra match event to position the ADC samplepoint.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Glenn0010Topic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: mt
Re: Cycle by Cycle current limiting Microcontroller (Help)
« Reply #11 on: March 18, 2018, 06:29:36 pm »

The PWM timer uses the same MATch signals so you can create an extra match event to position the ADC samplepoint.

That'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 timer

Thanks so much for your help
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf