Averaging voltage reading from rectified DC

So, I built this welding controller board, with microcontroller and whatnot. Spent last night debugging it on the bench and pretty much debugged the BASIC source code for stick and TIG welding. (when to close which relays, how to handle error conditions, etc).

There is one thing though, with which I am not satisfied, and it is voltage feedback.

"On the bench", my source of voltage is a rectifier based DC power supply that supplies a rectified single phase sinewave.

I take an exponential average of readings.

Vaverage = k*Vaverage + (1-k)*Vinstant

My issue is this. To get stable reading, I have to have k close to 1, like 0.98. Otherwise Vaverage bounces all over. And yet, with k like this, Vaverage is very sluggish to react to actual changes in voltage. And I need it to react fast, since at some moments I need to turn on high frequency arc stabilizer to keep the arc going, if arc voltage goes too high. I need to do that quickly.

I basically want to have a response time of 0.1 second or so, and yet I want relatively stable voltage readings.

In the actual welder, DC will be rectified 3 phase voltage, that is,

360 Hz wave (note that one phase could be lower than others due to using a phase converter). That should hopefully improve things compared to rectified single phase DC.

My own idea to try (very easy too) is to use a filter circuit. I figure that with a RC filter with 0.47 uF capacitor, and 200k resistor, I should get some decent average. Am I on the right track, or am I missing some good solutions?

i
Reply to
Ignoramus17238
Loading thread data ...

How about tracking the peak voltage rather than the average voltage? This could be done several ways... Take a burst of many measurements over a short time (say 2 cycles) and keep the highest one, for instance.

Reply to
mc

That's a very interesting idea, something I thought about also. I am afraid that it may become troublesome after interference is concerned, from high frequency arc stabilizer and IGBT inverter. Not that I know much.

i
Reply to
Ignoramus17238

Maybe you could filter the incoming signal with a half-wave rectifier so that you charge the capacitor much faster than you discharge it.

Reply to
mc

This was discussed previously in reference to current readings. I'm not sure what you are doing with the formula above, but the easiest way to obtain an average is to totalize 100 mSec worth of samples and then divide by the number of samples (if you need the result in the same data type). For line frequency readings, it is important to have the number of samples correspond to an integral number of cycles.

To do this, the A/D samples should be taken at precise intervals, and preferably an integral multiple of the ripple frequency. This will cancel out irregularities and result in a more stable reading. A good way to do this is by setting up a periodic interrupt at something like 1200/second, and use an ISR to take a sample each time. Actually, it is best to read the previous conversion result first, then take a new sample, and finally perform the totalizing routine. This ensures a precisely timed sample. I don't know how well this will work in BASIC. I use assembly for all ISR functions.

Any more details would require providing actual code. I could give you parts of what I use, in Z80 or Microchip PIC code, but the actual implementation depends on your processor, and involves setting up internal clocks, interupts, and ISRs.

This will greatly reduce the percent of ripple, and will allow a shorter sampling period for faster response, although it should be at least one full cycle to compensate for imbalances. Thus 16.7 mSec or 20 mSec for 60 or 50 Hz. 100 mSec will work for both frequencies.

A 100 mSec TC filter will take 500 mSec to settle within 1%. It is always good to have some analog filtering, but I would suggest about 10k with the

0.47 uF. You also need to consider the input impedance of the A/D, and whether or not it is a sampling type.

Paul

Reply to
Paul E. Schoen

This (using interrupt to collect measurements) is a great idea!

I think that I get the idea. I will see if I can get such timed interrupts. My processor does support some interrupts (like keypad interrupts), but I am not yet sure about time based interrupts.

Makes sense.

My A/D impedance is in dozens of megohms. No problem here. I will try first your 10k/0.47 uF suggestion today, since I already have all the components. (I am a little surprised by the seemingly low 10k number)

Thanks a lot.

If I use the interrupt approach, I will let you know how it goes.

i
Reply to
Ignoramus17238

Paul, I just learned that I do have on timer interrupts. My time interval can go as low as 1 ms.

My CPU can do 360 instructions per ms, so I have to be careful what I do on interrupts.

I have a feeling that the right approach here is to use a proper analog filter.

i
Reply to
Ignoramus17238

This filter is what I recommend with the ISR approach. It should also be OK if you just totalize a large number of samples over 100 mSec, but it is fairly critical to get the 100 mSec accurately.

Paul

Reply to
Paul E. Schoen

Ah-ha, I see now.

