PCMC+PSFB on STM32 is it possible? - Page 1
Forum section: electronics / general

author: Alex-lab
author_rank: Contributor
timestamp: June 07, 2024, 07:39:27 am
content: Hi,Up to now I have been using STM32G4 to control phase-shift full-bridge (PSFB) in voltage control mode (VCM). Now I would like to add peak current control mode (PCMC) for better performance, but it appears that none of STM32G4 is capable with such capabilities. At least I was unable to find the way for it.Did I miss something? What is the best way for such digitally controlled power supply?I have thought about some hybrid, a digital+analogue approach by coupling STM32 with something like UC28950, but I still believe that should be a better way...Thanks,

author: fourtytwo42
author_rank: Super Contributor
timestamp: June 07, 2024, 01:32:49 pm
content: I also found the STM32 PWM poor in terms of facilities and adaptability, of course they use the same block of IP in all there offerings so they are all the same.I thought of pairing it with an FPGA but that's getting expensive so in the end I changed to the motor control variety of the PIC24EP series, unfortunately a different IDE and programmer/debugger to pay for.

author: uer166
author_rank: Super Contributor
timestamp: June 07, 2024, 07:59:12 pm
content: Quote from: Alex-lab on June 07, 2024, 07:39:27 amHRTIM with reset event inputs (for your peak current limit) should be able to do this, the regular advanced timers are way too limiting. Have you looked into that peripheral?

author: mtwieg
author_rank: Frequent Contributor
timestamp: June 08, 2024, 02:01:43 pm
content: At a glance at the reference manual, it looks like the STM32G4 has all the requisite building blocks for doing current mode control:1. PWM synthesis controlled by external events2. Analog comparators which can generate events for the PWM synthesis based on the sensed current3. DACs which can connect to the inputs of the comparators (12 bits should be sufficient)4. DACs can be set up to generate ramp/sawtooth waves to implement slope compensationI've worked a lot with C2000 MCUs which are aimed at such applications, and the feature set looks comparable. Actually configuring these peripherals to work together properly is definitely not straightforward though. I would hope that STM's documentation is better than TI's...

author: Siwastaja
author_rank: Super Contributor
timestamp: June 08, 2024, 05:19:02 pm
content: Quote from: mtwieg on June 08, 2024, 02:01:43 pmYes. First time I did this (on STM32F334), all of the mentioned* many years ago setting it all up wasn't too difficult, in principle... just that ST, as usual, has some silicon bugs/undocumented "features" such as some invert bit here not doing anything at, and some other bit there completely breaking non-related IO pin... So before committing to a large batch of unmodifiable PCBs, do a prototype first. Which hopefully is quite obvious anyway.It's all in the reference manual, just build a prototype (around devboard, or spin an early revision of the actual board) and read the related sections on the reference manual and start working.*) expect that instead of slope compensation, which I did not need due to by-design <50% duty cycle, I used the DACs for arbitrary current waveform generation

author: Alex-lab
author_rank: Contributor
timestamp: September 19, 2024, 08:11:55 pm
content: Thank you for all replies. I was trying to setup HRTIM in a proper operation mode, but found some weird description in the refmanual (rev.8, chapter 27.3.9, p.879-880).I would like to use blanking as highlighted by yellow colour, and struggling with its operation. The example, which is given in the text (green), is quite confusing because none of the timers (B or C) has TIMFLTR6 as output of any Tx2. Do I understand this table correctly? Is this typo in the table or in the example? May other numbers be also inaccurate?Thanks for any ideas.

author: multipla
author_rank: Contributor
timestamp: September 20, 2024, 06:07:11 am
content: If you have a working PCB with the controller or a dev board already, I would also suggest trying out how the slope looks like first.I have tried using the internal DAC of an NXP KV44 to create the setpoint and subtract a slope from it, but there were lots of glitches when many bits of the DAC word changed (midpoint glitches). This was unusable for PCMC, I ended up adding the slope externally before feeding it to an external comparator. The internal comparator had quite long and inconsistent delay times too, depending on the operating point.

