Arduino based PWM diversion control system

Started by WillEert, May 29, 2015, 10:09:50 AM

Previous topic - Next topic

ClassicCrazy

Will ,
I have only messed around with Arduino a little bit - but that code you wrote is excellent - I mean I can follow along and understand what is going on. 
You did some good work there .
Thanks for sharing it
Larry
system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system 2
 5s 135w Kyocero , 3s3p 270w Kyocera  to Classic 150 ,   8s Kyocera 225w to Hawkes Bay Jakiper 48v 15kwh LiFePO4 , Outback VFX 3648 inverter
system 3
KID / Brat portable

WillEert

Hi Dgd and ClassicCrazy

        Thanks for your kind words regarding the stand alone  PID amp limiter control code. As you know I am very much a learner so it is very nice for me to get positive comments - Thanks again. I learned a lot from Paul when he was helping me with the first iteration of the diversion control. I have not had time to fiddle much with the code he wrote for me as I need to learn more to understand what he did and how he did it. When he refactored a sketch for me I learned a lot about how a skilled programmer would write the same code that I had written.
       I am using IDE 1.6.5 at this time. I guess that I should upgrade but our internet connection is via satellite and download speeds are painfully slow.
       I have puzzled out the tables  4130-1 and 4160-1 and now understand the hex values in them. How to read and write to 2 registers which appear to share bit addresses still remains out of reach for me. David - Thank You for finding the time to post an example for me.

      Please be aware that the sketch with an RW in the name is a work in progress that I am using to read / write to the Info and ForceFlag tables. The other sketch without the RW should be used if people wish to use the Amp Limiter.

       The diversion control at this time uses a Mega 2560 and an Uno. The Uno does the thermostat and button functions as there are lots of delays in these sketchs. The PID needs to run without delays as does the Modbusmaster to work well. They "talk" to each other by reading pins high or low as the thermostat and button status changes. I want to get the RS232 on one of the serial ports of the Mega with the other accessing the serial in the IDE but this is down the road. I have melded the PID PWM voltage diversion control with the PID amp limiter and it is working quite well.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

WillEert

I think I have figured out the code to access the required bits of the Info Flag table 4130 and Force Flag table 4160. I configured packets per usual SimpleModBusMaster coding for reading and writing to the registers. Although bitRead does not require it I bitshifted the 4130 table 9 to the right to put the current limit bit as LSB then read it using bitRead. This seems to work. I am very nervous about writing to the ForceFlag table as the ForceSweep bit is surrounded by bits in the table that the table description states "Do NOT Set to 1". I have attached a code snippet that shows the code I am thinking about using to write to the ForceSweep bit. With no liability incurred if I could get a second ( or third) opinion if this is a suitable way to code this force then I will give it a go. I live offgrid and it would be very inconvenient to damage my Classic as I do not have a spare handy.

Thanks

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

dgd

Will,

Cant see why that wont work  :)  Have you tried it yet?

dgd


  int amplimitBit;
  int ampLimitState;
  ampLimitState = (unsigned int)readRegsf[0] >> 9;     // 10th bit to the left has`amp
                              //  limit status on/off bit- shift to LSB position
  amplimitBit = bitRead (ampLimitState, 0);                  // read LSB
 
  //unsigned int forceSweep;
    uint16_t forceSweep;
    forceSweep = 0x00000800;
    packets[PACKET8].connection = 1;                          // turns packet8 write connection on
    writeRegsf[0] =  forceSweep;

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

BobWhite

Quote from: WillEert on November 30, 2015, 09:53:51 AM
I think I have figured out the code to access the required bits of the Info Flag table 4130 and Force Flag table 4160. I configured packets per usual SimpleModBusMaster coding for reading and writing to the registers. Although bitRead does not require it I bitshifted the 4130 table 9 to the right to put the current limit bit as LSB then read it using bitRead. This seems to work. I am very nervous about writing to the ForceFlag table as the ForceSweep bit is surrounded by bits in the table that the table description states "Do NOT Set to 1". I have attached a code snippet that shows the code I am thinking about using to write to the ForceSweep bit. With no liability incurred if I could get a second ( or third) opinion if this is a suitable way to code this force then I will give it a go. I live offgrid and it would be very inconvenient to damage my Classic as I do not have a spare handy.

