Current Control: Digital Filter Choice

Thread Starter

TechWise

Joined Aug 24, 2018
126
I am designing an inverter which uses three phase voltage measurments as part of the control scheme.

My PWM and sampling frequency is 10kHz and the frequency of the output current is 50Hz. I have applied a very simple digital low-pass filter with a cut-off at 1kHz to the measured voltages which has improved the performance of the controller significantly. However, I would prefer a filter with a sharper roll off since this introduces around 3deg phase shift around 50Hz and there is still some high frequency content getting by.

What would be the next step up the complexity scale in terms of filtering? I've thought about just cascading a few first order filters. I've also seen both FIR and IIR filters discussed in this context. It's a while since I did any sort of DSP class so I'm unsure how to proceed. What sorts of filter would be appropriate here?
 

Papabravo

Joined Feb 24, 2006
14,399
Just to put it in realistic terms:
  1. Were are the passbands
  2. Where ate the stopbands
  3. What is the maximum allowed attenuation in the passbands
  4. What is the minimum attenuation in the stopsbands
These four requirements will define the transition bands and guideyou in the direction of a filter topology. A couple of other points:
  1. Cascading 1st order sections is a really stupid way to go unless you can account for the loading effects of the 2nd section on the 1st and the 3rd on the 2nd and so forth.
  2. All digital filters require an anti-aliasing ANALOG front end.
Now lets start again and put the horse before the cart.
 

Thread Starter

TechWise

Joined Aug 24, 2018
126
Apologies for the lack of detail in the original post. Becasue of the type of current controller I'm using, it is very difficult to come up with exact requirements for the filter, because the switching frequency is variable. In theory, it could switch as slowly as 50Hz, making the filtering impossilbe. In practice, the switching tends to occur at around 2.5kHz and above.

There are two things I am trying to keep out of my measurements:
  1. High frequency components in the current due to the switching action of the converter.
  2. Spikes in the measured values induced by the rapid di/dt from the main switching semiconductors.

To try and answer the previous questions:
  1. My aim is to remove any high frequency components from the current measurements so that my current controller can regulate the fundamental 50Hz component.
  2. I am regulating a sinusoidal current whose frequency is 50Hz (+/- ~1Hz). Therefore, signals from around 49-51Hz are the passband. Ideally, I would not want the 50Hz component to be attenuated or phase shifted at all. In practice, let's say that 2% attenuation is acceptable with up to 2deg phase shift.
  3. The attenuation in the stop bands should be as much as possible. Let's say signals above 1kHz should be attenuated to less than 10% of their original values.

I am aware of the loading effect of simple RC filters when cascaded together without a buffer. I had not considered that there would be a digital manifestation of this effect. I had not yet given cascaded filters any serious thought. I have provided an anti-aliasing filter as close to the ADC as possible.

The simple first-order low-pass filter I've employed so far has worked reasonably well for initial testing, however, it will now be a week before I get back into the lab so I thought I would spend the time wisely simulating new filtering options.
 

andrewmm

Joined Feb 25, 2011
573
means of removing the High frequency noise, and the spikes of switching. make certain you sample at the correct time..

Actualy, as the noise is so small compared to the voltage being measured, it should make little difference. The Remember also the sampling therum and noise. if your sampling at say 1 MHz, then you MUST have a low pass analog filter on the input to the ADC with a stop band of at least 6 * the number of bits you want dbs attenuation at half the sample frequency.

So if you want 4 bits out of the ADC, and ADC is sampling at 1 MHz, then you need a filter thats at least 6 * 4 , 24 db down at 500 KHz.

If you have say a 1 KHz analog filter on the input the to the ADC, then all the switching spikes are going to be removed,

All filters by definition, has an effect on the phase of a signal.

My guess, and thats al it is , is that the mechanics / wirring of the system is giving you the noise, from pickup / earth loops or such like, and digital filtering is not the way to mask this at this stage in the design.
 

Thread Starter

TechWise

Joined Aug 24, 2018
126
means of removing the High frequency noise, and the spikes of switching. make certain you sample at the correct time..

Actualy, as the noise is so small compared to the voltage being measured, it should make little difference. The Remember also the sampling therum and noise. if your sampling at say 1 MHz, then you MUST have a low pass analog filter on the input to the ADC with a stop band of at least 6 * the number of bits you want dbs attenuation at half the sample frequency.