author: Alex-lab
author_rank: Contributor
timestamp: September 20, 2024, 07:48:15 am
content: Although the table is still unclear. It seems that the basic operation was achieved.I am using G474RET6 based Nucleo board and Arduino.Below is my basic peripheral configuration, the pins highlighted in blue are available for probing and behave generally as expected:As I didn't have a real device, I had to make a gyrator-based inductor current emulator:Some important registers:Waveform examples:Quote from: multipla on September 20, 2024, 06:07:11 amNot completely sure, but for me the slope looks as expected (see above). However, I worry about that additional short spikes in the output signal of CH_C1/2, which are shown in the last attachment.I was trying to play with hysteresis, event counter filter etc., but was unable to get rid of them even for a simple desktop layout without any power conversion and any serious noise.

author: mtwieg
author_rank: Frequent Contributor
timestamp: September 21, 2024, 01:06:56 pm
content: Is sounds like you were successful implementing a voltage-mode phase shifted bridge, and now you want to modify it to do peak current mode control. But I suspect rather than modifying what you have, you should start from scratch.For example, is there some reason you're using center-aligned/up-down count mode for counters A and C? Using up-count mode might make things a lot simpler. I don't believe center-aligned operation has any benefit for peak CMC.

author: Alex-lab
author_rank: Contributor
timestamp: September 21, 2024, 01:32:48 pm
content: Quote from: mtwieg on September 21, 2024, 01:06:56 pmWhy is not this a current mode?

author: mtwieg
author_rank: Frequent Contributor
timestamp: September 21, 2024, 11:21:37 pm
content: Quote from: Alex-lab on September 21, 2024, 01:32:48 pm.... what?You said this:Quote from: Alex-lab on June 07, 2024, 07:39:27 amI'm saying you shouldn't "add" preak CMC to the VMC design, but instead redesign it with peak CMC in mind.

author: Alex-lab
author_rank: Contributor
timestamp: September 22, 2024, 11:43:47 am
content: Quote from: mtwieg on September 21, 2024, 11:21:37 pmOk, this is exactly what I showed in my previous post as previously I used regular Timer, but now it's using HRTIM.

author: mtwieg
author_rank: Frequent Contributor
timestamp: September 22, 2024, 12:36:48 pm
content: Ok, then why are you using center-aligned mode? I'm not an expert on STM's HRTIM, but in general I've found center-aligned operation to come with more limitations. As far as I can tell, all of STM's documentation suggests using single-slope mode for peak CMC as well.

author: Alex-lab
author_rank: Contributor
timestamp: September 22, 2024, 01:30:26 pm
content: As ST does not provide any relevant examples for full bridge phase shift designs, I had to use an example from TI (TIDM-02000), where up-down mode is the core of the approach.In up-down you can differentiate the front and end of the pulse explicitly (one relates to UP, another to DOWN direction). Then you add a toggle function driven by external event (comparator) and that's it. I am not saying that with single-slope you cannot achieve similar operation, but it is definitely more complex as requires special measures.TIDM-02000 shows the circuit, and for me it is not quite clear, why they used a full bridge rectifier for current transformer, if it is operated in unipolar mode?

author: mtwieg
author_rank: Frequent Contributor
timestamp: September 22, 2024, 04:35:15 pm
content: Quote from: Alex-lab on September 22, 2024, 01:30:26 pmInteresting, I don't quite understand why they would use up-down mode for this, I'm guessing it somehow makes implementing their synchronous rectifier control easier.QuoteThe action qualifier (AQ) submodule in the C2000 ePWM modules do recognize the counter direction in determining actions, but I don't know if HRTIM has equivalent functionality. I also don't see why you'd need to differentiate the edges of the pulse in such a way.QuoteI doubt it, but it depends on exactly how the underlying PWM logic works.For example, you said you were struggling to implement blanking. In the C2000 design, this is done using the digital compare (DC) submodule, which is IMO by far the most complicated and confusing aspect of the entire ePWM module (I usually don't make use of any of the digital compare functions, but just configuring it to pass events through is insanely complicated). I highly doubt the HRTIM works in a similar way. You should look at how HRTIM implements blanking and start from there.QuoteAgreed, that is strange. I wonder how the magnetizing flux is reset properly...

