Author Topic: Arduino based PWM diversion control system  (Read 10485 times)

WillEert

  • Full Member
  • ***
  • Posts: 122
Re: Arduino based PWM diversion control system
« Reply #75 on: April 06, 2016, 08:59:05 AM »
I have managed to get the  Classic10 and Classic11 arduinos exchanging data using serial. For a newbie such as myself this is very pleasing. I tried various ways but this method is working very well for me. It does not block the program so the loop runs quickly. :)

http://forum.arduino.cc/index.php?topic=288234.0

I used, with modifications, the sketch in reply 72 for RX and used Serial.print instead of Serial.write for TX. Yay. Going to try jacking the baud rate up to see if it speeds the loop time up but so far I have not needed it.

So I will be able to force floats when needed without sending charge state data using digital pins. Also this will let me add up the production of the 2 Classics to get one number for data logging. I am thinking this is going to work out.

Cheers

Will
24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system
+ 15 Heliene 330 mono, Classic 150

NariParish

  • Newby
  • *
  • Posts: 1
Re: Arduino based PWM diversion control system
« Reply #76 on: May 12, 2016, 01:47:48 PM »
Hi.... Arduino is, IMHO, just about the best introduction with the bonus that it's straightforward to create some real world useful applications in this case some very nice extensions, both hardware and software, for the Classic.When you extend your RE system to include a second Classic then follow me can be implemented using the Arduino.

High Density Interconnect PCB
« Last Edit: May 25, 2016, 05:41:56 PM by NariParish »

WillEert

  • Full Member
  • ***
  • Posts: 122
Re: Arduino based PWM diversion control system
« Reply #77 on: May 16, 2016, 12:53:31 PM »
We have moved into our new off grid house and now are using our electric stove and electric hot water tank. Previously, in the off grid shop we were living in, we used a propane cook-top for cooking, solar oven and a thermal system in the summer and wood cook stove coil in the winter for hot water production. I know we are going to need more power generating capacity in the winter for the new house.

I had bought everything needed to add 1980 watts to the existing array of 4440 watts capacity. The array would become two arrays of 3210 watts each with their own Midnite Classic. My wife said - Why don't you just buy more panels and maximize your second Classic?  :) So I ordered 9 more 330w Helienes - Yay!!!!!!!

The plan now is that the diversion control will amp limit both arrays simultaneously, cutting them back and increasing them as required in order not to charge the batteries at too fast a rate but allowing all additional power available to be put into instantaneous loads and the HWT and and from the HWT used for building heating with the radiant floor. The electronic thermostat for the HWT is working very well now that I have no heating load in the summer. The ability to RX/TX without blocking between the two Arduinos in the diversion control permits simultaneous amp limit control to take place. More coding to be done but I can see how to make it work.

I am just learning about parallel processing and the Parallax Propeller board. I am not sure if this is a time waste or may come in handy in some fashion for the control. Time will tell.

Will
24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system
+ 15 Heliene 330 mono, Classic 150

Westbranch

  • Hero Member
  • *****
  • Posts: 2516
  • Building System (sort of) 1 weekend at a time
Re: Arduino based PWM diversion control system
« Reply #78 on: May 16, 2016, 01:18:34 PM »
Hi Will, it sounds like you are a few years ahead of us in some ways, we had the basement cement poured over the radiant heat tubes 3 years ago but are still working on gyproc on the main and upper floors..... it's coming....slowly. Also your path af heating, cooking is very similar, wood heat 100% though, but an induction cooker and SWMBO just got a propane cook-top  in preparation of the kitchen cabinets arriving later this summer... 

Do you have any pics or sketches of your plumbing ?
 My plan is to use the diversion method in the summer, once the fridge/electronics  consumption is replenished, for DHW but as you are doing, having more PV for the winter, up to  ~ 4200W, plus  I have some evacuated tube water heaters to include in the system...  I am thinking I will need 3 tanks, one for the tubes, one for the diversion to DHW heating  and a third one for the glycol loops which would be looped to the DHW tank and the Evac. tube tank... Make sense?

The programing is another issue ,  time time, no time....
KID FW1811 560W >C&D 24V 900Ah AGM
CL150 29032 V.2126-NW2097-GP2133 175A E-Panel WBjr, 3Px4s 140W > 24V 900Ah AGM,
2 Cisco WRT54GL i/c DD-WRT Rtr, NetGr DS104Hub Hughes 1100 Sat. Modem
Cotek ST1500 Inv  want a 24V  ROSIE Inverter
OmniCharge3024  Eu1/2/3000iGens
West Chilcotin 1680+W to come

WillEert

  • Full Member
  • ***
  • Posts: 122
Re: Arduino based PWM diversion control system
« Reply #79 on: May 18, 2016, 12:01:06 AM »
Hi Westbranch,

