Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

basics of PID control

Status
Not open for further replies.
There are a few ways to do averaging. First, the capacitor can help you if you measure current on the solar cell side, as we discussed. Second, you can put your current sensor through an analog low pass filter which will filter out a good amount of the PWM switching. Third, you can digitally filter or average.

The problem with two values, one for on and one for off, is that you are not accounting for the duty cycle variation. You really want a weighted average with the weights given by D and 1-D. Two values does not do that, but filtering can do the effective averaging and then you only need to sample one value to get the average. There is no one right way to do this, and you will have to figure out a method that meets your criteria and design philosophy.

Some funny things can happen if you are not careful, and I can give one example of an unexpected result that I got once. One time I used digital control with a 100 kHz sample rate, and I used a PWM frequency of 100 kHz. I used external analog filtering on the current sensing, and then sampled the values with an A/D converter. However, since my control rate and my PWM rate were exactly the same and phase locked, the PWM frequency variations in my current readings caused me to always sample at the same point in the AC variation, which resulted in an offset error. The solution was to change my PWM rate to 111,111 Hz which allowed my samples to scan over the entire AC cycle and effectively average out the PMW frequency from the measurement. Many things you did not anticipate will show up when you actually get to building this thing.
 
Q1. As Steve already said, the current at MPPT is already slightly lower.

Q2. Correct.

Q3. No. As Cin charges to Voc, panel cannot push current any more.

Q4. Yes. If you connect the suitable resistor to this panel, Cin will be kept at MPPT. In case of the resistive value, you can find an equlibrium point graphically. Look at the panel I-V curve. Draw the resistor I-V curve (which is a straight line V = I*R). The equilibrium I and V are where these two lines cross.

Q5. Yes. The 440 Ohm resistor will have a shallower I-V curve, so the equlibrium will be at higher V and (much) lower I.

Q6. Yes. The steeper I-V curve for the resistor will cross the panel's I-V curve at lower voltages, but with not so much gain in current.
 
For the "input" power, it is better to measure between the panel and capacitor, because it is steady and doesn't turn on and off.

For the "output" power, it is better to measure right next to the battery. This is because part of the current is stored by the inductor, so the battery receives current even when the switch is off.
 
Thanks a lot, Steve, NG.

There are a few ways to do averaging. First, the capacitor can help you if you measure current on the solar cell side, as we discussed. Second, you can put your current sensor through an analog low pass filter which will filter out a good amount of the PWM switching. Third, you can digitally filter or average.

The problem with two values, one for on and one for off, is that you are not accounting for the duty cycle variation. You really want a weighted average with the weights given by D and 1-D. Two values does not do that, but filtering can do the effective averaging and then you only need to sample one value to get the average. There is no one right way to do this, and you will have to figure out a method that meets your criteria and design philosophy.

In my humble view, the easier approach would be to measure the voltage and current for a number of times and then taking average of the values, and finally calculating the power. Let's say that the frequency of PWM is 100 HZ which means cycle of 10 ms. The current and voltage values can be sensed, say, 30 times every second to find the average power. Will this work in your view? Thank you.

Regards
PG
 
First of all, 100 Hz sounds too low for a PWM frequency. I find external analog filtering off the sensors to be very effective and simplifies what must be done in code. Multiple samples and averaging in code can be very effective too. You are still very very far from specifying the critical factors that would allow you to answer these questions. PMW rate is one factor that determines where your filter cutoff frequency needs to be. What processor are you using, and how much computing power do you have. The algorithm and update rate of the controller matter. So far, I have not seen a clear specification of exactly what you will do. That's fine, as you are making progress and will get there. But, if things are not specified and if the solution is not simulated to help verify high chance of success, it's better to have options. Hence, carefully design your analog sensors, and condition the measurements with buffering and filtering before going into the A/D converters. This gives you the most flexibility.
 
Thank you.

First of all, 100 Hz sounds too low for a PWM frequency.

I was just using that value to get the point across.

In general terms, would it be a big problem if multiple samples are taken and then the averaging is done? Thanks.
 