Thanks, I will try experimenting tonight. Should be relatively easy.

i
Reply to
Ignoramus17238

[...]

He is using a very simple method of doing a IIR low pass filter in a micro. For his application, it may be easier than the method you suggest because it always has a result reading instead of only providing one every N readings as the simple form of what you suggest would.

There is a middle ground if he needs very good rejection of 60Hz and a little low passing beyond that. If he takes a few samples over the cycle of the mains frequency, he can reject the 60Hz with that and then use the IIR for further smoothing.

--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

Thanks.

I wrote a perl script to simulate effect of a RC filter.

It tries to simulate differential equation of charging the capacitor with voltage through a resistor.

The equation is captured in this assignment operator:

$FilteredVoltage += $dt * ($InstantaneousVoltage-$FilteredVoltage)/$R/$C;

$t is time, in $dt (0.0001s) second increments.

$R, $C are resistance and capacitance (set to 100k ohm and 0.47 uF, since these are parts that I have at home).

Here's the script

====================================================================== #!/usr/bin/perl

my $frequency = 60;

my $dt = 1/10000.00;

my $amplitude = 100;

my $pi = 3.1415;

my $R = 1E5; my $C = 0.47e-6;

my $i = 0;

my $FilteredVoltage = 0;

my $tmax = 100; my $tmax1 = 100.1;

for( my $t = 0; $t < $tmax1; $t += $dt ) { # Sine Wave my $InstantaneousVoltage = $amplitude*sin( 2*$pi*$t*$frequency );

# Rectified $InstantaneousVoltage = -$InstantaneousVoltage if $InstantaneousVoltage < 0;

# Zero voltage after $tmax seconds $InstantaneousVoltage = 0 if $t > $tmax;

# Differential Equation $FilteredVoltage += $dt * ($InstantaneousVoltage-$FilteredVoltage)/$R/$C;

# Print reading every second if( $i % int( 1/$dt ) == 0 ) { print "$t $FilteredVoltage\n"; } $i++; }

print "$t $FilteredVoltage\n";

====================================================================== Here's the output after a while:

81.0000000015654 64.7836365616653 82.0000000015986 64.7752435560597 83.0000000016318 64.7664873669859 84.000000001665 64.757918471578 85.0000000016982 64.7484028037203 86.0000000017314 64.7374004026052 87.0000000017646 64.7278129479949 88.0000000017978 64.7181011836722 89.000000001831 64.7066219189671 90.0000000018642 64.6954853083098 91.0000000018973 64.6842197145063 92.0000000019305 64.6717424584277 93.0000000019637 64.6584412507117 94.0000000019969 64.6456822926563 95.0000000020301 64.6323724216462 96.0000000020633 64.6179690540923 97.0000000020965 64.6047593827934 98.0000000021297 64.5911040743259 99.0000000021629 64.5759746895269 100.000000002196 64.3699842788548 7.66643040668214

As you can see, it gives me a basically stable reading.

When I abruptly set voltage to 0 at time t = 100 seconds, and see what happens at time t = 100.1 second. (simulating effect of removal of DC voltage)

The measured voltage would decline from 100 volts, to 7 volts. After

0.1 more seconds, it would decline to 0.87 volts.

So.

If my model is right (a big question), then a simple RC filter is all I need, period, since it means zero effort (and wasted CPU cycles) in software.

i
Reply to
Ignoramus17238

You should have an analog filter on the input to reduce or eliminate frequency components above half your sampling rate. You can find lots of information about anti-aliasing filters for audio and RF applications. It's important even for this type of measurement because suppose (for example) you sample at 60Hz and your input is a full-wave rectified wall current. Your 60Hz samples could line up on the peaks or the troughs and you would get no information. Even when your sampling frequency doesn't have such an obvious problem (say, at 100Hz) it still "beats" against the input frequency and produces aliases that you can't differentiate from signal.

Try something like a 4k7 into 1uF before the ADC. Beware of increasing the resistance too much -- the ADC probably has a maximum imput impedence spec.

Just to reiterate: You can't fix aliasing problems in software after sampling. However, if there's more noise on top of what you eliminate with the simple external filter, a software filter is cheaper and more precise than more analog filtering. You've got a simple IIR filter there. A free software package like GNU Octave (with octave-forge for the signal processing library) can help you design more sophisticated software filters.

That is in the right ballpark for your overall frequency response, if you want to do it purely analog, but you may need a buffer after that to keep your ADC happy (due to the 200k input resistor).

--
Ben Jackson

http://www.ben.com/
Reply to
Ben Jackson

First, you say, "quickly", and then, you say, "0.1 second"? With a micro, that's like dog years. I did a 24V, 40A battery charger once with a CT tranny and two SCRs, fired by a Motorola 68HC11. (and opto SCRs, of course.) It sampled the voltage and current 16 times per half-cycle, and I tried both RMS (I squared each sample, averaged the squares, and looked up the square root) and just a plain average, and there was no discernible difference in the regulation. One thing that really nagged at me was that it oscillated at about 1-2 Hz, about .5V P-P, which the guy I'd designed it for fixed by slapping a capacior across the sense line.

IOW, I didn't try to maintain a running average in real-time - that's just a low-pass filter - I took discrete samples, and used that info to correct the timing on the next half-cycle.

Maybe get out of BASIC, and into a little assembly code? ;-)