So if you want 4 bits out of the ADC, and ADC is sampling at 1 MHz, then you need a filter thats at least 6 * 4 , 24 db down at 500 KHz.

If you have say a 1 KHz analog filter on the input the to the ADC, then all the switching spikes are going to be removed,

All filters by definition, has an effect on the phase of a signal.

My guess, and thats al it is , is that the mechanics / wirring of the system is giving you the noise, from pickup / earth loops or such like, and digital filtering is not the way to mask this at this stage in the design.
The sampling is synchronised with the PWM which is fine when I'm using traditional sinusoidal PWM. However, as I said, in this case, I'm using a modulation approach with variable switching frequency. This means there is ripple in the measured signals which is below the nyquist frequency of the ADC, so it is not removed by the anti-aliasing filter. This is why I want to perform additional filtering.

As you've pointed out, noise pickup should ideally be minimised at the design stage. This has been done as much as possible at a hardware level. However, due to the need to use a development board with the microcontroller on it, the traces from the anti-aliasing filter to the ADC input are longer and more exposed than I would ideally like. There will be some noise induced on these traces of various frequencies irrespective of what the anti-aliasing filter and any other circuits before that point do. Even if my measurement circuitry were idealised and no noise was pickup up, there would still be distortion of the measured quantity due to the nature of mains voltage.

EDIT: I am measuring both current and voltage. So yes, the noise on the voltage measurement is small in relation to the fundamental, however, noise is picked up in the low voltage signal conditioning circuitry. As explained, the current measurements contain noise and high-frequency components.
 

andrewmm

Joined Feb 25, 2011
573
Ok, sorry , we get so many on here that do not know about anti alias filters and such like, we get defensive.
My apologies.


what sort of filter was one of the original questions.
in essence , it does not matter, FIR, IIR, CIC , analog or digital , all are equivalent for your application.
The fundamental advantage of FIR over IIR is stability, the advantage of IIR over FIR is much less resources,

I'd suggest, that you are not going to be resource limited.


Can I point you at this , The open energy monitor.

https://learn.openenergymonitor.org/electricity-monitoring/ctac/how-to-build-an-arduino-energy-monitor

Its basically a single phase or three phase , current / voltage monitor, that runs on the Arduino or the Raspberry Pi systems,
used in various projects , which sounds like its just the sort of measurements your doing, measuring power.

You will also see in there how the bias removal is done and the phase shift is compensated.
 

Thread Starter

TechWise

Joined Aug 24, 2018
126
Ok, sorry , we get so many on here that do not know about anti alias filters and such like, we get defensive.
My apologies.


what sort of filter was one of the original questions.
in essence , it does not matter, FIR, IIR, CIC , analog or digital , all are equivalent for your application.
The fundamental advantage of FIR over IIR is stability, the advantage of IIR over FIR is much less resources,

I'd suggest, that you are not going to be resource limited.


Can I point you at this , The open energy monitor.

https://learn.openenergymonitor.org/electricity-monitoring/ctac/how-to-build-an-arduino-energy-monitor

Its basically a single phase or three phase , current / voltage monitor, that runs on the Arduino or the Raspberry Pi systems,
used in various projects , which sounds like its just the sort of measurements your doing, measuring power.

You will also see in there how the bias removal is done and the phase shift is compensated.
No need to apolgise. It's important to get the basics right before getting too carried away. A coworker of mine is currently learning the hard way that no amount of digital filtering is going to cure horrible analogue design. Fortunately, I've done my best at the hardware design stage so the digital filter is just to remove unwanted noise that creeps in on the way to the ADC on the development board.

I will check out this resource that you have linked. I'm using a Texas Instruments C2000 series (TMS320F28379D) so I have a lot of computing power at my disposal with floating point support. It also has a dual core so I could let the second core deal with some of the computation if need be. It sounds like the FIR may be the way to go with this in mind.
 

Papabravo

Joined Feb 24, 2006
14,399
Here is the thing about filters. It is way easier to filter things away from the frequency of interest. It is common in switching converters to have a fixed frequency and a variable duty cycle. In that fashion you can have a single stage LC filter with a corner frequency that is a small fraction of the switching frequency and that filtering problem is about as simple as they come. The more difficlult problem is getting the right gain and phase margins for the loop response to load transients. I think you need to recalibrate. It sounds like this might be your first converter design. What references have you read?
 

Thread Starter

TechWise

