A digitally-controlled-power power supply

If it plugs in, post it here.

Moderator: Site Moderator

Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

Hi lampshade,

As sambedded said, it will evenly spread the "on" semi-periods across control interval. This was intended to minimize any surge boiling due to having had the power off and then turning it on. Surge boiling doesn't seem to be a problem, so there was no need to add the complexity of Bresenham's algorithm .

If you were to try to get 1024 levels using a single element, then some sort of distribution scheme would be a good idea.

M
lampshade
Rumrunner
Posts: 541
Joined: Tue Jan 24, 2012 3:19 pm
Location: Southern California

Re: A digitally-controlled-power power supply

Post by lampshade »

Thanks, Martimer. Here is a diagram of applying the Bresenham algorithm to rendering a straight line on a computer screen.
You do not have the required permissions to view the files attached to this post.
In Flanders fields the poppies blow * Between the crosses, row on row, * We are the Dead. Short days ago * We lived, felt dawn, saw sunset glow, * Loved and were loved, and now we lie * In Flanders fields. -- from a WWI poem
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

sambedded, where are you? How do you use Bresenham's algorithm to turn on the correct half-cycles?

M
lampshade
Rumrunner
Posts: 541
Joined: Tue Jan 24, 2012 3:19 pm
Location: Southern California

Re: A digitally-controlled-power power supply

Post by lampshade »

Maritimer wrote:sambedded, where are you? How do you use Bresenham's algorithm to turn on the correct half-cycles?

M
I'm guessing it works this way -- but it is only a guess. If you look at the above chart, you see that the number of pixels in each vertical line is two or three. Let's assume that you want to run your power controller at 51% of max power. You could do this by passing 51 cycles followed by blocking 49 cycles, and so on. But suppose that 49 cycles is too long for the power to be off and thus causes surging. So let's pass 10 or 11 cycles and block 10 or 9 cycles. The OFF time is now shortened to 10 cycles, which is just short enough to minimize surging to an acceptable level.

However, we need to determine when to pass 10 cycles and when to pass 11 cycles. One solution would be to pass 10 cycles four times (each of the 10 ON cycles followed by 10 OFF cycles) and then pass 11 cycles (followed by 9 OFF cycles). This would give 51 ON cycles and 49 OFF cycles, which is 51%.

For this example, I was able to easily come up with a solution off the top of my head. But how do you create a computer algorithm that does what my brain did. I'm guessing that is the Bresenham algorithm, but that's only a guess.
In Flanders fields the poppies blow * Between the crosses, row on row, * We are the Dead. Short days ago * We lived, felt dawn, saw sunset glow, * Loved and were loved, and now we lie * In Flanders fields. -- from a WWI poem
lampshade
Rumrunner
Posts: 541
Joined: Tue Jan 24, 2012 3:19 pm
Location: Southern California

Re: A digitally-controlled-power power supply

Post by lampshade »

I just did a google search on "bresenham algorithm power control" There are articles which confirm that I was on the right track with my above guess for how the Bresenham algorithm is used to control power with a minimum of flicker (surging).

In most of the power controllers on HD, surging is eliminated by using PWM of each cycle. In other words, only a portion of each cycle is passed and the rest of the cycle is blocked. In this scheme, for a particular power setting, each cycle is identical.

The other approach is to pass a certain number of cycles and block other cycles. For those cycles that are passed, the entire cycle, not a portion of the cycle, is passed. The advantage if this approach is that the SSR is turned ON/OFF only when the cycle crosses zero volts, which eliminates electromagnetic interference (noise). The first approach can be noisy. This second approach has been discouraged because it has been observed that it can produce surging, especially for low power settings. However, applying the Bresenham algorithm to the second approach may eliminate surging. The disadvantage is that complicated calculations must be performed whenever the power setting is changed. A microprocessor (like the arduino) must be used.

Some have thought that the surging of the second approach can be eliminated by randomly selecting which pulses are passed or blocked, as long as the average numbers produce the desired power setting percentage. However, the fallacy in using random numbers is that there is a likelihood that sometimes the number of contiguous OFF cycles can be large. Think of tossing 10 heads in a row; the probability of that occurrence, while small, is not zero -- they do occur. And when random numbers do produce a long series of OFF cycles, surges happen, not often, but maybe often enough to knock a column out of equilibrium.
In Flanders fields the poppies blow * Between the crosses, row on row, * We are the Dead. Short days ago * We lived, felt dawn, saw sunset glow, * Loved and were loved, and now we lie * In Flanders fields. -- from a WWI poem
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