Good Luck! Rich

Reply to
Rich Grise

Hi Rich, great project you did. Congrats. Could you check out my another post titled something like. Averaging voltage reading from rectified DC -- differential equation simulation in perl. I talk about my attempt to simulate a RC filter with perl, and a realization that a simple filter like this ought to solve my problem. I will try it first tonight.

Reaction time within 0.1 or 0.05 second ought to be good enough for me. I need that to start high frequency arc stabilizer if arc voltage becomes too high (loss of arc).

Barring that, yes, I could take samples. The lowest delta t that I can go to is 1 msec.

i
Reply to
Ignoramus17238

Hi Rich,

I am pretty sure that I know what to do.

What I will do is the following:

1) Use RC filter with R=50 kOhm and C=0.47 uF to get "fast average".

I will use this fast average to decide when to turn on high frequency. (will turn HF on at 45 volts and turn off at 40 volts, or some such)

That would give me very fast (for my purposes) reaction time, way under

1/10 second.

2) In software, further average this value over some period, for display on the serial LED display purposes only. I do not want voltage reading to blink changing 32-33-34-33-32 etc. Output to LED display is kind of expensive.

i
Reply to
Ignoramus17238

In article , Ignoramus17238 wrote: [...]

Yuck.

AssUMing that "/$R/$C" means divide by both, I think this is right.

.... etc ...

[...]

It sounds like it if you can withstand the lag. If not, you can make a 2 pole filter with 2 more parts and get it a little better.

R 10R ----/\\/\\/-----+-----/\\/\\/\\----- ! ! --- --- ---10C ---C ! ! GND GND

Making the ratio of the parts 10:1 prevents the second stage from degrading the first's performance until you get to about 10 times the cut off.

--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

That's right.

Very nice. Thanks. I will try to do it (second stage) in software. I already physically put in the RC filter into my board, and it seems to be working nicely, to spec, exactly as the model predicted. I will use this fast value for turning arc stabilizer on and off as needed, and will further software filter this reading for displaying display voltage.

I get basically instant response now (instant in terms of my human perception).

i
Reply to
Ignoramus17238

There is a way to get a very fast response value without any extra filtering. The basic idea is to measure values 90 degrees apart and take the square root of the sum of the values. If you try to take a voltage value from a single measurement, you must filter and that slows things down a lot. However if you take the real and imaginary components and find the magnitude from that, this can be done with only four measurements over one period of the signal.

The basic idea is that an ac voltage can be represented as a rotating vector with magnitude and angle. What we want is the magnitude. For an AC voltage, the magnitude is constant while the angle is changing. If we look at the signal in magnitude and phase components rather than amplitude versus time, the time dependence drops out.

This sounds hard but is very simple. To do this with a sine wave, you sample at four times the sine wave frequency. These four samples are called A, B, C, D. You split them into two values, A-C and B-D. This gives you two components, the I and Q values. Now sum the squares of the two values you just got. If you have nothing better to do, you can take the square root but that is not required. This value is a measure of the magnitude of the signal. No filtering or phasing of the sampling signal is required.

Since you are using rectified voltage, the two terms you want are A+C and B+D.

With the resolution you probably need, you can use 8 bit multiplies which are not expensive and sums are, of course, easy. If you do your control on the square of the magnitude, then it goes pretty painlessly.

Reply to
""doug"

Well, like I said in another post in this thread which is growing into more of a tree, [ ;-) ] a low-pass filter would be simple, but like I said, I'd hack the SCR supply, if that's feasible.

Good Luck! Rich

Reply to
Rich Grise

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.