In general terms, would it be a big problem if multiple samples are taken and then the averaging is done? Thanks.
In general yes it is a problem. But given your situation, and depending on your final implementation possibly not. Again, you have not defined things well enough, nor analyzed anything for me to say with confidence. However, I can say with confidence that it is good design practice to do as I said and provide buffering and filtering to your sensor readings.

The very first level of the problem relates to "aliasing". Remember the Nyquist rate? Let's say your PWM frequency is 100 kHz and your controller sample rate is 10 kHz. The PWM frequency and higher frequencies from noise and harmonics shows up in your measurements. You really don't want those high frequencies there when you sample. So now you put a low pass filter in to reduce those high frequencies. Well if the filter is already there and you want to filter/average for other reasons, why not filter at an even lower cutoff frequency? It's free filtering and does not eat up processing power on the coding side. Additional filtering digitally is also an option, but again this depends on the details. Filtering generally has consequences on the control side and usually the control analysis includes the filtering effects.

Again, your situation is relieved of many issues if you use the natural filtering of the Cin capacitor and choose that value well. Also, your simple control approach with P&O is not terribly sensitive to these issues. But, again, you have not defined anything clearly yet.
 
Thanks a lot.

I see your point now but let's first talk about sampling as a side topic. We can return to the main discussion later.

We will use this attachment for the queries. You might find this text about low-pass filter useful.

Q1: We are talking about unfiltered frequency spectrum of analog signal shown in the figure.

Although the high frequencies lying beyond 'red' dot are part of the original analog signal and they are required to reproduce 100% true representation of the signal, they can still be ignored in the sampling because their magnitude on average isn't that much significant, and inspite of their absence the signal can be reproduced almost accurately. To get rid of these high frequencies, we can use low pass filter whose critical frequency is equal to that of 'red dot'. Do I have it right?

Q2: Let's say the highest frequency in analog signal is 2 kHz. It means to sample this signal accuately, we need to use sampling rate of at least 4 kHz. What does this sampling rate of 4 kHz mean? Please have a look on Figure 13-3. The sampling rate of 4 kHz means that there are going to be 4000 sampling pulses per second.

Now coming to the question. I don't understand the shown "Sampling frequency spectrum". What does it really mean? We are just using 4000 sampling pulses per second where each pulse, in my view, can be approximated with an impulse function.

Regards
PG
 

Attachments

  • pro_lowpass.jpg
    pro_lowpass.jpg
    514.9 KB · Views: 748
  • pro_sampling.jpg
    pro_sampling.jpg
    653.3 KB · Views: 803
I think by "Sampling frequency spectrum" they meant the range of frequencies detectable by ADC at a given spampling rate.

What you're sampling is usually a complex signal consisting of different components, each having its own frequency spectrum. E.g., in your MPPT application you will have a noise coming from resistors and amplifiers, you will get ripple at your switching frequency and you will get slower components induced by loads, clouds etc.