We moved from Cedar BC to the hinterland of Manitoba 6 years ago. Been building ever since. We are enjoying our new house after the shop.

I use a single 120 us gal tank with and upper and lower heat exchangers in it. I bought it from Advance Metalpress in Vancouver. 316L stainless. Roy is a very pleasant person to work with. The logic for the heating system is that at 155F the radiant floor circulating pump turns on, circulating water through the upper HX cooling the tank. At 150F it turns off. I use the 60 tonnes of mass in the floor like a big battery. In the winter my system never stops. The diversion control keeps the array working at maximum and the energy flows through the tank to the floor. At the end of the solar day the tank ( assuming there was sufficient sun) is at a minimum of 150F. I use thermostatic tempering valves on my floor and domestic hot water. The heating system has a standby load of 2w for the temperature control. At 155F the thermostats (7) turn on using a total of 14w. If a zone calls for heat the zone control valve opens using 3w each. When a zone limit switch open  is made the Grundfos Magna pump starts. This is a VFD pump that controls on constant pressure. It  uses between 10 to 180w depending how many zone control valves are open. At 150F in the tank the system shuts down and goes back to using 2w watching the tank temperature and waiting for energy. This system is working very well for us. I put an electronic thermostat in the diversion control tank that turns the diversion off  at 157F and on again at 152F. In the summer when I am not heating the tank runs at these temperatures. There are also the usual thermodisc stye thermostats on the tank which are set at 175 just in case.
The lower HX could be used with a propane condensing boiler (or something similar) controlled by an aquastat if one so desired. We have a water heating loop on the wood cook stove in the new house also and it can run the heating system on its own as well as make hot water as we cook on it if there is no sun in the winter for an extended time.

PM sent

Will
24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system
+ 15 Heliene 330 mono, Classic 150

WillEert

  • Full Member
  • ***
  • Posts: 122
Re: Arduino based PWM diversion control system
« Reply #80 on: July 01, 2016, 10:47:24 AM »
I have changed the mode of the Classic from Solar to Legacy P&O. I seem to be making more power as the sweep does not reduce the diversion controls output on occasion as it did with Solar. Also it seemed Solar would be "happy" at a less than maximum output while Legacy seems be able to find all the watts.

Will
24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system
+ 15 Heliene 330 mono, Classic 150

WillEert

  • Full Member
  • ***
  • Posts: 122
Re: Arduino based PWM diversion control system
« Reply #81 on: August 21, 2016, 09:05:43 PM »
I think I have all the needed equipment for the expansion to the power supply. 15 Heliene 330w monos, racking, various types of wire and a Midnight MNGP6 combiner box.I have to build the array mount now and install the panels. If you didn't know better you would say the design is a firewood storage building with a very steeply pitched south roof that comes to within 3 feet of the ground.

   The new Classic 150 is in place and powered up. With the new array I will be able to bring in about double the maximum rated amps for the battery bank. The batteries are rated for about 85A max in but I limit them to 70A. I seldom get there as the batteries usually go to absorb and won't take the current before the sun gets around to where the panels will make that much current. With the new array that will not be the case. The battery amp load limiter will come in handy now. It limits on amps on WBJr amp flow to the batteries as well as output amps from the Classic. I limit the Classic to 75A. I posted the sketch for a stand alone battery amp limiter a while ago. I have been working on the code for the new system. The two megas ( one for each Classic #10 & #11) talk to each other using a  serial method that does not "block" the sketch. This keeps the PID amp limit and diversion controls working smoothly and well. I wanted each Classic to share the job of amp limiting and have got that working. The Amp Limit PID control is located in the DC_1_Amp_Limiter_Counter sketch (Classic /Mega10). It develops the amp limit setpoint and dynamically writes it to Classic10 limiting the amps to the batteries while also allowing maximum amps out of the Classic. It also sends the amp limit setpoint  to mega #11. The DCT_2_Amp_Limiter_2_Read_Write_Limit sketch then writes that limit to Classic11. Fun. The sketches are working well and when I change the amp limit in Classic 10, Classic 11 follows along very nicely. Might need to tune the control for two Classics when the system gets running but I know now I will be able to bring in maximum array amps while limiting the battery amps to a comfortable safe limit with two Classics.

    The electronic thermostat for the hot water tank is working well. It is located in the Classic11 mega and sends a signal using the serial without blocking to the Classic10 mega. It just turns off the diversion relay when the HWT reaches setpoint. I run it with a 5 degree differential as the tank always cools down that much overnight so it turns on the diversion relay on again the next day in time for the sun to come up. The control panel in each sketch permits easy adjustment of parameters.

Sketches attached

