AVR regulator.. Large Output Ripple.

Go To Last Post
28 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,

im using a tiny45 to regulate the output of a solar panel with the ADC and PWM. currently, i have the ADC reading the solar panel output if the voltage drops below 14 volts, the PWM on the connected buck converter will decrease, if voltage goes above 14 volts, the duty cycle will increase.

The regulation routine is shown here

ISR(TIM0_OVF_vect)
{
	getADC(0b00100010);

	{
		if(ADCH > refV && PWM <= (OCR0A-10))
		{
			PWM++;
		}

		if(ADCH < refV && PWM > 0)
		{
			PWM--;
		}
	}
}

Basically for every period in the PWM, it will take an ADC reading and adjust the duty cycle accordingly.

However, Problem is im getting a ripple of around 1 volt at around 110Hz and i dont know why.

Im currently using the Vcc as the reference, and i checked it, its a rock solid clean 5v. ive also tried using the internal 2.56v reference and i get the same problem.

any help will be much appreciated.

thanks

Attachment(s): 

- Tony B. Sydney, Australia.
tbaz2679@mail.usyd.edu.au

Status: Supporting the GNU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you tried playing around with the value of the output filter capacitor?

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yep i have, i went from 330uF to 5000uF and i had no change at all. its a low frequency ripple, it seems like the oscillation is occurring due to a PWM oscillation.

- Tony B. Sydney, Australia.
tbaz2679@mail.usyd.edu.au

Status: Supporting the GNU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would guess a loop stability problem. Time lag between measurement and change of the control element and when the control element actually has an effect on the system can cause some strange effects. Do not know what to suggest other than possibly using a PID control algorithm.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can a tiny45 even handle a PID control algorithm?

- Tony B. Sydney, Australia.
tbaz2679@mail.usyd.edu.au

Status: Supporting the GNU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A PI control algorithm would probably be sufficient.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What the OP has now is only an I algorithm.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

how can i implement the PI algorithm?

the tiny45 doesnt have a HW multiplier.. Would it be fast enough at 8Mhz?

- Tony B. Sydney, Australia.
tbaz2679@mail.usyd.edu.au

Status: Supporting the GNU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don't need multiplication to do the gains. The trick is, as long as you aren't after the utmost in loop performance, you can get away with powers of 2. So the code looks something like

 error = setpoint-readadc();
 integrator+=error;
 ctl = (error<<PGSHIFT) + integrator;
 if (ctl<0) { integrator -=ctl; ctl=0; }
 if (ctl>=MAX) { integrator-=ctl; integrator+=MAX; ctl=MAX;}
 pwm = ctl >> IPGSHIFT   //MAX=pwm_max << IPGSHIFT

Which is actually quite small. Google "PID without a PhD" for hints on how to tune the regulator.

I'm doing it in a Tiny13.

/Kasper

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im gonna try implement your code.
Just a quick question..

What are the PGSHIFT and IPGSHIFT values? can i just use '2' for both?

- Tony B. Sydney, Australia.
tbaz2679@mail.usyd.edu.au

Status: Supporting the GNU

Last Edited: Sun. Oct 26, 2008 - 11:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, Does error need to be a signed integer? im using 10bit ADC, so should i make error a signed 16bit integer?

My PWM is only 8bit btw.

- Tony B. Sydney, Australia.
tbaz2679@mail.usyd.edu.au

Status: Supporting the GNU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

8 bits resolution is not much... chances are that there is no duty cycle that causes the output voltage to be exactly want you want, so it will oscillate continously; unless you add some deadband.

I think that's your real problem. The regulator is not always able to stably achieve the setpoint because of lack of resolution. That might be no problem if the precision of the output voltage does not need to be that tight.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could set a port pin high when the PWM increments and low when it decrements, and scope that to confirm it is correlated with your ripple. 110 Hz sounds like mains interference.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

110 Hz sounds like mains interference.

Sounds like he's in the middle of the ocean - between 50Hz and 60Hz. :lol: :roll:

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok this is really weird. I was testing the original code again today, and i had moment where it regulated perfectly for a few seconds, then a ripple at around 300Hz, then a ripple at 70Hz, then perfect regulation again.

i have a feeling im getting something interfering with my ADC, but it cant be the 5v rail because Ive checked that.

- Tony B. Sydney, Australia.
tbaz2679@mail.usyd.edu.au

Status: Supporting the GNU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is your settings for the counter? I wouold like to know the PWM frequency/period.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ub3r wrote:
Ok this is really weird. I was testing the original code again today, and i had moment where it regulated perfectly for a few seconds, then a ripple at around 300Hz, then a ripple at 70Hz, then perfect regulation again.

i have a feeling im getting something interfering with my ADC, but it cant be the 5v rail because Ive checked that.

With a PV supply you also have to pay attention to what the Sun is doing!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dak664 wrote:
Ub3r wrote:
Ok this is really weird. I was testing the original code again today, and i had moment where it regulated perfectly for a few seconds, then a ripple at around 300Hz, then a ripple at 70Hz, then perfect regulation again.