Hi lampshade,

For my first power supply I used a random number generator, assuming that by setting a threshold at the desired level, the power would average out to be at the threshold. Here is what happens: http://homedistiller.org/forum/viewtopi ... 2#p7020450 . The random number generator, at least in the library of the Zilog development system I'm using, is not so random over large stretches. One thing I contemplated, but never implemented because the current power supply is working fine, would be to use a random number generator and count the number of half-cycles that have been passed. If the required number have been passed before the maximum cycle count, do not pass any more until the next cycle. If not enough will be passed, pass all of the next half-cycles. Then, to make things easier, test the random number/threshold count for all combinations and find the amount of extra threshold that would have to be added so that the random number generator always produces too many pulses. Then, in operation, count the number of passed half-cycles and stop passing any more until the next round of counting. This could be done programmatically, increasing the amount of added threshold until you find the amount to add.

I remembered back to when I was playing with the program, and the real problem was not surge boiling, but puffing. If I powered all four elements together, and using a cycle count of 256 (one byte), steam would come out in puffs. So I tried two elements together, but shifted 1/2 of the counting cycle, and still got the same effect. That's when I had to go to four elements each shifted by 1/4 of the counting cycle.

The random threshold technique does not cause surging or puffing.

Are you thinking of using a single element? How many power levels do you want?

M
lampshade
Rumrunner
Posts: 541
Joined: Tue Jan 24, 2012 3:19 pm
Location: Southern California

Re: A digitally-controlled-power power supply

Post by lampshade »

Thanks, M.

I would say that your controller uses random numbers as an input to a controlled process.
Last edited by lampshade on Tue Jun 04, 2013 9:53 pm, edited 1 time in total.
In Flanders fields the poppies blow * Between the crosses, row on row, * We are the Dead. Short days ago * We lived, felt dawn, saw sunset glow, * Loved and were loved, and now we lie * In Flanders fields. -- from a WWI poem
User avatar
sambedded
Trainee
Posts: 758
Joined: Tue Jul 10, 2012 11:25 pm
Location: Canada

Re: A digitally-controlled-power power supply

Post by sambedded »

Maritimer wrote:
so there was no need to add the complexity of Bresenham's algorithm .
Why are you talking about complexity? Bresinhem algorithm is extremely simple Your "random" implementation is more complex.

=======================================================

Code: Select all

#define regMax (100)   //How many power levels we want
signed short regError=regMax/2; 
unsigned short regValue;             //Current power level

void  SetNewLevel(unsigned short Level)
{
   regError=regMax/2; 
   regValue = Level;
}

void ZeroCrossingInterrupt()
{
    regError=regError-regValue;     \\<-------------------------
    if (regError<=0)                       \\<-
    {                                             \\<-  This a core of Bresinham algorithm
      regError=regError+regMax;     \\<---------------------------------
      SwitchOn();
    }
    else
      SwitchOff();
}
===================================
Last edited by sambedded on Mon Jun 03, 2013 10:48 pm, edited 2 times in total.
lampshade
Rumrunner
Posts: 541
Joined: Tue Jan 24, 2012 3:19 pm
Location: Southern California

Re: A digitally-controlled-power power supply

Post by lampshade »

sambedded wrote:Why are you talking about complexity? Bresinhem algorithm is extremely simple Your "random" implementation is more complex.
I'm going to keep my mouth shut for awhile before responding. I don't think you are being fair to Maritimer.
In Flanders fields the poppies blow * Between the crosses, row on row, * We are the Dead. Short days ago * We lived, felt dawn, saw sunset glow, * Loved and were loved, and now we lie * In Flanders fields. -- from a WWI poem
lampshade
Rumrunner
Posts: 541
Joined: Tue Jan 24, 2012 3:19 pm
Location: Southern California

Re: A digitally-controlled-power power supply

Post by lampshade »

Sambedded's algorithm, as posted, is quite simple.
Last edited by lampshade on Tue Jun 04, 2013 9:54 pm, edited 2 times in total.
In Flanders fields the poppies blow * Between the crosses, row on row, * We are the Dead. Short days ago * We lived, felt dawn, saw sunset glow, * Loved and were loved, and now we lie * In Flanders fields. -- from a WWI poem
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

Sambedded suggested using Bresenham's algorithm, of which I was totally ignorant, so I checked it out on the net. The implementations I saw there were not at all simple. When I say that my implementation worked OK, I was referring to the simple counting scheme and the four elements stepped 1/4 way around the 256 level cycle in the OP. I came up with the random number idea because, quite frankly, the Bresenham algorithm, as explained on the net, was incomprehensible.