I am pondering the system of forcing floats and bulks. I can see that it is needed to force floats so that the Classics operate together and the system does not get into trouble ( Thanks DGD). I am not so sure about forcing bulks. I don't think each Classic will wake up at the same time as the arrays are slightly different. I am just thinking about putting a very long time into the absorb timer on Classic11 and then forcing it to float when Classic10 floats. Any suggestions?

Will
24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system
+ 15 Heliene 330 mono, Classic 150

Westbranch

  • Hero Member
  • *****
  • Posts: 2516
  • Building System (sort of) 1 weekend at a time
Re: Arduino based PWM diversion control system
« Reply #82 on: August 21, 2016, 09:18:14 PM »
Will, what program makes .INO files?
KID FW1811 560W >C&D 24V 900Ah AGM
CL150 29032 V.2126-NW2097-GP2133 175A E-Panel WBjr, 3Px4s 140W > 24V 900Ah AGM,
2 Cisco WRT54GL i/c DD-WRT Rtr, NetGr DS104Hub Hughes 1100 Sat. Modem
Cotek ST1500 Inv  want a 24V  ROSIE Inverter
OmniCharge3024  Eu1/2/3000iGens
West Chilcotin 1680+W to come

paul alting

  • Jr. Member
  • **
  • Posts: 64
    • http://paulalting.com
Re: Arduino based PWM diversion control system
« Reply #83 on: August 21, 2016, 09:34:54 PM »
Files in the Arduino IDE editor typically (traditionally) have used .ino as the extension.
They are C++ in reality, and I always use .cpp instead of .ino.

You can use a text editor to read them anyhow.

Regards,
Paul
6 x 200W PV into home-brew 6 stage MOSFET charge controller : Microhydro 220Vac 3 phase IMAG
8 x 400Ah LiFeYPO4 Winston : Latronics LS2412 inverter
QuadlogSCADA control and monitoring system : Tasmania, Australia : http://paulalting.com

Westbranch

  • Hero Member
  • *****
  • Posts: 2516
  • Building System (sort of) 1 weekend at a time
Re: Arduino based PWM diversion control system
« Reply #84 on: August 21, 2016, 09:43:29 PM »
Thanks Paul  :)
KID FW1811 560W >C&D 24V 900Ah AGM
CL150 29032 V.2126-NW2097-GP2133 175A E-Panel WBjr, 3Px4s 140W > 24V 900Ah AGM,
2 Cisco WRT54GL i/c DD-WRT Rtr, NetGr DS104Hub Hughes 1100 Sat. Modem
Cotek ST1500 Inv  want a 24V  ROSIE Inverter
OmniCharge3024  Eu1/2/3000iGens
West Chilcotin 1680+W to come

WillEert

  • Full Member
  • ***
  • Posts: 122
Re: Arduino based PWM diversion control system
« Reply #85 on: November 04, 2016, 08:36:32 PM »
I think I am about a week or so away from putting the new 4.9 KW array into service. I have been coding up the force float code and other goodies. The Classic 11 arduino is not doing PID / PWM diversion so I am putting potentially blocking code in that control. I am bringing in the Classic 10 instantaneous watts, KWhr and charge state along with the amp limiter set point into the Classic 11 arduino. This lets me add up the watts and KWhr so I can see what the system is doing without getting a calculator out. Both arduinos will increase and decrease their amp load based on the WBJr amp set point and limited by the Classic amp limit.

After months of smooth operation about a month ago the Classic 11 arduino "locked up". Unfortunately I just reset it without really looking at what it was doing too closely. This has been bothering me but like a car that rattles until you take it to the garage for repair how do you find a coding fault that happens once and then goes away? The other day it was locked up again. This time I looked at it and what it seemed to be doing and not doing before I reset it. It seemed to happen as the Classic went from FloatMppt to Resting at the end of the day. I checked my code over and could not see any reason for this to occur. Kind of a grasping at straws but I did take out a Millis timer that I had on the LCD on / off button. This was a very simple timer that I think can give problems when the millis roll over. I had been meaning to take it out for a long time but had not got around to it. I replaced it with an ElapsedMillis library timer that I like to use. I have been reading a good book about C coding and got to the section on arrays. It made me think about the changes I had made to my code. I document my changes and keep old versions of my code along with the dates so I can always go back. I realized that when I increased the data I was transferring between the Classic 10 and Classic11 arduinos I did not increase the size of the arrays that the data is parsed and stored in.   So I increased the size of the arrays to accomodate the data.  Hopefully that will fix the problem...........

Will
24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system
+ 15 Heliene 330 mono, Classic 150

paul alting

  • Jr. Member
  • **
  • Posts: 64
    • http://paulalting.com
Re: Arduino based PWM diversion control system
« Reply #86 on: November 04, 2016, 10:16:03 PM »
Hi Will,

With the millis() value, it in itself doesn't cause any troubles, only in how your code deals with it.
People run into trouble when they code the code to add to the millis() value rather then doing a subtraction to get the next time for doing something.
You might like to look inside the ElapsedMillis library to see how they do it. I don't use any library for working with millis() function, just works well enough with no lock ups at all.