Joined Aug 24, 2018
126
Here is the thing about filters. It is way easier to filter things away from the frequency of interest. It is common in switching converters to have a fixed frequency and a variable duty cycle. In that fashion you can have a single stage LC filter with a corner frequency that is a small fraction of the switching frequency and that filtering problem is about as simple as they come. The more difficlult problem is getting the right gain and phase margins for the loop response to load transients. I think you need to recalibrate. It sounds like this might be your first converter design. What references have you read?
I am aware of how filtering is achieved where the switching frequency is fixed at an order of magnitude greater than the fundamental. I am familiar with L, LC and LCL filters for removing the harmonics from the output current. I am familiar with tuning controllers to regulate the output current.

What I'm doing at the moment is a form of predictive control where much of the traditional control techniques are not applicable. The controller operates in the stationary reference frame, so the inputs to the controller are the measured sinusoidal quantities. Extrapolation is used to predict the measurements in advance to compensate controller delay and this stage of the process is quite sensitive to any noise on the measurements. I have discussed this with a couple of people who have done this in the past and they found that things could be improved simply by inserting a first-order digital low pass filter. However, they were NOT using a variable switching frequency. This is why I am looking for something with a sharper roll-off, because I cannot guarantee that the problem harmonics will be above 10kHz. They could be much closer to the fundamental in my case.

This is not my first converter design, but it is the largest I have built, the only one that is grid connected and the only one with variable switching frequency. The hardware design is based on days of reading application notes from TI, Infineon, Analog Devices, Linear Technology etc just to identify the main parts that would be needed. This was followed by weeks being spent designing the individual subsystems: isolated power supplies, gate drivers, voltage measurement, current measurement, shifting and scaling, filtering. All simulated in LT Spice and TINA-TI, followed by testing on a single-phase prototype board I knocked up. This was followed by many hours spent laying out the PCB and paying attention to high-current paths, high and low voltage areas, return paths, functional and safety isolation etc. This was aided by input from several experienced people and it went through two or three revisions before manufacture. After it was built, it was all tested thoroughly and "beasted" up to double its rated power and four times its rated switching frequency under the watchfull eye of a thermal camera with an IsoVu system observing the switching waveforms.

I suppose I'm telling you this just to make it clear that this is not something thrown together on a breadboard that I'm trying to squeeze unrealistic results out of. I've put a lot of work into the hardware and the overall system, complete with control, does work. However, there is still some noise and unwanted harmonics creeping into the digitized measurments, hence why I am looking at filtering.
 

Papabravo

Joined Feb 24, 2006
14,399
I am aware of how filtering is achieved where the switching frequency is fixed at an order of magnitude greater than the fundamental. I am familiar with L, LC and LCL filters for removing the harmonics from the output current. I am familiar with tuning controllers to regulate the output current.

What I'm doing at the moment is a form of predictive control where much of the traditional control techniques are not applicable. The controller operates in the stationary reference frame, so the inputs to the controller are the measured sinusoidal quantities. Extrapolation is used to predict the measurements in advance to compensate controller delay and this stage of the process is quite sensitive to any noise on the measurements. I have discussed this with a couple of people who have done this in the past and they found that things could be improved simply by inserting a first-order digital low pass filter. However, they were NOT using a variable switching frequency. This is why I am looking for something with a sharper roll-off, because I cannot guarantee that the problem harmonics will be above 10kHz. They could be much closer to the fundamental in my case.

This is not my first converter design, but it is the largest I have built, the only one that is grid connected and the only one with variable switching frequency. The hardware design is based on days of reading application notes from TI, Infineon, Analog Devices, Linear Technology etc just to identify the main parts that would be needed. This was followed by weeks being spent designing the individual subsystems: isolated power supplies, gate drivers, voltage measurement, current measurement, shifting and scaling, filtering. All simulated in LT Spice and TINA-TI, followed by testing on a single-phase prototype board I knocked up. This was followed by many hours spent laying out the PCB and paying attention to high-current paths, high and low voltage areas, return paths, functional and safety isolation etc. This was aided by input from several experienced people and it went through two or three revisions before manufacture. After it was built, it was all tested thoroughly and "beasted" up to double its rated power and four times its rated switching frequency under the watchfull eye of a thermal camera with an IsoVu system observing the switching waveforms.

I suppose I'm telling you this just to make it clear that this is not something thrown together on a breadboard that I'm trying to squeeze unrealistic results out of. I've put a lot of work into the hardware and the overall system, complete with control, does work. However, there is still some noise and unwanted harmonics creeping into the digitized measurments, hence why I am looking at filtering.
That is an interesting essay. How come you can't (won't) answer the question I posed in post #4?
 