Sambedded, could you explain in words how your implementation works?

M
User avatar
sambedded
Trainee
Posts: 758
Joined: Tue Jul 10, 2012 11:25 pm
Location: Canada

Re: A digitally-controlled-power power supply

Post by sambedded »

Maritimer wrote: Sambedded, could you explain in words how your implementation works?
Hate to type. But after 2 minutes of googling found nice article explaining about Bresenham: http://trolsoft.ru/articles/bresenham-a ... hp?lang=en" onclick="window.open(this.href);return false;" rel="nofollow.
Take a look to the final implementation. But author overcomplicated it a bit. You don't need to count steps since by the end of full cycle

Code: Select all

st->error
will be equal to

Code: Select all

st->size/2
automatically.
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

Hi sambedded,

I also found that site while looking for an explanation, but as something to put in an interrupt, it was way too complex. I explored you code using MATLAB, and it does work very well. Here is what happens with 100 power levels and setting the desired level to 63:

>> bres = zeros(100,3); create a 100 X 3 matrix of zeros. This will be filled with data

>> b = Bres(100,63,bres) Bres is your code rendered as an m function (see below)

b = this is the matrix filled with regError in the second column and switch() in the third
1 -13 1
2 24 0
3 -39 1
4 -2 1
5 35 0
6 -28 1
7 9 0
8 -54 1
9 -17 1
10 20 0
11 -43 1
12 -6 1
13 31 0
14 -32 1
15 5 0
16 -58 1
17 -21 1
18 16 0
19 -47 1
20 -10 1
21 27 0
22 -36 1
23 1 0
24 -62 1
25 -25 1
26 12 0
27 -51 1
28 -14 1
29 23 0
30 -40 1
31 -3 1
32 34 0
33 -29 1
34 8 0
35 -55 1
36 -18 1
37 19 0
38 -44 1
39 -7 1
40 30 0
41 -33 1
42 4 0
43 -59 1
44 -22 1
45 15 0
46 -48 1
47 -11 1
48 26 0
49 -37 1
50 0 1
51 37 0
52 -26 1
53 11 0
54 -52 1
55 -15 1
56 22 0
57 -41 1
58 -4 1
59 33 0
60 -30 1
61 7 0
62 -56 1
63 -19 1
64 18 0
65 -45 1
66 -8 1
67 29 0
68 -34 1
69 3 0
70 -60 1
71 -23 1
72 14 0
73 -49 1
74 -12 1
75 25 0
76 -38 1
77 -1 1
78 36 0
79 -27 1
80 10 0
81 -53 1
82 -16 1
83 21 0
84 -42 1
85 -5 1
86 32 0
87 -31 1
88 6 0
89 -57 1
90 -20 1
91 17 0
92 -46 1
93 -9 1
94 28 0
95 -35 1
96 2 0
97 -61 1
98 -24 1
99 13 0
100 -50 1

>> sum(b) This sums each column. The sums of columns 1 and 2 are incidental, but column 3 is the number of half-cycles of AC passed, and it is bang on 63
5050 -1250 63

>> stairs(b(:,1),b(:,2)) this plots regError, the lighter graph

>> stairs(b(:,1),10*b(:,3)) this is the switch() signal. It is ON whenver the regError is negative
bresenham stairs and switch 60%.jpg
Here is the MATLAB file Bres(): (Unfortunately the forum software does not allow leading spaces. I changed the names of variables to make them more understandable)

Mod Edit: Enclosed code withing code tags for proper formatting...

Code: Select all

function y = Bres(NumberOfLevels,InputLevel,matrix)

FollowingLevel=NumberOfLevels/2;
n=0;

for n=1:100
	 FollowingLevel=FollowingLevel-InputLevel; 
	 matrix(n,1)=n;
	 matrix(n,2) = FollowingLevel;
    if FollowingLevel<=0    
      FollowingLevel=FollowingLevel+NumberOfLevels;
      matrix(n,3)=1; 
    else
      matrix(n,3)=0;
	 end	
end 
y=matrix;
Next question, why does it work?

M
You do not have the required permissions to view the files attached to this post.
User avatar
sambedded
Trainee
Posts: 758
Joined: Tue Jul 10, 2012 11:25 pm
Location: Canada

Re: A digitally-controlled-power power supply

Post by sambedded »