i have a feeling im getting something interfering with my ADC, but it cant be the 5v rail because Ive checked that.

With a PV supply you also have to pay attention to what the Sun is doing!

The sun was constant all day during testing.

Could it be internal CPU interference effecting the ADC?

- Tony B. Sydney, Australia.
tbaz2679@mail.usyd.edu.au

Status: Supporting the GNU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How often are you updating the PWM ?

I could be just instability in the control algoritm.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i was updating the PWM every PWM cycle.

Now, im updating the PWM every 200 PWM cycles, and im getting the same ripple.

BTW the PWM frequency is 31.25KHz

- Tony B. Sydney, Australia.
tbaz2679@mail.usyd.edu.au

Status: Supporting the GNU

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sun may seem "constant" during day but it is NOT. Even if only the angle changes due to earth rotation, it changes. Light intensity has to change by a rather large percentage for you to be aware that it has changed.

Your observation of unexplained changes in ripple suggests that at some intensities, the output is very close to optimum for an 8-bit system. Change it JUST a little, then it falls between the "cracks" (in the 8 bit values) and it begins to hunt. Because of the low PWM resolution, it can never find that "just right" level so it must constantly search. Then, when sun changes a little, it is closer to optimum, again, and no hunting.

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd love to see a scope trace of the ripple overlaid on PWM increment/decrement. I am using Tiny85s for the same purpose, on a 75 watt panel. But I don't have a functioning oscilloscope :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The problem is in the PWM filtering. The filter adds a delay that causes instability. :(

BTW. have you left adjusted the ADC result? You need to do that to get 8 bit resolution by reading ADCH. If you don't do that, the result is by default right adjusted, so reading ADCH will only give you 2 bit resolution.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The sun was constant all day during testing.

I'd bet that this was not so. The solar angle changes by the minute. Your eyes may not perceive a change, but it sure changes. You need to have a rather large change before your eyes tell you that a change has happened. Eyes logarithmic!

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
i was updating the PWM every PWM cycle.

Now, im updating the PWM every 200 PWM cycles, and im getting the same ripple.

I can attest that the ATTiny25/45/85 family can do PID. I am using ATTiny85's and with one channel of full PID, the code is just under 2K. Ram usage is something like 75 bytes.

I sample 2 or 3 channels (but only handle one of them right now) on the ADC. I run the ADC clock in the recommended range, and at every ADC complete interrupt, I add the reading to an accumulator for that channel, then change channels and start a new conversion. There is a surprisingly large 15% overhead in the interrupt handling (i.e. I am achieving only 85% or the theoretical maximum ADC conversion rate).

I average the channels for about 1/20th of a second (about 400 samples), then process the PID.

You might find that your PWM is more immune to noise by averaging. I could not tell if you are averaging 200 ADC readings, or only acting on the 200th.

There is no great necessity to lock the ADC conversion rate to the PWM rate. Actually, you CAN't get 1 ADC conversion per PWM cycle unless you are losing resolution. 31.25KHz conversions requires an ADC clock of ~400KHz. So most likely you can only get one ADC conversion for every 4 PWM cycles. I would recommend averaging over several cycles of the observed ripple unless this creates too much ripple itself.

A decent PID algorithm should have negligible induced ripple.

Which timer/counter are you using. One of them is buffered for automatic glitch-free PWM

-Tony

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

emuler wrote:
BTW. have you left adjusted the ADC result? You need to do that to get 8 bit resolution by reading ADCH. If you don't do that, the result is by default right adjusted, so reading ADCH will only give you 2 bit resolution.

If a PID algorithm is used, then there is no good reason to limit yourself to 8 bits. You might as well use all 10 bits. For the I term, you probably need 32 bits no matter what. For the P & D terms you will need 16 bits (if you limited yourself to 8 bits on the ADC, you could probably get away with 8 bits).

Depending on how often you want to update the pulse width, more bits resolution may be a problem. I do the updates at 20Hz, and for one channel it is not a problem. However, I have not actually timed the performance of the PID algorithm.

-Tony

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oscillation is definitely a symptom of control issues. When you start getting into control systems you have to take into account ADC noise (which limits your useful measurement, fewer bits of measurement = oscillation due to less precision), the number of bits of your PWM (which will limit how much 'control effort' you can expend, ie maximum change in PWM value), and a whole lot of other stuff.

What you have now isn't really a control system since it doesn't calculate error. You might be able to get by with proportional control but it depends on how much oscillation you're willing to allow. I would calculating an actual error from the ADC data instead of just >14V or <14V, then use proportional control. At first it can just be a gain of 1 - add the error to the PWM signal and see how that works. It might work great, but probably you'll have to mess with error gains to get better.
Another issue - it is entirely possible to overcompensate. I wouldn't update the PWM value at the PWM frequency - high frequency noise from other sources will be measured by the ADC and transferred to the PWM output. 100Hz would probably be fine, even 1KHz is probably OK, but don't go above that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If we speculate that (for the moment) the simple control algorithm is OK, then consider that when the charging circuitry is turned on/off it affects the reading somehow: Vcc, Aref, signal, Gnd.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.