Yes, it looks like you may have found the root cause of your troubles, with reading and writing to memory beyond the array range, which can be the cause of all sorts of issues.
Your code should be setup as functions that are called from the main routine in a timed manner.

Things to look for are, waiting for an event to occur by using a 'while do' loop structure.
If you use these, then you need to account for all possibilities of what can happen, so as to not lock up the while loop.
A common thing I see is where people code to check either key pad or button or some other digital input state, using a 'while do' loop in there.

What you might also consider is using a software driven interrupt based on a internal timer to drive the function scheduling, such as 'TimerOne' or 'TimerThree' libraries.
It can make to fairly accurate scheduling if you have need for functions that need to perform at specific time intervals.

I like your analogy to a 'car that rattles'.
There are many rattles in my Arduino Due that runs as my solar controller, that I need to attend to soon, now that I may have some time again.

Paul
6 x 200W PV into home-brew 6 stage MOSFET charge controller : Microhydro 220Vac 3 phase IMAG
8 x 400Ah LiFeYPO4 Winston : Latronics LS2412 inverter
QuadlogSCADA control and monitoring system : Tasmania, Australia : http://paulalting.com

dgd

  • Hero Member
  • *****
  • Posts: 1700
    • Lorylink
Re: Arduino based PWM diversion control system
« Reply #87 on: November 05, 2016, 01:52:06 AM »
..... I realized that when I increased the data I was transferring between the Classic 10 and Classic11 arduinos I did not increase the size of the arrays that the data is parsed and stored in.   So I increased the size of the arrays to accomodate the data.  Hopefully that will fix the problem...........

Writing data beyond the bounds of an array is guaranteed to lead to unexpected results. The Arduino IDE c++ compiler is fairly simple and only supports simple data structures. In better compilers there are dynamic memory management instructions. Malloc and Free functions to get and free up memory as needed. Nice when you want to implement structures such as indexed linked lists.
When you compile your code how much of the Mega's 8k ram are you using?
dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

WillEert

  • Full Member
  • ***
  • Posts: 122
Re: Arduino based PWM diversion control system
« Reply #88 on: November 14, 2016, 10:17:15 PM »
Hi Paul,

My code was subtracting the millis value however the ElapsedMillis library has some options for timers that I find handy and do not have to figure the code out for myself.

Hi Dgd,

When I compile the code I am only using 14% of the Megas dynamic memory. So far the control is running well without crashing since I increased the array size. The serial function I am using to send data between the two Arduinos has start and end markers for the packet. I think if the array ran out of room before it received the end marker then the control would just stop - which is what it seemed to do.

Thanks for the help.

Will
24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system
+ 15 Heliene 330 mono, Classic 150

WillEert

  • Full Member
  • ***
  • Posts: 122
Re: Arduino based PWM diversion control system
« Reply #89 on: November 14, 2016, 10:50:31 PM »
The new array is in service. Yay!!!! It took us two days to install the panels and wire them to the Midnite MNPV6 combiner box. All seems good so far. Today was the first day of it being fully operational all day. A difficult day for making power. Sun / cloud/ Sun/ dishwasher cycling / cloud. I am trying to bias the new array ( array 2) ahead of the old one so that it maintains the load while array 1 takes the swings. +.1 V difference in absorb and float setpoint seems to do the job. My code was full of bugs for forcing floats but I have it working very nicely now. The two Classics seem to coordinate themselves quite well as Bulk / Absorb changes. The amp limiter got a workout today as the insolation changed. I am limiting both Classics and the control is slower than I like. When the amps to the batteries is not being limited the control output is 0. When limiting today the control had to increase it's output to about 50% before it would limit the Classic output. Ie WBjr amps to batteries setpoint  = 70A. Each array therefore needs to be limited to about 35A so the control has to increase it's output to about 50% before affecting a change. This puts a lag into the control while the output winds up. I am thinking about some kind of output tracking system that will calculate the required control output for the desired setpoint. When the control turns on it would use this output value to start. This would reduce the time lag and speed the control up. Possibly fiddling with the tuning would work also - more proportional? Overall however I am quite pleased with the install and first day of operation.

I am grateful to the help that I have received from people on this forum as I learned coding and physical computing - particularily Dgd and Paul. The house would not work without the diversion control and the ability to customize it's configuration for the needs of the system. Thank You.

Winter is coming to Manitoba soon. We have had an incredible spell of warm weather which has been nice for building but this Friday we are supposed to be H of -7C / L of - 15C with snow and blowing snow. I know we will be happy to have our new power supply working in time for this.


Will
24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 3x Magnum 4448, homecooked diversion system
+ 15 Heliene 330 mono, Classic 150