author: Alex-lab
author_rank: Contributor
timestamp: September 22, 2024, 06:02:45 pm
content: Quote from: mtwieg on September 22, 2024, 04:35:15 pmI suppose, it is because on the over current event we need to toggle the output states, but on the normal ending (if no comp event) we should switch outputs to specific levels.All other things like blanking and slope compensation using DAC are simple in implementation. My question was about a particular table from the manual, but it seems work fine.QuoteIn my future design I am planning to use unipolar circuit as in the datasheet for UCC28950.

author: Alex-lab
author_rank: Contributor
timestamp: September 24, 2024, 12:27:10 pm
content: I am wondering if I need to change the slope magnitude for low duty cycle? I know that the DAC value controls the peak current, but what is about the slope at low duty cycle? Some appnotes (SLUA837) states that it is a good thing to have slope compensation even at low duty cycles. Despite it is mainly designed for 50% and over. Just for more predictable behaviour in noisy environment etc. May it be practical to reduce the slope at low duty cycles?

author: mtwieg
author_rank: Frequent Contributor
timestamp: September 28, 2024, 01:04:02 pm
content: Quote from: Alex-lab on September 24, 2024, 12:27:10 pmIt's been a while since I looked closely at the math of slope compensation/subharmonic oscillation. Yes, having some slope compensation can be beneficial even when D<50%. The D>=50% threshold is based on the assumption that there are no delays in the system. For example if your controller has a delay equivalent to 5% of a PWM period, then you should have slope compensation at D>=45%. Having a bit of slope compensation might be justifiable, but I would rely on thorough empirical testing.Changing the slope dynamically will act as a perturbation to the system, so I would not take that approach unless you've modeled everything correctly and can show a clear benefit.

author: Alex-lab
author_rank: Contributor
timestamp: October 27, 2024, 01:55:30 pm
content: Thanks. For now I just keep it constant and it works as expected. Really impressive set point step response!But I have one more question. Previously, working in voltage mode, when controller reduced the duty cycle below a certain minimum level (<3%), the PWM signal was shut down to zero and overall converter was turned into a "period skipping" mode.Using PCM control I have no direct access to the current duty cycle value, thus cannot implement the same period skipping approach. As a result, when pulses are getting shorter than some critical value, the phase of variable leg jumps by ~180 deg., which cause almost 100% power. It looks like comparator is triggered twice.Of course, this behaviour is unwanted as can easily damage the device.What can be used as a parameter to prevent this situation?I tried to use DAC value, to skip period if it goes below some small value (<5%), it skips periods, but the phase is still inverted...May extended Blanking of current transformer signal help in this case?Is there any special name for this situation?Thank you.

author: mtwieg
author_rank: Frequent Contributor
timestamp: October 28, 2024, 12:09:04 pm
content: Quote from: Alex-lab on October 27, 2024, 01:55:30 pmHmm could you show an example waveform of what you're seeing?The first thing that comes to mind is that your blanking is implemented such that transitions in the current comparator areignoredduring the blanking window. This is as opposed to the transitions beingdelayeduntil the end of the blanking window. The former case can lead to issues like what you describe (but it's probably not the only way).If possible I would also add a second current comparator whose threshold is always higher (maybe at the maximum peak current spec) than the first comparator, in order to limit peak current to a sane value in case the first comparator is missed. At least as a hack until a better solution is found.If this is your problem, and there's no way to make the blanking delay the comparator trip, then another workaround may be to implement a minimum

author: multipla
author_rank: Contributor
timestamp: October 28, 2024, 01:43:46 pm
content: Quote from: Alex-lab on October 27, 2024, 01:55:30 pmMaybe you could use the same concept in PCMC, but instead of the duty cycle you base this on when the peak current set point gets below a certain threshold and start skipping pulses then?A blanking might be necessary to implement anyway to filter out leading edge spikes on the primary current signal. What are the specs of your converter?