M, what exactly is unclear - how line drawing applicable to power control or how Bresinham algorithm works?
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

s,

I've been reading more about the line-drawing algorithm, and I'm starting to get the hang of it. But that is about selecting pixels close to the desired line. Understanding your little code that turns of half-cycles on and off so properly is still a mystery. There is some concept I'm not getting.

M
lampshade
Rumrunner
Posts: 541
Joined: Tue Jan 24, 2012 3:19 pm
Location: Southern California

Re: A digitally-controlled-power power supply

Post by lampshade »

I think the algorithm works as follows:

The algorithm was developed to determine which pixels to illuminate in order to render a straight line on a computer screen. Because the pixels are large relative to the line, it is impossible to draw a perfect line, but it is possible to trace up and down around the desired line. The important thing is that the pixels remain near the line. This same attribute is the reason that the Bresenham algorithm can be used to pass or block half-cycles -- the average pass/block ratio is constant (and this ratio determines the amount of power that the controller transmits to the load, relative to the maximum power).

Now how does the algorithm do this? The beauty of the algorithm is that it calculates whether the next half-cycle should be passed, and it does this simple calculation during each half-cycle. The calculation is the same as it would be to draw a line -- at each pixel, the algorithm decides whether the next pixel will be above or immediately to the right of the current pixel. So, when a the next pixel is above or immediately to the right of the current pixel, that is the same as whether the next half-cycle is passed or blocked. The slope of the line varies between 0 degrees and 45 degrees, which is the same as the power being completely off or completely on (max power), or something in between.

Edit: Per sambedded's correction, the line slope was changed from 90 degrees max to 45 degrees max.
Last edited by lampshade on Wed Jun 05, 2013 12:06 pm, edited 1 time in total.
In Flanders fields the poppies blow * Between the crosses, row on row, * We are the Dead. Short days ago * We lived, felt dawn, saw sunset glow, * Loved and were loved, and now we lie * In Flanders fields. -- from a WWI poem
User avatar
sambedded
Trainee
Posts: 758
Joined: Tue Jul 10, 2012 11:25 pm
Location: Canada

Re: A digitally-controlled-power power supply

Post by sambedded »

Yes, L yor are completely right. It works exactly as your described. The only correction - slop can vary from 0 degree (comleyely Off) to 45 degree completely On).
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

s,

Thanks for the code. I'm going to convert my power supply to it. Those mere 1024 levels that I used to use can now be expanded as much as desired (within the limits of a 16-bit signed integer). I played around with using real numbers in the algorithm, so it is possible to get any accuracy desired. Of course, the whole point is to use integers, so my 4000W supply could be taken to 32000 divisions, i.e., 1/8 Watt! The maximum value of regError is 32000 when the input level is 16000. Ridiculous, but possible at the touch of the keyboard. The complete cycle, though, would take 1/120 sec X 32000 = 267 seconds = 4.444 minutes.

M
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

Here is another way of looking at the algorithm. First, here is a plot of the regError and switch() using an input level of 45 out of 100. The cycle repeats in 21 time units, so only one cycle is shown.
45 units X 24 time.jpg
There are two conditions in the algorithm: 1, the running sum signal, called regError, when tested, is negative, in which case a half-pulse IS passed; and 2, the running sum signal, called regError, when tested, is positive, in which case a half-pulse is NOT passed.

RegError is generated by starting with a 50% value, an arbitrary value. Whatever happens next, the algorithm is going to pull regError towards zero, either by subtracting 45 or adding 55 (100-45).

In condition 1, the signal is negative. This is because, just before testing, it was positive, so 45 was subtracted from the running total, regError. This also means that a half-cycle must be passed.

That half-cycle has a value of 45. Why? Since the running total was depleted of 45 units, something must have happened, and in reality, the switch pulse did this by turning on a half-cycle. Instead of thinking of it as power being added to the boiler, think of it as power that has been taken from the mains.

Then a half-pulse with a value of 55 is added to the running total, regError. At this point regError becomes positive, so on the next test, the switch will do nothing--it will not try to deplete the mains.

That means that a half-cycle that is not passed has a worth of 55. The running total, regError, has to stay as close to zero as it can, and it has to do something every time a time unit (interrupt) asks it to; so it does this by subtracting 45 units if its running value is positive and adding 55 units if its value is negative.

Averaging over time, 45% of the switches will be powered.