Thanks

Will



Will, just curios if you don't mind! were or should I say what state do you live in and are you in collage?
Walt
12-Lifeline AGM 8D's
10-Lifeline AGM GPL 31T
16- Diehard GC2
4-Classic 3-150 and 1-200
1-Classic Lite
2-BRATS
5wiz bang Jrs, , 2- Samlex-24Volt
5- 235 MX60s
10- Sharp 198
10 Solar world 345 XL Mono

WillEert

Hi Dgd,

I have tried reading the current limit status flag bit and that is working well. I know that I am reading the correct bit since I can see it change state when I run the amp limiter down until it turns on. I have not tried the write to force a sweep yet as I was not sure if using uint16_t was correct. Also I was nervous about using hex to write the force bit into the correct location in the register as I have not done that before. The sun is has gone down now where I am so I may try tonight or maybe Wednesday as we are busy tomorrow. Thanks for the reply and sharing your knowledge. If I can access these bits then it should not be too difficult to puzzle out some logic to force a sweep without a time lag when the control is needing to increase output following being in a load limit condition.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

WillEert

Hi Walt,

I live in the frozen north- better known as Manitoba. I am far from a college student as I am old (60) and retired. I worked in a pulp mill in British Columbia for 30 years as a power engineer before I was able to quit retire. I have never done programming nor fooled around with electronics before I started this topic in May however I knew I needed a better control for my power system and had an idea of how it would work and what it would do. I am very grateful to Dgd and Paul Alting for the help they have given me on this project and the knowledge they have shared as I would not have known how to start or go about building and programming this control without the information and sketches they have posted. I  now have a fairly extensive collection of Arduino and C books that I read and think about when I am trying something new or trying to figure out why something is not working. The house we are building uses the diversion power from the array to heat domestic hot water. A heat exchanger in the HWT tank removes the energy when the tank is hot enough and the heating system put that energy into a hydronic floor. The PV system makes our electricity, domestic hot water and heats us ( when the sun is shining) :). I can't wait to get going on an Arduino based data collection and logging system for my heating system - lots of fun ahead.

Cheers

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

BobWhite

12-Lifeline AGM 8D's
10-Lifeline AGM GPL 31T
16- Diehard GC2
4-Classic 3-150 and 1-200
1-Classic Lite
2-BRATS
5wiz bang Jrs, , 2- Samlex-24Volt
5- 235 MX60s
10- Sharp 198
10 Solar world 345 XL Mono

BobWhite

Hmm short hours of daylight at this time of year, May I ask what you have for a system? You may have stated so Ill look back just don't remember seeing.

Walt
12-Lifeline AGM 8D's
10-Lifeline AGM GPL 31T
16- Diehard GC2
4-Classic 3-150 and 1-200
1-Classic Lite
2-BRATS
5wiz bang Jrs, , 2- Samlex-24Volt
5- 235 MX60s
10- Sharp 198
10 Solar world 345 XL Mono

WillEert

I have tested the code and my Classic is still chugging along fine. :) The current limit on bit does not appear that it will be of use for the logic I was hoping to use to toggle a sweep when needed as it turns on and off very quickly and the modbusmaster does not read it reliably.
I can write to the Force FlagBits table but since I can't read from it I am uncertain if I am actually forcing a sweep. I have tried to force a float and then a bulk and can do this so I think that I am forcing a sweep. I am waiting for the correct conditions to perform a force sweep test which should be in the next few days. I think I have a different logic puzzled out for toggling sweeps as needed when the amp load limiter is increasing load so if the sweep test goes well will put this into the load limit control. When this works the next step for me is amp limit PID PWM diversion.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