author: Alex-lab
author_rank: Contributor
timestamp: November 08, 2024, 07:53:45 am
content: Quote from: mtwieg on October 28, 2024, 12:09:04 pmYes, I know about these modes, and it should be correct, otherwise this false-triggering would happen for any DAC setpoint and the system would be unable to regulate.QuoteHm, quite interesting approach, I will try to work around using it.Quote from: multipla on October 28, 2024, 01:43:46 pmWhen I limit pulse width, I limit the output voltage. When I limit DAC setpoint, I limit the current.I am attempting to properly manage low impedance load conditions (close to short circuit). In other words, to reduce voltage if the load is of low impedance, this what is happening under voltage control. However, if the current is limited then period skipping occurs on high-Z loads with little current, which is not really practical.What I am thinking is to estimate the load impedance from voltage/current ratio, and manage this situation in software.I also heard that current mode, can be turned into voltage mode if the slope compensation is too high. Thus another option may be to stop reducing DAC below certain min limit, and than reduce the slope only, which max value shut down converter in period skipping mode. There should not be any problem to implement as both DAC and Slope are available from the same register.

author: Sniper1
author_rank: Regular Contributor
timestamp: December 16, 2024, 07:02:09 pm
content: Quote from: Alex-lab on November 08, 2024, 07:53:45 amHow is it going? did you figure it out?

author: multipla
author_rank: Contributor
timestamp: December 17, 2024, 01:30:14 pm
content: Quote from: Alex-lab on November 08, 2024, 07:53:45 amDo you have a normal rectifier on the secondary or a synchronous one? That affects the waveforms and behaviour quite a lot, especially in low load conditions.In dead short circuit situations it's easier to measure and control the current instead, if you can do this somehow...

author: euthon
author_rank: Newbie
timestamp: December 23, 2024, 04:54:32 pm
content: Hi Alex!Would you mind sharing some details on how you configure the HRTIM peripheral for phase shifting? Right now I’m trying to build a voltage mode phase shifted full bridge.Here is the HRTIM configuration I came up with so far. The timer A drives the non-modulated bridge leg. The timer B drives the modulated (leading) leg. The Master timer is used for synchronization. All three timers are set to the same period. The timer A is configured in half mode and is reset on master’s period. The timer B is also set to half mode and is reset on one of the master’s compare registers. Thus, the value in that master compare register determines the phase shift between the timers A and B.This config seems to work, but I’m wondering if it can be done more efficiently, reliably, etc.

author: Sniper1
author_rank: Regular Contributor
timestamp: June 18, 2025, 08:14:56 pm
content: Quote from: Alex-lab on June 07, 2024, 07:39:27 amDid you manage to make it work in the end?

author: Alex-lab
author_rank: Contributor
timestamp: June 18, 2025, 10:48:11 pm
content: Quote from: euthon on December 23, 2024, 04:54:32 pmNo, this is the correct method.Quote from: Sniper1 on June 18, 2025, 08:14:56 pmNot yet, I had to put off this project so far as I was unable to achieve reliable operation.

author: Sniper1
author_rank: Regular Contributor
timestamp: June 19, 2025, 07:18:01 pm
content: okI am also going to implement PSFB on a STM32.Did u use a MCU with a High resolution timer or not?or rather did you try using normal timers or the special one?

author: Alex-lab
author_rank: Contributor
timestamp: June 19, 2025, 11:55:33 pm
content: Originally, my project had been using F1 where I used regular timers. After that it evolved through F3, F4 to G4 where HRTIM is used. All that story is about voltage mode control. For current mode I have not found the solution yet as I have no time at the moment. I am still thinking about digital-analog hybrid approach.

author: Sniper1
author_rank: Regular Contributor
timestamp: June 23, 2025, 05:34:00 pm
content: Quote from: Alex-lab on June 19, 2025, 11:55:33 pmI am starting with G4 since i am not the best programmer and as of now i am at the design stage .

author: uer166
author_rank: Super Contributor
timestamp: June 23, 2025, 09:29:18 pm
content: Quote from: Sniper1 on June 19, 2025, 07:18:01 pmI would highly recommend HRTIM, but not for its' "high resolution" feature, you can totally ignore that most of the time.The real value is the output set/reset crossbar that can be driven from many different sources (comparators, other timers, etc), and all HRTIM instances can be synchronised together quite easily.