In the diagram, notice that at the 12th time position, subtracting 45 wasn't enough to bring regError below zero. Since it is positive when tested at position 12, a half-cycle is not passed, but since it is positive for the next time position, 45 is subtracted again. It's this mechanism that assigns a value of 45 to a passed half-cycle and 55 to a missed half-cycle.

M
You do not have the required permissions to view the files attached to this post.
lampshade
Rumrunner
Posts: 541
Joined: Tue Jan 24, 2012 3:19 pm
Location: Southern California

Re: A digitally-controlled-power power supply

Post by lampshade »

Here are some plots of the Bresenham algorithm, for 1%, 11%, 37%, and 50% power settings. The plots repeat every 100 half-cycles (0.83 seconds, assuming there are 120 half-cycles per second). While the plot is at "1", the half-cycles are passed; and when the plot is at "0", the half-cycles are blocked. For example, for 1% power or 37% power, one or 37 out of every 100 half-cycles are passed. The software used was MatLab. ** Isn't this beautiful!
You do not have the required permissions to view the files attached to this post.
In Flanders fields the poppies blow * Between the crosses, row on row, * We are the Dead. Short days ago * We lived, felt dawn, saw sunset glow, * Loved and were loved, and now we lie * In Flanders fields. -- from a WWI poem
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

Hi lampshade,

Another MatLab user, how nice! Here are the 1% and 11% plots with a little more detail:
bres 1%.jpg
bres 11%.jpg
The code that sambedded gave us is the kind of thing that you write when you're in the thick of programming, and then you come back and say to yourself, "How the hell does that work?" The pictures tell the story: while regError is positive, keep subtracting the input level until it goes to zero or negative; when it is negative or zero, keep adding the maximum number of levels (100 in the examples) minus the input level; whenever regError is negative, turn on the half-cycle.

M
You do not have the required permissions to view the files attached to this post.
lampshade
Rumrunner
Posts: 541
Joined: Tue Jan 24, 2012 3:19 pm
Location: Southern California

Re: A digitally-controlled-power power supply

Post by lampshade »

Nice work, M !!!
In Flanders fields the poppies blow * Between the crosses, row on row, * We are the Dead. Short days ago * We lived, felt dawn, saw sunset glow, * Loved and were loved, and now we lie * In Flanders fields. -- from a WWI poem
User avatar
Cardinalbags
Swill Maker
Posts: 409
Joined: Tue Mar 26, 2013 2:35 pm
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Cardinalbags »

Great work fellas....

On another note, I have a buddy that we nicknamed Lampshade.... At first I wondered if you were him, then you starting talking math and computer programming and that was a real indication that you are NOT him!!! :lol: :lol: :lol:
timbit1985

Re: A digitally-controlled-power power supply

Post by timbit1985 »

Nice! I've made pid controllers for water baths and I didn't need to worry about zero sensing because heater elements are purely resistive loads. I found it didnt really matter when I was turning the element on and off, just that I was.
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

Hi timbit,

If you want to directly control power, some form of pulse width modulation will give you exact control. The boiler needs to produce a constant stream of steam, so turning off and on the power generates pulses of vapour. With the four elements in my boiler cycled in rotation, the pulses from each one unite.

If you are going to use a microcontroller, you might as well go for something like Bresenham's algorithm (if you are using a single element), because the exact amount of power gives you exact control. Different parts of the distillation process use different power levels, and if you want to automate, you'll need the micrcontroller to set them. Check out the state diagram at the end of the Poor Man's Flow Switch.

You might not need pid control. The temperatures are determined by the composition of the liquid or vapour, and the reflux column sets up the temperature gradient on its own.

M
Jacksonbrown
Swill Maker
Posts: 315
Joined: Fri Sep 20, 2013 3:00 pm

Re: A digitally-controlled-power power supply

Post by Jacksonbrown »

Hi guys,

Sorry to dig up an old one but could some spell out the benefits of this style power controller in layman’s terms?

I have a PID controller set to manual that I use for my power controller.
The output is PWM that drives one or two 240V SSR’s (depending on how much juice I need).
The shortest cycle time is 0.5s which can cause a bit of dimming in the lights at 100% (2.2kW) (EDIT - SHOULD BE 50%) but nothing unacceptable.

I’m thinking about having a crack at an Arduino or Pi E-ARC and was just going to use PWM again since it’s there but go for a much shorter cycle time.
What are the pros and cons of a fixed cycle PWM versus a more random type algorithm that you guys are using?
Last edited by Jacksonbrown on Sat Jan 03, 2015 7:07 pm, edited 1 time in total.
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

Hi JB,