dgd

Will and Paul,

I have had some time to look closely at this code and extract the parts that interest me in progressing to a simple web page manager for the power diversion system.
Have also discovered along the way that I can use both the Classic's available serial ports, one for my Due web server and the other for a Mega to handle the power diversion to heat water.
Now just need to figure out the comms between the two Arduinos.

I hope you don't mind Will but I have hacked about your code and modified it a fair bit to do some streamlining, not necessary but makes me read the code easier..
eg I enjoyed the == test all inside !() instead of !=   :P

The underlying logic is excellent, I like your dynamic reconfiguring of the modbus registers to make energy availability and extraction the more efficient.
I'm sure there are a lot of people benefiting from the excellent work you have done.

Should be able to post my hacked code here soon

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

Hi dgd,

I am pleased that you are finding the code I wrote of use. I look forward to seeing the modified code, because as you know, I am definitely a learner. I learned a lot when Paul modified the code and look forward to moving my knowledge forward again.
I have gone through a few more iterations of the stand alone amp limit control and also the combined voltage diversion / amp limit control. I am pleased with how it is working. I hope to continue testing today with the code writing to force a sweep and also turning the amp limit control off when it is no longer needed. My wife is convinced that I am going to break the Classic but I am not so sure. My new panels ( 6 @ 330 w mono) and Classic 150 arrived a few days ago for our system upgrade so I have a spare Classic on hand if all goes wrong.....
Will post revised code when it is done.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

WillEert

Here is stand alone amp limit control sketch with the force sweep logic added. It should be an easy matter to add the force sweep to other sketches if desired.
I think it will come in very handy to be able to force the bits in table 4160-1 because if needed to force a float when I have the two Classics running without follow me it should now be quite easy.  8)
I am also posting the combined PID PWM voltage diversion sketch with the amp limiter added in. I have it configured with a thermostat arduino turning the diversion on / off in response to tank temperature and also a button turning the leds on / off after elapsed time. It will run as is without the lcds turning on or the thermostat affecting its operation but once again can be easily changed to what an arduinoist desires.  I attach the thermostat sketch also. I have a circuit diagram sketched out crudely for this combined control which I could post if there is interest but the pins tell you what is happening.

Will
(1)24 ET 185 mono, Classic 150,8x Surrette 6CS25p, 4x Magnum 4448, homecooked diversion system;(2)15 Heliene 330 mono,Classic 150;(3)2X6 Hansol345mono, 2 stand alone Hotspot ACDC12C Minisplit heat pumps.(4)15 Hanwha Q cell 400 1/2 cell, Classic 200: (5)1X6 HanwhaQcell 400 1 Hotspot minisplit ACDC18C

paul alting

Hello David and Will,
This sounds exciting news, from both of you, and would be happy to tag along and help with what ever I can.

Will, it is good to see you have been making steady progress with writing code for these little controllers, and especially for such a worthwhile project.
David, for the communications between DUE and Mega, I guess you could simply ustilise an existing async serial port on each and implement a simple communications protocol between the two.
This can be Modbus if you wish, or any other protocol that provides an efficient means to exchange data between both units.
Using Modbus has an advantage in some way, in that you will already have the library included as part of the existing code, together with knowing that Modbus is simple and reliable.

Presently, I have been working on my code for my new solar system.
This all operates on a DUE board and communicates to the battery BMS via CAN bus, which I have nutted out all the code for now.
The Due also is my solar controller, which will control the individual MOSFETS for each solar panel.
Today I plan to swing across from using the lead acid battery bank to the new Lithium LeFeYPO4 bank with new larger Latronics inverter.
I'll be flying by the seat of my pants so to speak for the next couple of days until I bring up the solar controller section, as I'm still running on the microhydro system on the old system, with low water flows.

But I'm about and do keep a keen eye on all post in this open source section :)
____
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

AncellCavat

#59
It's good to read you are getting into electronics and micro controller coding.
The Aduino 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.

smt assembly