It is your choice of what you want to sample, but certainly you do not the full spectrum (even if you're recording a music).

In MPPT:

You can go micro scale, so that you only filter out high freqency noise and sample at a rate faster than your switching frequency. You can then follow your ripple, and, perhaps, even make decisions in real time when to switch mosfet on or off based on your measurements. Then you need a low pass filter to take out high frequency noise, but to preserve your ripple.

You can go at larger scale and filter out both the high frequency noise and the switching ripple. You do not worry about the switching and let it run at a given duty cycle until you decide otherwise. This way you chose sampling frequency which is lower than your switching frequency. If you do that, you need a different low pass filter, which will eliminate noise and smooth out your ripple.
 
PG,

Before we try to delve too much farther here. Do you have an understanding of what frequency components will be in your measurements. Do you know what the input volage, input current, output voltage and output current will look like? This is important to know.

Consider the difference in measuring the solar cell current versus the input current to the converter after the Cin capacitor. The latter current is an on/off signal which huge components at the PWM frequency and low harmonics of that. Imagine sampling that and trying to filter and average the value. The solar cell current is not as bad because the capacitor helps the filtering or averaging. Still, there will be a PWM frequency component or ripple in the measurements. The input voltage is the same. The cap can not instantaneously change its voltage, but it can go up and down at the PWM frequency. This implies a high frequency ripple. The output side is similar. The coil acts as a filter for the current and current can not change instantaneously on the output, but still there is a ripple component at the PWM frequency. The battery voltage is really locked down. You can imagine the battery as if it is a huge capacitor. It takes a lot of current either in or out to change that voltage. So, the ripple is small on that measurement, but the ripple is still there, and you may want to filter that signal as best as you can.

Again, it is hard to talk about specifics because you have not nailed down any design parameters for us. Will sample rate be higher or lower than PWM rate? Typically is is lower and I would expect it to be lower, but you have not specified the values. What control will you use? You mentioned P&O, but we are talking about limiting functions as well which might be done with PID control or something else. What bandwidth do these controls need to have to prevent transients? You need to estimate it and nail down the design parameters. These things and many others will affect what filtering you want to implement.

At this stage, all I'm saying is that you should enable your design to accommodate whatever you might need. Design your sensor system and add buffers and filters with the ability to change the cutoff frequency of the low pass filtering. Then you won't get stuck later. At a minimum you want to use that filter as an anti-aliasing filter. But, you may also decide to go further and let that filter do the averaging for you, or to help stabilize the control feedback as a compensator.

There is much to do here and I recommend you focus first on understanding the basic operation of the buck converter and then establishing a schematic drawing of your system and nail down some design constraints. Then if you present that to us, we can give significantly more guidance. We can help you put in place a basic design that will have the necessary flexibility to do what you want later, once you know what you want. You may not know everything you want until you start playing with this experimentally. You will then learn more, learn faster and discover issues that you and the rest of us didn't even consider yet.
 
Hi

Though NG tried to help me with the queries from post #48, I'm still confused. Let me try again.

Q1: It looks like my Q1 wasn't clear enough so I need to rephrase it. We will use this attachment.

We can see that the frequencies lying between green and red points of analog signal are getting mixed with the sampling frequency spectrum. To overcome this aliasing problem, we need to filter all the frequecy components of the analog signal between green and red points.

To do this, we need to use a low pass filter which has cutoff frequency lying somewhere around the blue point. This way all the frequecies between 0 Hz and the blue point will ideally pass through the filter without any attenuation, and the frequencies lying between the blue and green points will be subjected to attenuation. All the frequencies from green point onward will be entirely rejected by the filter including the frequency component represented by the green point itself. Do I have it correct?

We should note that the low pass filter employed to filterize the analong signal will also be able to reject all the frequency components occuring due to sampling pulses because all the components due to sampling pulses lie above the green point. Do I have it correct.

Q2: The answer to the question was already present in the text I was using. The answer is the following paragraph.

"Another way to view aliasing is by considering that the sampling pulses produce a spectrum of harmonic frequencies above and below the sample frequency, as shown in Figure 13-5. If the analog signal contains frequencies above the Nyquist frequency, these frequencies overlap into the spectrum of the sample waveform as shown and interference occurs. The lower frequency components of the sampling waveform become mixed in with the frequency spectra of the analog waveform, resulting in an aliasing error."

Q3: This is my new question. Please help me with it.

A low-pass filter is a filter that passes low-frequency signals and attenuates (reduces the amplitude of) signals with frequencies higher than the cutoff frequency. The actual amount of attenuation for each frequency varies depending on specific filter design. In simple words, the output voltage drops for frequencies higher than the cutoff frequency of the filter.

But what does really happen inside a low-pass filter? To make easier to visualize, at least for me, we will use electron current instead of conventional current.

For a 0 Hz signal, i.e. DC signal, electrons are moving at a constant speed. I understand that the actual drift velocity of electrons is very low but let's not get into this issue. In case of a DC signal, after some time electrons get accumulated on negative plate of the capacitor and no more electrons would be able to flow inside the plate because accumulated electrons would be push against the battery's potential with the same force.

For an AC signal, we can say that electrons oscillate around their mean position. At low frequencies, amplitude of oscillations is larger but there are less oscillations per second. At higher frequencies, amplitude of oscillations get decreases but now there are greater number of oscillations per second.

Why does the voltage across capacitor get dropped as frequency is increased?

This is my own attempt at the answer. As the frequency is increased, the electrons don't get enough time to accumulate inside the negative plate to maximum capacity (the present negative plate was positive plate in the previous ac cycle). Likewise, on the positive plate the electrons don't get enough time to get depleted to maximum capacity. Let me put it differently. Say when the frequency was 10 Hz, the number of electrons which could be accumulated on negative plate was 100 and in similar manner the number of electrons which could be depleted from positive plate is also 100. When the frequency is increased to 500 Hz, the number becomes, say, 10. Now the 100 accumulated electrons on negative plate compared to the 10 have greater potential to do work while moving toward the positive plate. I hope you get the idea what I'm trying to say. Do I make any sense to you?

Thank you for the help.

Regards
PG
 

Attachments

  • pro_123.jpg
    pro_123.jpg
    619.3 KB · Views: 924
  • pro_sampling1.jpg
    pro_sampling1.jpg
    573 KB · Views: 1,118
  • rc_filter1.jpg
    rc_filter1.jpg
    23.8 KB · Views: 761
Last edited:
Hi

But what does really happen inside a low-pass filter? To make easier to visualize, at least for me, we will use electron current instead of conventional current.

For a 0 Hz signal, i.e. DC signal, electrons are moving at a constant speed. I understand that the actual drift velocity of electrons is very low but let's not get into this issue. In case of a DC signal, after some time electrons get accumulated on negative plate of the capacitor and no more electrons would be able to flow inside the plate because accumulated electrons would be push against the battery's potential with the same force.

Thank you for the help.

Regards
PG

It's much easier for me to visualize flow this way, field potentials moving charge and the effects of charge movements as currents (magnetic field) and the separation of charge as voltage (electric field) potentials. You can visualize charge as a type of electromagnetic singularity with lines of force emanating from it to other charges. In a conductor these charges are free to move and will try to arrange themselves to neutralize any net charge along the conductor. Just saying electrons are flowing explains very little and is confusing.

DC signal:
The charged particles in the wire (free electrons) move (magnetic field from 'conduction current') when first connected to the capacitor to neutralize the difference of potential on the wire from the two terminals of the battery generated from it's electrochemically based charge separation process. As the capacitors charge separation increases (the rate of change between plates is not infinitely fast or infinitely large and the changing electric field results in a simultaneously changing magnetic field 'displacement current') between the plates the Potential difference (electric field) increases at the capacitor reducing the difference of potential on the wire until the battery and capacitor are at the same potential and the wire is neutral IRT the battery terminal. The wire (assuming a low impedance) is just a 'carrier' of charge via the slowly moving (low drift speed) huge number of free electrons in it.

For the AC signal think of the actions of charge, fields with the change of time across the components and what happens as they change vary in time and Electrical polarity across each component .
 
Last edited:
Q1: It seems you have this basically correct. However you will never completely attenuate any frequencies as you seemed to imply.

Q2: What spectrum would you expect from sampling? You can do the calculations, or use transform properties to show what the spectrum should be.

Q3: I like to think of the capacitor in the frequency domain as an impedance. We know the effect of sine waves on any impedance whether R, L or C. At any particular frequency you can think of the filter as a voltage divider. At high frequency 1/wC is very low and you are basically shorting out the voltage source, hence the attenuation is increasing at frequency increases. If you understand a voltage divider with resistors and DC voltage, then you can understand the filter with AC sine waves and impedances.
 
Thank you, Steve.

Q1:
Q1: It seems you have this basically correct. However you will never completely attenuate any frequencies as you seemed to imply.

I don't know why you say so because to me what I say here seems correct. Could you please elaborate a little on where I have it wrong. In order to quote some particular piece of text from the embedded image, you can use my previous post. Thanks.

Q2:
Q2: What spectrum would you expect from sampling? You can do the calculations, or use transform properties to show what the spectrum should be.

In this attachment from my previous post, we can see a series of sampling pulses in FIGURE 13-3. I think a single sampling pulse looks more like a trapezoidal pulse in reality. Fourier transform of trapezoidal pulse is given here and plot of frequency spectrum is shown here. This is the **broken link removed** I have used (problem #5, part (a)). I think the sampling frequency spectrum shown in FIGURE 13-5 and 13-6 ignores the parts in green highlight. Do I have it correct? Please let me know.

Q3:
Q3: I like to think of the capacitor in the frequency domain as an impedance. We know the effect of sine waves on any impedance whether R, L or C. At any particular frequency you can think of the filter as a voltage divider. At high frequency 1/wC is very low and you are basically shorting out the voltage source, hence the attenuation is increasing at frequency increases. If you understand a voltage divider with resistors and DC voltage, then you can understand the filter with AC sine waves and impedances.

That's a good interpretation. Yes, I have an understanding of the effect of sine waves on any impedance whether R, C or L. But couldn't you please help me to extend or correct my crude model or interpretation from previous post of mine? I'm sure different interpretations are possible of a same phenomenon and some might seem less formal and more along layman terms. Thank you.

Regards
PG
 

Attachments

  • trapzoid_pulse1.jpg
    trapzoid_pulse1.jpg
    39.4 KB · Views: 2,108
  • trapzoid_pulse.jpg
    trapzoid_pulse.jpg
    98.1 KB · Views: 840
  • cap11.jpg
    cap11.jpg
    25.4 KB · Views: 797
  • trapzoid_pulse2.jpg
    trapzoid_pulse2.jpg
    123.9 KB · Views: 772
That's a good interpretation. Yes, I have an understanding of the effect of sine waves on any impedance whether R, C or L. But couldn't you please help me to extend or correct my crude model or interpretation from previous post of mine? I'm sure different interpretations are possible of a same phenomenon and some might seem less formal and more along layman terms. Thank you.

Regards
PG

IMO Steves reply is not really an interpretation, it's more like using normal circuit theory to calculate the results. My reply to your visualization question was an attempt to show one way to develop a mental picture of a circuit by using the fields in motion as the physical representations of voltage and current values. Some people use numbers, arrows or dots to visually animate their mental circuit pictures but the patterns from that picture are still based on normal circuit calculations not the movement of electrons.
 
Q1:


I don't know why you say so because to me what I say here seems correct. Could you please elaborate a little on where I have it wrong. In order to quote some particular piece of text from the embedded image, you can use my previous post. Thanks.
All I mean is that a filter never completely attenuates something to exactly zero. For all practical purposes what you said is correct, but I just want to make sure you are aware that some small amount of those high frequencies still get through.

Q2:


In this attachment from my previous post, we can see a series of sampling pulses in FIGURE 13-3. I think a single sampling pulse looks more like a trapezoidal pulse in reality. Fourier transform of trapezoidal pulse is given here and plot of frequency spectrum is shown here. This is the **broken link removed** I have used (problem #5, part (a)). I think the sampling frequency spectrum shown in FIGURE 13-5 and 13-6 ignores the parts in green highlight. Do I have it correct? Please let me know.
I'll need to take some time to check this. I've been a little busy today. I'm wrapping a lot of things up at work so I can leave for vacation tomorrow.

Q3:


That's a good interpretation. Yes, I have an understanding of the effect of sine waves on any impedance whether R, C or L. But couldn't you please help me to extend or correct my crude model or interpretation from previous post of mine? I'm sure different interpretations are possible of a same phenomenon and some might seem less formal and more along layman terms. Thank you.

I'll take another look at what you said and see if I can say something better. Sometimes I like to make an analogy with a mechanical system, but being an electrical engineer, more than a mechanical engineer, I often take mechanical systems and equate them to equivalent circuit models.
 
For a 0 Hz signal, i.e. DC signal, electrons are moving at a constant speed. I understand that the actual drift velocity of electrons is very low but let's not get into this issue.
If by "speed" you mean "rate" then this is ok. You are correct to not worry about the drift velocity. What really matters is the rate of electron (or Coulomb, or charge) flow. So, what you are saying is "at a steady state constant current".

In case of a DC signal, after some time electrons get accumulated on negative plate of the capacitor and no more electrons would be able to flow inside the plate because accumulated electrons would be push against the battery's potential with the same force.
Yes, so what you are saying is the steady state current is zero. Zero current will result in zero voltage drop on the resistor. Hence, the output voltage will equal the input voltage.

Then, as the frequency goes up from zero. More current flows. Initially the voltage drop on the resistor is negligible, but at some point it becomes significant, and the cap voltage amplitude will decrease.

This is all a description similar to the impedance concept. Capacitors have high impedance at low frequency.


For an AC signal, we can say that electrons oscillate around their mean position. At low frequencies, amplitude of oscillations is larger but there are less oscillations per second. At higher frequencies, amplitude of oscillations get decreases but now there are greater number of oscillations per second.
This is confusing. What amplitude are you referring to? Current? Voltage? Charge? We know the current is low at low frequency even though the time for the time to flow in a half period is greater. So what is the net effect on the total charge transfer in a quarter of the period. If you can make sense of this, that's great, but it seems confusing to me to use that for visualization.

Why does the voltage across capacitor get dropped as frequency is increased?

This is my own attempt at the answer. As the frequency is increased, the electrons don't get enough time to accumulate inside the negative plate to maximum capacity (the present negative plate was positive plate in the previous ac cycle). Likewise, on the positive plate the electrons don't get enough time to get depleted to maximum capacity. Let me put it differently. Say when the frequency was 10 Hz, the number of electrons which could be accumulated on negative plate was 100 and in similar manner the number of electrons which could be depleted from positive plate is also 100. When the frequency is increased to 500 Hz, the number becomes, say, 10. Now the 100 accumulated electrons on negative plate compared to the 10 have greater potential to do work while moving toward the positive plate. I hope you get the idea what I'm trying to say. Do I make any sense to you?
Again, this is confusing. What is "maximum capacity" referring to? It seems that both the time and the current determine how fast much you can change the voltage in a quarter cycle. There would also seem to be a different intuitive explanation in the low frequency region, the cutoff region and the high frequency region. What you described might apply better to one of those regions.

Overall, I get the gist of what you are saying, but I don't have a clear understanding of the details of your mental picture.

But, I don't think there is one right way to get an intuitive feel, so whatever works for you should be fine.
 
PG,

On your Q2, I'm not sure I'm following all of what you are saying. It is interesting that you are trying to use a trapazoidal sampling pulse, but for conceptual purposes, why not just use an impulse function for sampling. You will find this worked out in any of your DSP books. I'm trying to get ready for my vacation and wont have time to look at this till I'm settled in my hotel tomorrow night. In the mean time keep in mind that sampling is the multiplication of a series of pulses (impulses, square pulses, trapazoids etc.) with the signal. Multiplication in the time domain becomes convolution in the frequency domain. So your signal Fourier transform needs to be convolved with the Fourier transform of an infinite train of impulses. The transform of a train of impulses is a train of impulses in the frequency domain. So your signal spectrum gets shifted to all harmonics of the sample frequency. This is why that signal better be band limited, because otherwise these shifted spectra will overlap.
 
Thank you, Steve.

I will return to Q3 later but first I need to clear few things about Q2.

On your Q2, I'm not sure I'm following all of what you are saying. It is interesting that you are trying to use a trapazoidal sampling pulse, but for conceptual purposes, why not just use an impulse function for sampling. You will find this worked out in any of your DSP books.

I had thought of using impulse function but then it wasn't making sense to me in the given context. I understand that Fourier transform of impulse train is also an impulse train in frequency domain. In this attachment just above FIGURE 13-5, it says, "the sampling pulses produce a spectrum of harmonic frequencies above and below the sample frequency, as shown in Figure 13-5. If the analog signal contains frequencies above the Nyquist frequency, these frequencies overlap into the spectrum of the sample waveform as shown and interference occurs. The lower frequency components of the sampling waveform become mixed in with the frequency spectra of the analog waveform, resulting in an aliasing error". (Please note that the text from that attachment provides two views of aliasing; for the other one, please see FIGURE 13-4.) This really makes sense to me but I can't see how an impulse train can produce a frequency spectrum which looks similar to the one shown in FIGURE 13-5 or 13-6 by the curve in pink. An impulse train can't produce such a spectrum.

Further, please note that at any given time, we just using only a single rectangular pulse, trapezoidal pulse, or an impulse to take a sample so we should really be concerned about the frequency spectrum produced by these single pulses or a single impulse rather trains of these signals.

I have checked some books but no one explains Nyquist theorem the way it should be explained.

Thank you for the help and I hope you would enjoy your vacation to the fullest.

Best wishes
PG
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top