The power line frequency in Australia is 50 Hz, so if you use zero-crossing SSRs, you have a choice of 100 discreet power levels if you use 1 second as your maximum cycle time. Of course, if you are using triacs that can switch anywhere during a power cycle, you can have an infinite range of power levels, but the control is non-linear. If you have two elements, you can stagger the power levels to give 0.5 seconds with zero-crossing SSRs, which is perfectly acceptable as far as pulsing is concerned.

The nice thing about using zero-crossing SSRs is that you can count the zero-crossings in the microcontroller to implement PWM or you can use Bresenham's algorithm and be done with power pulsing.

If you are using a feedback configuration, which is how a PID controller is intended to be used, you need some way to measure the power so that you can generate an error signal measuring the difference between the set point and the actual power being dissipated. You can measure power in the RC and PC if you know the flow rate of the coolant and the coolant temperature drop, so you could use this to control the power dissipated by the elements.

If you want to simply set the power, say in you microcontroller program, then you need a way to manipulate the SSR's on/off ratio. The simplest way is PWM, with its attendant pulsing problem, or you could use the usual phase control, which is non-linear, or you could use phase control with a formula to figure out the correct place to switch, or you could use Bresenham's algorithm, the code having been presented above, which you could paste into you code.

So, to answer your question: the advantage of using Bresenham's algorithm is that you can have much finer control of power, say to within 0.1% without any pulsing compared to 1% using the technique described in the first paragraph.

M
Jacksonbrown
Swill Maker
Posts: 315
Joined: Fri Sep 20, 2013 3:00 pm

Re: A digitally-controlled-power power supply

Post by Jacksonbrown »

Ok, thanks for the reply.

The shortest PWM cycle time of the controller is 0.5s so that suggests 50 power levels (2% increments) yet my PID in manual mode goes from 0% to 100% in 0.1% increments.
It sounds like this level of adjustment a bit of an illusion unless I increase the cycle time from 0.5s?
Discussing with the in-house oracle we were wondering ‘if the PWM cycle time was the same as the line cycle time and you pulled 50% would you get DC?’ Conclusion was no because the line cycle fluctuates a bit.

If that’s the case then the algorithm might be a good thing for me if it’s easy to implement hardware wise.
Getting the signal from the micro controller to the SSR might be a bit more mucking around but will have to look into it. I may be OK to use one of the normal IO pins if the cycle time is long enough.
Then save one of my PWM pins for a VM valve positioner.
Being able to dial in Watts in 10W or even 100W increments would be enough resolution I would think.

What I’m thinking is limiting the max output of my 2.2kW elements to 2kW and putting in a 10 buck, 9A circuit breaker to protect against a failed SSR (should it fail closed and draw 9.1+A the circuit breaker will trip).
2kW is still heaps of power and it seems like a simple solution to the failed SSR conundrum. What do you think and what was your solution?

Also has anyone found a good solution to cheap and accurate flow measurement? Ada fruit had some good gear but 10% precision is nowhere near good enough for intended usage, (bit of a hijack but it’s a stale thread anyway).
Maritimer
Rumrunner
Posts: 716
Joined: Sun Jul 01, 2012 6:09 am
Location: Nova Scotia, Canada

Re: A digitally-controlled-power power supply

Post by Maritimer »

Hi JB,

That idea of using 9.0/9.1 amps on/off looks a little iffy. Are circuit breakers really that accurate?

I'm taking care of the shorted SSR failure problem by monitoring the voltage across the element with an opto-coupler/gate IC. When there is voltage across the element, the LED turns on, turning on the gate. The microcontroller can check to see if the element got its power as directed. Here is the idea:
waveform for zero-crossing.jpeg
An interrupt is generated a little after every zero crossing. So if the next half-cycle is to turn off, an output signal goes Lo as in the first dotted orange vertical line. When the SSR goes through the zero crossing, it sees that the voltage is Lo, so it turns off that half-cycle. On the turned-off half cycle, where the orange signal is now going Hi, the interrupt checks to see if the power is off. Also, the next half-cycle is programmed. In this case, the next half-cycle is supposed to turn on so the orange signal goes Hi.

So the interrupt 1) sets the next half-cycle on/off state and 2) checks the previous half-cycle's instruction to see if it has been followed.

BTW, if you do use two SSRs and have a 1 second repetition rate for the PWM cycle (instead of using Bresenham), and stagger the two SSRs by 0.5 second, you can get 200 power levels, not 100.

M
You do not have the required permissions to view the files attached to this post.
Post Reply