andrewmm

Joined Feb 25, 2011
573
You have a good processor there, Ti aim it at the control application,
there are some great libs, such as the digital control lib for them,

https://www.ti.com/tool/C2000WARE

BUT

The system design of the product needs to be right,
symulink is the "standard" way of defining the system,

what system design docs do you have for this application ?

Im concerned that "putting a filter" in might not be the solution, but a patch.
( once had a student, who was in theory graduate , asked around till they got answer he wanted , how to get rid of a glitch , the answer they got was an RC filter. unfortunately, the glitch was on a fast digital circuit, so the RC filter totally killed the response. The correct answer was to register the data , but as they would not share the system design, the wrong answer was arrived at. Cost the company a fortune to fix )
 

Thread Starter

TechWise

Joined Aug 24, 2018
126
That is an interesting essay. How come you can't (won't) answer the question I posed in post #4?
I have attempted to answer your question in post #5. To recap what I said:
  • Passband - I am only interested in signals at mains frequency 50Hz (+/- ~1Hz). Therefore, signals from around 49-51Hz are the passband.
  • Stopbands - I see no need to filter out anything below the passband outlined above. I would like to filter out components above 1kHz.
  • Maximum Allowed Attenuation in the Passbands - The 50Hz component is the thing I am regulating, therefore *ideally* I would not want it phase shifted or attenuated. In practice, I would accept 2% attenuation with up to 2deg phase shift.
  • Minimum Attenuation Allowed in the Stopbands - I have no interest at all in signals above ~50Hz. Therefore, as a starting point I would suggest that signals in the stopband should be attenuated to less than 10% of their original values.

I am not deliberately trying to withold information or be vague. I know little about digital filtering, so I have posed the question to see if what I want to do is even feasible and, if so, what would be a suitable filter to employ. I have tried to solve the problem at its source using analogue techniques, however, as I said in post #7, my microprocessor is mounted on a development board so the traces leading to it are longer than I would have liked, so noise is creeping into the signals right before they make it to the ADC. This leaves a digital filter as a potential option to remove them.
 

Thread Starter

TechWise

Joined Aug 24, 2018
126
You have a good processor there, Ti aim it at the control application,
there are some great libs, such as the digital control lib for them,

https://www.ti.com/tool/C2000WARE

BUT

The system design of the product needs to be right,
symulink is the "standard" way of defining the system,

what system design docs do you have for this application ?

Im concerned that "putting a filter" in might not be the solution, but a patch.
( once had a student, who was in theory graduate , asked around till they got answer he wanted , how to get rid of a glitch , the answer they got was an RC filter. unfortunately, the glitch was on a fast digital circuit, so the RC filter totally killed the response. The correct answer was to register the data , but as they would not share the system design, the wrong answer was arrived at. Cost the company a fortune to fix )
I am very pleased with the processor so far as it has been relatively easy to program and there's lots of discussion about it on the TI forums where you can pick up useful information or ask questions.

I have modelled my controller under various scenarios in Simulink. This is obviously a very useful tool to play with the parameters and experiment with tuning and suchlike. As you know, when you move to the hardware, problems start to creep in which you haven't necessarily modelled, like noisy signals, delayed signals etc.

I am reluctantly trying to "patch" a problem which has been forced on me by using a development board in a fairly harsh EMC environment. The solution would potentially be to mount the processor directly onto the PCB, allowing all signal carrying traces to be shortened considerably to reduce pick-up. The converter is part of my PhD project, so using the develoment board was an attractive solution, otherwise I'd have to mount the processor directly and deal with implementing my own isolated JTAG interface, as well as trying to physically solder on a BGA or QFP package outside of a professional SMD assembly setting. The development board avoided all this but the price I pay is that I have three inches of copper track between my anti-aliasing filter and the ADC which is allowing noise to creep in.
 

Papabravo

Joined Feb 24, 2006
14,399
If noise is being coupled in on "long" traces, then you put an analog LPF at the end of the "long" traces just in front of the ADC. You don't want the corner of the analog filter close to the edge of your narrow passband. I would start with a corner at 100 Hz. I would then an FIR filter since you have the processor horsepower. One advantage of the FIR filter is that when the input disappears so does the output of the filter. I think this will be important for you. Here, in the digital domain, is where you can narrow the bandwidth to your tighter margins.
 
Top