A Forum run by Enthusiasts of MidNite Solar

The Open Source software/hardware corner => Arduino => Topic started by: WillEert on May 29, 2015, 10:09:50 AM

Title: Arduino based PWM diversion control system
Post by: WillEert on May 29, 2015, 10:09:50 AM
I am very new to Arduino and writing code and electronics in general. I live off grid and have done for a number of years. I have a classic 150 that I enjoy using. I have not been able to find a setpoint for the Aux 2 PWM threshold and width that works well consistently. My diversion control problem symptoms are similar to cpfl on the Raspberry pi section of this forum. I believe what is needed is a means of turning the diversion on when excess power is available, regulating the PWM rate to control battery voltage and then turning the diversion off when the excess power is no longer available. If a WBjr is used then AUX2 is no longer available for diversion use.

Thanks to dgd and Paul Alting who have been giving me advice and assistance. I have obtained an Arduino Uno R3 and have achieved making an LED blink at a variable rate. I have ordered an ethernet shield, rs 232 shield and a suitable DB 9 rs232 to RJ 11 cable ( Thanks dgd). I am on my way.

Question - If the Arduino connects to the Classic at the centre RJ 11 connection then can Follow Me still be used? I know my system will have to get bigger and that I will need to stack another Classic in order to get the capacitymy system requires. Maybe a splitter?

Thanks

Will

Title: Re: Arduino based PWM diversion control system
Post by: dgd on May 29, 2015, 02:38:34 PM
WillEert,
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.
Keep us informed of your progress  :)

When you extend your RE system to include a second Classic then follow me can be implemented using the Arduino. I have experimented with this but have not yet found it absolutely necessary as my Classics track battery voltage very accurately and change charge state at almost same time.

Dgd
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on May 31, 2015, 11:16:13 AM
Waiting for my parts and manuals to arrive. What to do. One of the manuals I ordered - Arduino for Dummies (I do not feel like a dummy) has arrived so I am reading that. I cannot do the exercises as I lack the hardware but that will come. Learning lots.

Found the MODBUS Network Spec. rev B.3 --- May 28,2013. Reading that and attempting to understand it. I think I will have to almost memorize this document by the time I am done. Looking for registers that hold data that would be needed for a controller to operate.

Questions - The document references tables that I do not find in the document ; for example table 4146 - 1 USBcommMODE. Are there more tables somewhere else? Maybe these are internal tables that can only be seen when viewing the registers? Maybe the document is not complete or has been modified? I am thinking I may cut and paste this document to organize the tables in numerical order to make them easier to find.

                - Is register 4149 the Absorb set point voltage as it states or actually the Absorb voltage set point?

                - Are the voltage setpoints, 4150,4151,4149?,  the Tcomp set point that the Classic is actually controlling the stage voltage  to? I do not find a TComp setpoint register anywhere in this list.

Thanks

Will the Noobie
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on June 02, 2015, 08:06:52 AM
Somewhere on the web was an Arduino simulator where you could build circuits that would work .
For some good Arduino tutorials check out Adafruit  .
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on June 05, 2015, 11:40:13 AM
More of my textbooks and hardware has arrived. Went to Adafruit and downloaded the lessons and other info. Thanks ClassicCrazy for the tip. Studying like wild when I am not building our new house or gardening or doing life.

Success - I was able to compile and upload dgd's sketches from the rs232 and uno webserver topics. Thanks again dgd for all your thought and work.  Had problems compiling at first but once I did more learning about libraries and also found the correct modbus library things worked very well. Ordered an LCD shield and waiting for my RJ11 to db9 cable. I suspect that I will have to be careful about the pinouts  on this connection???

Cheers

Will
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on July 04, 2015, 12:04:16 AM
I'm looking for some input into this diversion control code I am writing for the Arduino for Will to use.
At present I have most of the basic code skeleton there to support various parts of the functionality, but am undecided about the a central core part of the control methodology.

To summarise, the code is designed such that it talks to the Classic to get the current situation of the charge controller, the PV array and battery bank.
Based on the situation, it should be able to work out when not to allow diversion to occur or when to allow it.

The Arduino code will provide two outputs that will be PWM independently to their respective loads, but in a lead / lag control.
This form of control will initially bring on the lead output under PWM to provide smooth ramping up of the diversion energy to the load.
As energy becomes available from the PV array and knowing the battery bank has completed the charge process and is in 'float' mode, the control will continue to ramp up the PWM output on one of the outputs.
If the energy form the PV array is such that there is more available than the load can consume, the controller will at that point bring on the second output at full 100% on while zeroing the PWM on the initial output. If the two loads are equal in power dissipation then this will be seen as a transparent and smooth condition change, from lead load being 100% PWM to lag load being 100% on (not PWM) and lead load being 0% PWM.

All that is good and I have no problems with that part, having done these things in PLC's for industrial compressor systems.

But, my thinking is that with a charge controller, if the energy diversion is such that the load is to be via an inverter that is connected back to the battery bank, then essentially the load is being powered by the battery bank, based on the condition that energy diversion is allowed only when the battery bank has completed its charge cycle and is in 'float' mode.
In 'float' mode, the charge controller just maintains the voltage according to the float setpoint.

My understanding is all charge controllers will drop back to 'bulk' mode when the battery voltage falls to another predefined setpoint.
With this, it is also true that to get the energy from the PV array to the load, via the charge controller and battery bank, the energy diversion controller will not want the charge controller to be in 'float' mode. It will need to be in full on charge mode, whether that is 'bulk' mode or whatever. The idea is that we want maximum energy flow though the circuit so that it can be 'diverted' to the load.

The reason I am thinking that this controller will need to force the Classic back into 'bulk' mode is so that no or very little energy is taken form the battery bank to support the diversion system.
We want the battery bank to remain fully charge and ready for when it is needed after sun down.

So, my thoughts are, if the diversion controller manually forces the Classic to go back into 'bulk' mode, what impact does this have on the way the Classic handles things and does it then confuse the Classic in anyway ?

So, to confirm, the energy diversion system is essentially connected to the battery bank and will have its own inverter to supply the two AC loads.
The other side of this dedicated diversion inverter will have two AC SSRs that will be controlled by the Arduino at a rate the AC SSRs can handle, which is slower than the inverter line frequency, due to zero-crossing switch on and the fundamental function of how a SSR (internally a TRIAC) only switches off at the zero point as well.

I have mentioned to Will, the other concept of taking the energy pick up point directly at the PV array input to the charge controller, if the PV array VOC matches the specifications of the load.
He mentions this might be a workable idea as well. The PV array VOC is around 110Vdc, which would suggest it could be used to feed the approximate 110Vac load heating elements.
In this case, we could use a DC SSR to feed the PV array directly to the load elements without any need for a dedicated inverter.
Also, since it would not be connected to the battery bank, there is little risk of depleting the store energy form the battery under any condition.
Added to this would be the small increase in efficiency of transferred energy from the PV array to the diversion loads, having not to pass through the charge controller and then back through the dedicated diversion inverter.

I would like to hear what thoughts and ideas other might have or tricks about the Classic that I don't yet know that would help me formulate the correct control methodologies for this Arduino controller.

The Arduino project is named SEnDArd - Solar Energy Diversion control program for Arduino, any other suggestions ?
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: cpfl on July 05, 2015, 12:36:47 AM
QuoteMy understanding is all charge controllers will drop back to 'bulk' mode when the battery voltage falls to another predefined setpoint.
With this, it is also true that to get the energy from the PV array to the load, via the charge controller and battery bank, the energy diversion controller will not want the charge controller to be in 'float' mode. It will need to be in full on charge mode, whether that is 'bulk' mode or whatever. The idea is that we want maximum energy flow though the circuit so that it can be 'diverted' to the load.

The reason I am thinking that this controller will need to force the Classic back into 'bulk' mode is so that no or very little energy is taken form the battery bank to support the diversion system.
We want the battery bank to remain fully charge and ready for when it is needed after sun down.

So, my thoughts are, if the diversion controller manually forces the Classic to go back into 'bulk' mode, what impact does this have on the way the Classic handles things and does it then confuse the Classic in anyway ?

Paul,

As per my thread on the RPi side, "Continuous tweaking of AUX2 threshold for maximum PWM output", you can redirect all available power to the diversion load without it affecting the charge controller mode.

current battery volts    = modbus register(4115)
target battery volts      = modbus register(4244)

Any controlled changes to the diversion load (by adjusting the PWM value) should make sure that the current battery voltage remains as close as possible to the target battery voltage. As long as the current battery voltage is within about 0.4 volts of the target battery voltage then it will not affect the charge controller mode, ie BULK, ABSORB, FLOAT, EQ. Ideally, the current battery voltage should be kept at 0.2 volts under the target battery voltage.

Attempting to maintain the 0.2 volts under target will ensure that even when the sun sets or is obscured by clouds temporarily, the system will compensate and reduce the power going to the diversion load. The battery bank should never be discharged due to the diversion load.

Chris
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on July 05, 2015, 12:46:19 AM
Chris, that clarifies it for me nicely, thank you.
Now I have the a better understanding and the missing piece of the puzzle is found.

I'll re-read what you say and have identified this section in your C code where you do this.
I think if I utilise what you say above and use that to be the input to the PID block which then provides output to the PWM, I hope that will be getting closer to what is needed.

Just trying to calculate what 320 sqft is in square meters, I think we have similar size little cabins :)
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: cpfl on July 05, 2015, 12:55:13 AM
Paul,

I think you'll have Will's project cracked now.

If and when I decide to get a WBjr for my system, I will be looking at implementing the same thing.

Yes, the 320 sqft (30 sq meter) cabin is cosy.

Chris.
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on July 06, 2015, 10:58:43 PM
I am very grateful to all the people who are contributing to this diversion control project. Thank You. We are building a new house and optimizing the power supply is important to us as we want to get to net  zero carbon  with our lives.  I am on my 6th book now about Arduino and its capability's and am gradually learning to speak the language. I have done a little basic coding and can see that it will take me a long time to reach the level of expertise of Paul, Cpfl and dgd. I am learning a lot which I enjoy. Paul is teaching me much which is very helpful - Thanks Paul for taking me under your wing. 

I have been buying hardware and getting ready to go. I think I have  figured out the pinout for the RJ11 - DB9 cable and have ordered the parts needed to make a nice one. We decided to use a Mega 2560 R3 for this control and it has now arrived as has the RS232 shield. As I have time I will try to get dgd's LCD Uno system ( I have the parts for that) up and running to prove out the cable. I want to use the lower RJ11 port as I presently have a remote MNGP connected to the middle one. I don't see downside that except possibly we cannot write to that port?

Thanks again. I guess I will know if I got the pinout correct if any magic smoke comes out of some of this equipment when I plug it in

Will
Title: Re: Arduino based PWM diversion control system
Post by: T on July 09, 2015, 11:56:23 PM
Here is my Arduino based diversion control code.

I have 2 aux outputs on this. I'm using aux1 for an air conditioner and aux2 for a dc water heater element.

I went with a PWM frequency of 30hz because it produces much less heat in the SSR compared to the aux2 of the classic which I believe is 500hz.The 30hz frequency does track slower. It takes a few seconds to go from 0% duty cycle to 100%, or back down, but it really doesn't seem to matter in my system.

The settings are easily adjustable by changing the variable values at the beginning of the code.

The only input I'm getting from the classic is the Float High signal from Aux1. I configured the Aux1 jumpers for relay operation and use it to switch 5v from the Arduino to a digital input pin on the Arduino.

For battery voltage measurement, I just use 2 resistors as a voltage divider and input the voltage between the two to an Arduino analog pin.

I power the Arduino with an adjustable voltage regulator which I configured to output 9.8 volts. The SSR's are fed from this 9.8 volts through transistors that are switched by the Arduino output pins... not sure if the Arduino pins could power the SSR's by themselves or not.

I have the voltage settings at a point where my batteries will typically be over 90% before the water heater begins to PWM. However,I am giving priority to hot water over Absorb with these settings because I hate cold showers.

I've had this up and running for about 2 weeks now and it works very well. I can now use the Classic Aux2 port for the WBjr if I want to...I do have a separate SOC monitor already. The main reason I did this was to PWM the water heater at a lower frequency and get more control over the diversion outputs.

I think one advantage of this design (with minimum input from the charge controller) is that it can easily be made to work with a different charge controller. This would be great if my Classic had problems and I needed to switch back to my cheap pwm charge controllers temporarily.

Hope this can help with your project.






unsigned long timeOfLastFloat = 0;
float aux1BulkSetPoint = 50.0;   // I set this high to run only in float
float aux1FloatSetPoint = 13.4;
float aux1SetPoint;
unsigned long minOnTime = 300000; // aux1 delay in milliseconds
unsigned long minOffTime = 180000;
unsigned long timeOn;
unsigned long timeOff;
boolean aux1State = false;

int aux1 = 10;  // using aux1 for window air conditioner through inverter.
int aux2 = 11;  // using aux2 for 300w dc water heater element.
int floatRelay = 2;
int voltagePin = A0;
float voltage;
float voltageFactor = .0206;
float aux2BulkSetPoint = 13.8;
float aux2FloatSetPoint = 13.2;
float aux2SetPoint;
unsigned int pwmSetPoint = 0; // start with duty cycle of zero. 100% duty cycle = 255
unsigned int pwmSetPointInc = 2; // amount to increase or decrease duty cycle each loop
//unsigned int ctr = 0;

void setup() {

  TCCR2B = TCCR2B & 0b11111000 | 0x07;   //set timer2(pins 3 and 11) to 30hz

// Serial.begin(9600);
  pinMode(aux1, OUTPUT);
  pinMode(aux2, OUTPUT);
  pinMode(floatRelay, INPUT);
  digitalWrite(aux1,LOW);
  timeOn = millis();
  timeOff = millis();
}


void loop() {


// Get float signal from aux1 of classic (with aux1 set up in relay mode). 5v from arduino through classics
// aux1 relay provides the input to floatRelay. Aux1 on classic set to float high mode.
// Then set voltage points to their bulk or float values.
// timeOfLastFloat is set to keep voltages at float values when Classic goes into float mppt mode.
 
  if (digitalRead(floatRelay) == HIGH){
    aux2SetPoint = aux2FloatSetPoint;
    aux1SetPoint = aux1FloatSetPoint;
    timeOfLastFloat = millis();
   
  }
  else if ((timeOfLastFloat == 0) || ((millis()-timeOfLastFloat) > (28800000))) {  //28800000 is 8 hrs in milliseconds
    aux2SetPoint = aux2BulkSetPoint;
    aux1SetPoint = aux1BulkSetPoint;
  }

 
//read battery voltage


  voltage=analogRead(voltagePin) * voltageFactor;

// aux2 logic (PWM)

  if (voltage >= aux2SetPoint) {
     if ((pwmSetPoint + pwmSetPointInc) <= 255){
       pwmSetPoint += pwmSetPointInc;
     }
     else{
       pwmSetPoint = 255;
     }
     
  }
  else if (voltage < aux2SetPoint) {
    if (pwmSetPoint >= pwmSetPointInc) {
      pwmSetPoint -= pwmSetPointInc;
    }
    else{
      pwmSetPoint = 0;
    }
  }
 
  analogWrite(aux2,pwmSetPoint);
 



//aux1 logic (ON/OFF with delays)
 
  if ((voltage >= aux1SetPoint) && (!aux1State) && ((millis() - timeOff) >= minOffTime)) {
    aux1State = true;
    pwmSetPoint = 0;  // turn off power to aux2 to ease starting of motor on aux1
    analogWrite(aux2,pwmSetPoint);
    timeOn = millis();
    digitalWrite(aux1,HIGH); //turn on aux1
    delay(2000);  // delay starting aux2 for 2 seconds
  }
 
 
  else if ((voltage < (aux1SetPoint - .4)) && (aux1State) && ((millis() -timeOn) >= minOnTime)) {
    aux1State = false;
    timeOff = millis();
    digitalWrite(aux1,LOW);
  }
 
 
 
/*  used for debugging only
  ctr++;
  if (ctr >= 90){
    Serial.print(aux1SetPoint); Serial.print(" ");
    Serial.print(aux1State); Serial.print(" ");
    Serial.print(voltage); Serial.print(" ");
    Serial.print(millis()); Serial.print(" ");
    Serial.print(pwmSetPoint); Serial.println("");
    ctr = 0;
  }

*/
  delay(33); //This delay equals approximately 1 period of a 30hz signal

 
}
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on July 10, 2015, 12:25:13 AM
Hi T, welcome to the forum.
Thanks for your insight and code that you use, just soaking it in with the way you do it.

Yes, I have found the Arduino is quite capable to switch the SSR directly, though going through a level transistor can only be better as not all SSR's are the same.

With your battery measuring, only using two resistors, I am guessing you are working at the lowest workable level, yes, I think you are on a 12 volt system
Anything higher becomes problematic with using two resistors as your scaling and then resolution is lost.
I do use this for my system at present and am on a 24 volt setup.

Will is on a 48 volt system, so using a resistor divider is not going to work.

Instead, we are using Modbus to get all this data from the Classic, which will be far superior in terms of accuracy, resolution and stability.

Like you, I am making my code adaptable to be used with other charge controllers, with the code making allowances for Modbus register maps for other charge controllers, such as TriStar units.
At present the code I am working on for Will is designed now to operate in a Mega based board due to the need for controlling two loads.
An Arduino UNO has the capacity for two PWM, but that gets reduced to one if there is ever the need for Ethernet.
Again, the design behind what I am doing is that a lot of this is sorted out by the pre-process before compilation.

One thing with SSR, which you will probably know, and that is that AC SSR's are limited to how fast they can operate due to the zero-crossing point used for on switching and the same point as a function of how the internal TRIAC works anyhow. This means that a typical AC SSR can only be switched on and then off, no more than once every cycle of the AC waveform, as there are two zero-crossing points in a single cycle.

With DC SSR's, they are essentially a MOSFET and can operate quite fast, and the ability to PWM this at a higher rate is something that can improve the overall control effectiveness.
As with any semiconductor device, working in the digital domain, components will get hotter with higher switching rates, especially with MOSFET based devices.

You say you are using DC for water heating, can I assume you are taking the DC direct from the PV array via a low voltage high current DC SSR, such as a 60V 40Amp device ?
Can you tell more about your setup, in terms of the PV size and batter capacity ?

I am sure I see 'T' over on the Arduino forums just in the last few days :)
Well, all this brings in new ideas and it is good to see how other people are doing things.

Hopefully I will have some code and a document to share in the coming week or two. The code itself is over a number of files and over 1k lines, errr, so far :)

Thanks 'T', whoever is behind that, for your input, and hope you can share more as things develop.
Edit: oh, can you edit you last post and place your code in code tags please.
I only asked someone in Arduinoland a few hours ago to do same. One day, these forum software's will be able to detect it automatically, one would hope.
____
Paul (aka Rockwallaby in Arduinoland)
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on July 10, 2015, 01:17:41 AM
T
With your code, a few things pop up for me.
First is the method of controlling the PWM, it will bounce back and forth between the setpoint dead-band limits, continually oscillating in a sawtooth waveform.
Obviously this will work, but can be improved by using a PID loop control function to provide nice smooth and stable signal which then can be applied to the PWM function.

The other thing is you have a delay(2000) in your main loop.
I'm just now writing an email to another who is writing Arduino code about the pitfalls of over use of the delay(x) function.
Short delays are mostly not a problem, where the delay is only a few mSec, but a delay of 2000mS (2 seconds) really does have the potential to mess up a control system.
Many people put delay(big) in so many places that they often don't understand why their code does not perform the functionality they expect.
I ask everyone to first check for these delay(big) statements and remove them or refactor the code differently so the delay is not needed.

For AC SSR's I found the Arduino statement analogWrite(..) produces a PWM that is far too fast, typically I recall around 490Hz.
Instead, I use a timer library, such as Timer1 or Timer3 and then generate a PWM cycle period of a much lower rate.
I guess if you are using a DC SSR, then that will allow you to use the analogWrite(..).

Another area where you can save time on processing is to do away with all the floats and only use integer based types for everything.
Again, many folks think to do things they need to represent the data as they would, and that is typically as floating point data.
With virtually all the code I have written, I never use floats, not unless a sensor library provides it to me as a float, to which I quickly then and there scale it to an integer type.

For example, if you are reading a battery voltage of 12.6 volts, why work with a float of 12.6, instead, work with a scaled representation of this, typically scale by a factor of 10 or 100, but be consistent.
So, your 12.6 will become 126 as an integer. This is far easier for the poor Arduino CPU and when you are really needing to reduce processing time, then this is a method that has dramatic effect.

I go one step further, and that is I work with raw data where I can.
For example, if I read the analog port, I simply use that data throughout the program.
It will be from 0 to 1023, so 1024 counts of raw ADC data.
This means you loose no resolution along the way and all condition checking will be as accurate as possible as you have the raw data, you can't get better than that.
Typically I only convert from raw to more meaningful human readable data at the point of display, whether that be on a simple LCD or at once it enters the SCADA system and gets to a web page.

Hope what I have mentioned can be helpful :)
Right, back to coding for me  8)
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: T on July 11, 2015, 12:00:44 AM
Hey Paul, thanks for the input and suggestions.

My solar setup consists of 1200 watts of solar panels, wired for 24v nominal output. I have a 500ah 12v battery bank.

I am feeding the water heater from the 12v nominal of the battery bank (not directly from the solar array). Actually with my controller all current to the water heater will come from the output of the Classic, without drawing from the batteries.

I like your PID idea.  I may incorporate that into the code for the water heater control...probably just the PI part of it.

I am going to take out the delay(2000) statement in the code. It's not detrimental, but not really necessary after setting the duty cycle of the PWM to zero. This section of the code will only run when the air conditioner is switched from off to on...no more than once every 8 minutes minimum with my current settings.

I'm getting 30hz by using analogWrite(). The following statement in the code is what makes it happen: TCCR2B = TCCR2B & 0b11111000 | 0x07;

I could PWM the water heater at a higher frequency, but it's very inefficient on those very cloudy days where the duty cycle may be low for extended periods of time. This is the main reason I built this controller instead of just using Aux2 on the classic.

I can understand the performance advantages of using only integers in your code. I will keep that in mind for future projects that place greater demands on the processor.

Also, I haven't posted anything on the Arduino Forums. Must be a different T over there.












Title: Re: Arduino based PWM diversion control system
Post by: WillEert on July 21, 2015, 01:26:20 PM


Hi T,

Thanks for posting the code for your diversion controller. I will download the code and look at it. It is very interesting the various methods of diversion used and I find I can learn from each system. Thanks again.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on July 21, 2015, 01:43:02 PM
Got my copy of dgd's RS 232 modbus to classic system working but I am having an interesting problem with it that I do not have the knowledge to resolve. I am posting to that forum topic - RS232 modbus to Classic- as I think that might be more suitable. Thanks dgd for putting together such a nice system for people to use.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on July 24, 2015, 10:04:37 AM
Having been successful in getting dgd's system working on the lower rj11 Classic port I now need to get the temperature corrected Battery Voltage setpoint. Using the code in the Uno via rs232 to Classic I was able to add a packet and get register 4244 into a second array. It took several attempts but I was able to make this work. Having done this I added a page to the 16X2 lcd and displayed this value - then added some math and calculated what will be the diversion set point for this control. This I also displayed on the new page. Realizing that I needed access to the pwm pins that the lcd shield covers up I changed the code and put in an I2C 20X4 lcd which displays the Classic mode, battery voltage, temp corrected battery voltage set point and diversion control voltage setpoint. Now I am pondering how to add the PID PWM control to this system. Ordered another book which is focused on programming arduinos -still lots to learn. I am hoping to use this control as a test bed for the controller that Paul is working on the code for. I think adding pages to a 4X20 lcd and buttons and lead/lag element code will be beyond me for a while.

Will
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on July 24, 2015, 08:34:21 PM
I can see Will is making great strides with working with Arduino systems and attached peripheral components, well done Will, and it looks like I'll have another set of helping eyes.

Will, as far as putting the code for PID and PWM into the code you have is quite a step up in terms of the code logic required to do this.
The Arduino has built in functionality for analogWrite(x), which is PWM to a digital pin, but I have found this technique is not suitable for controlling a SSR.
I use a different method.

For me, I do need to remain as focused as I can on the code I am developing for you that does this.
Progress on the diversion code is getting there, the PID and PWM is in and operational for two load heating elements.

I am making the code such that it is able to be used by folks with Midnight Classics or Morninstar TriStar charge controllers, with separate Modbus templates for each.
The path I am taking with it allows for other solar charge controllers to be easily implemented and simply selected by a selection number at compile time.

Others might not yet know, but the code so far, which is designed to operate on an Arduino Mega, also has an integrated GUI system with communications on the main USB serial port via VT100 / VT220 terminal codes. This GUI allows for character placement at x , y screen location as well as colour to any standard ANSI terminal application.

In **nix based systems, such as Mac OSX or Linux variant, you simply use the terminal application and connect to the serial port and hey presto, a simple but worthwhile GUI on you computer screen.
With windows users, I have looked into this and it can be done using the built in 'command.exe' application or any one of many terminal emulators available that support VT100 codes.
Additionally, with this GUI, I am putting in place the ability, not only to view all data real time, but also to be able to alter setpoints and have other forms of control directly from your connected computer.

The code also has a full LCD menu system, allowing the same functionality as the VT100 GUI above, via a 20 x 4 character LCD and a number of push buttons.

My next step is to develop code to simulate a Classic charge controller so I may start testing.
For this project I had to swap out my Arduino Ether-Mega that was being used for my own running system for the Ether-Ten, a UNO with Ethernet size board.
This has now given me access to the Mega that I need for this project.
I have an older Arduino which I will setup as the Classic simulator over the next day or two.

The code for the diversion project continues to grow in size, but there is a lot of pre-processor code to help out with the particular user configuration at compile time.

I'm working toward having something available soon to show with code and GUI.
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on July 25, 2015, 09:39:24 AM
Wow. The diversion system Paul is developing is a long way past what I imagined when we started chatting about making code for a PWM PID diversion system for my power supply. It sounds like a lot of work and effort -Thanks Paul. I like the idea of the versatility that the control that Paul is developing can be used by others, even with other brands of charge controllers people may have ( deluded though they may be :o). I believe that for off-gridders a generic diversion system that they can obtain and will meet their needs is something the industry lacks. I know for my system my base daily load is about 5.5 -6 KWHr /day. With my old Apollo system that is what I made if my batteries were charged at the end of each day. Using the Classic , diverting excess energy via the Aux 1 Waste not hi function, into my HWT I now make about 12 -18 KWHr depending on the initial temp of the HWT - quite a bit more output from the power system. I use a hydronic heating system that extracts excess heat from the HWT and uses it for heating the house we are in the process of building. This works automatically turning heating on / off based on thermostat requirements and tank temperature. I have made 24 KWHr in a day while doing an equilization and heating as well. People pay for a power supply system and then the trick is to get as much out of it as possible to lower the cost per watt. The system Paul is developing looks like it will be able to do this on a generic basis. Great!

Will
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on July 25, 2015, 09:47:59 AM
Thank you Will for your kind words.
Currently buzzing along on my little Mac mini, with around 6 (check: make that eight) virtual screens all running, including watching the last mountain stage of Tour de France, three screens for web browsing, a few others for skype, email and then Eclipse IDE, and another for the terminal GUI.

So, I have the basic code for a Midnight Solar simulator up and running in a small Arduino now.
I have this connected to the Ether-Mega which is operating the diversion project.
Yes, they are talking, which now allows me to further progress the code and do testing.
All is good :)
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on August 01, 2015, 04:17:36 PM
Well I got the first iteration of my diversion controller running. My system is presently set up for AC diversion as I wanted to be able to use conventional AC thermostats on the tank. My next system may be DC diversion using an arduino based thermostat to control a suitably sized DC SSR. It took me a few days of struggling to get the PID control to read the values of the setpoint and battery voltage variables but by studying my books and trying various things finally a light bulb went on and I was successful. I put the Timer 1 library in quite quickly and set it up. I am quite pleased with the results. I have done some loop tuning in the past and it took a little bit but the tuning is not too bad I think. I am running the SSR at 10hz and the Magnum 4448 inverter is very happy at this speed. Thanks Paul. I had dedicated an inverter to diversion because of lights flickering / discomania at the Aux2 PWM speed but I think I will change my wiring around and see if I can my system working with all of the inverters operating in parallel again. The pwm always has output == 0 within -.3 or so of SP and there is no risk of draining the batteries. I have had a few sun cloud days and it seems to work well. Code posted. The board is an Arduino Uno R3. The 4x20 lcds are by DFRobot as is the RS232 shield. I made my cable by using a db9 - RJ11 adapter that acts as a breakout box. This was about $5 from ebay. Code attached.

Did you know that if you plug the 9V jack in and out of your UNO enough eventually the magic smoke will come out of the m7 diode and your UNO will stop being able to get power through the jack? I have learned this.

The control continues to develop. I have put in two tuning speeds in order to cope better with sun / cloud and when a large load starts or stops ( well pump, etc). I put in a second PID and logic to start it when the first is at 100% and then to turn off again when its output is zero. So far that logic looks like it is working OK. Now I have to rewire my HWT to simultaneous element operation and then get the second relay running the upper element. That will give the lead / lag operation that Paul suggested and that I like the idea of so much. It is apparent with the PWM that the tank temperature changes little if at all until the wattage the element gets is about 50% of rated KW. I picked up the thermostat I needed the other day so time permitting maybe next week I will be able to test lead / lag operation.

Bought another book - this one focused on actual C coding as it relates to the Arduino. I am a few chapters into it now and it is teaching me lots that has been a mystery until now.  I know the code that I have created is clumsy and likely does meet any number of good conventions. It does work however.

Will
Title: Re: Arduino based PWM diversion control system
Post by: dgd on August 01, 2015, 08:28:39 PM
Will,

Thats excellent progress  :)

The power connector problem seems to be well known on the Arduino newsgroups.
I always use the USB connector to provide 5volt power to the uno, Mega or DUE. This has several advantages.
It bypasses the on board voltage regulator which at best is not very efficient, ok for playing about with and occasional use of the Uno but as a long term power supply its not too good. The recommendations are a 7.5volt to 9volt DC power unit but if you have attached one of more expansion cards then it can take power consumption well over an Amp, this means the simple onboard regulator is probaby disposing of 2.5 to 4 volts at > 1A and producing several watts of heat.
My first Mega got very hot after an hour or so and it eventually died, completely dead the cpu is non responsive.
So if you use USB 5volt power = amost no excess heat at the Uno.

I also means to upload sketch that I just unplug the one metre long USB cable at the apple power wallwart and plug it into my laptop for the upoad.
I also use an apple 12/24volt cig lighter power adaptor, I have wired a twin USB socket version of this via 5amp breaker to my
DC power distribution panel. Works well, these adaptors seem to use a decent switch mode regulator so produce very little heat from my 24v battery system.

Although I designed my ex-pc-psu case with a teensy fan and the DUE with temperature probe to control it, it has never come on since I moved DUE to 5V usb power. After running a few weeks I can touch the DUE and its hardly warm, the warmest part is the Wiznet ethernet chip on the Enet card.

There is no such thing as code that works being clumsy, its always good code if it does what its supposed to. Be pleased with what you have achieved. Just remember to puts lots of comments in your code to remind yourself what the code is doing and how it does that. Comments are not for other people, they don't matter  :o
I know (hired) professional programmers who keep two copies of their code, one detailed with comments for their own use and one stripped of/devoid of comments that they distribute to others. Weird science eh?   :P

dgd
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on August 01, 2015, 08:35:21 PM
Will,

Well done so far, good to see your progress and and achievements thus far.

I took a little look at the program and, well, over a cup of coffee I couldn't help myself with a bit of massaging of it.
I hope you don't mind, instead, hopefully it gives better insight.

I totally refactored the code to be indented to the normal 2 space and correct indentation for statements and for easy reading :)

The last two lines in the main loop() would be better moved to another location where they will do something while in the loop()
I am not able to make a lot of sense with the second last line. Having two equates on a single line is not usually done in C and is advised against such statements.

Looks like David has just made a post, so I better post this to read :)
Must be breakfast time, surely.

Will, I will have this code of mine ready today for testing, if you are keen to try when you are ready ?
I will prepare a write up for it.
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: dgd on August 01, 2015, 09:36:14 PM
Will and Paul,

I really like this code you have both posted and I will be setting up a water heating system at a friends place and this is just getting to what I need.
In the quest for a truly black box I wil be interested in not having an LCD display on the final production version, maybe at most an externally visible LED or two, one that perhaps flashes at a rate that reflects to PWM cycle and another for power.

It seems the Classic has no issues with using both available serial ports to talk to Arduinos. I have tried DUE for web server and an UNO on other port just showing data on LCD. This UNO I''d like to get to manage the DC water heating.

dgd
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on August 01, 2015, 09:53:52 PM
David,

Yes, in regards to the LCD, I agree, and have been thinking on this in the past weeks while writing this code of mine.
In the past, I have used LCD, such as 20 x 4 style units and they have performed well in those applications.

On my HydroSolar system, I do have an LED that does light in beat to the PWM, and it provides a nice quick indication for me of the battery state.
When it is not flashing, I right away know that no dumping of energy is taking place.
Then, while it is beating to the PWM signal, I get a fair idea of the amount of dumping taking place, with an almost on beat telling me that a lot of energy is being diverted to the dump load.

In the code I have, I have a pre-processor define that can be set at compile time to set either the LCD code or the VT100 code.
Presently, I just use the VT100 code as I think that is a nice way to display data as compared to a LCD.
Plus, I don't have a LCD2004 here at the moment anyhow.

The VT100 code is simply the Arduino sending out data through the normal USB serial port connected to your computer.
Your computer runs a terminal application that understands VT100 escape sequences.

I'll get back to doing some finishing off things to the code and then make a post with it all.
One point, the code is set for an Arduino Mega, not a UNO, but if you really would like or need to have it for a UNO, I think we an do that.
Using a UNO, with only one hardware serial port and wanting to use the VT100 GUI is going to need to use the SoftwareSerail library.
I haven't used this library as my thinking is that if a project needs multiple communications ports, then use a bigger board that has the ports.

It will take some hours yet, and have fresh coffee to make a start :)
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on August 01, 2015, 11:20:32 PM
I was on a roll and simply wasn't able to resist in distilling your code even further Will.
It is about half the size now and a lot of unused variables have been removed.
I also re-wrote a few of the variable statements for efficiency and readability.
I removed a whole switch statement also, by integrating its code into the first switch statement.
Hope you won't be mad at me, but now, for me, it has better flow and is readable, I hope you might agree.

With comments, my take on it is that comments are there for you as the coder writer, but also very much to help others understand your code as well.

Right, back to what I should be working on, distractions distractions ..  :)
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on August 02, 2015, 10:27:25 AM
Wow - lots of response to this iteration of the as I call it, UDC - Uno Diversion Controller.

Dgd : Thanks for the positive comments. I am always happy to learn when and where I can. I will search out your system for powering up the Arduinos and implement it as eventually the control will be mounted in a box nicely instead of sitting on a chair bread boarded together. Not cooking my boards has to be a good thing.
       : LCD's - for tuning purposes I put in 2 lcds with many parameters so that I can watch the control work and try to optimize it. I would not think others would likely want or need all this info.
       : I had a version of this control operating with 2 tuning speeds however in the development process it went away. There is an example in the PID library that shows what needs to be done to get two tuning speeds. The control works better with this in place. My tuning for the second speed is Kp =600, Ki=112.5,Kd=.6. Not completely sure of these tunings as when I see it go to fast tuning it settles out so quickly I have a hard time seeing what it did.

Paul: Thank You for reworking the sketch and posting the results. I am not angry but happy. I have learned quite a bit by analyzing what you changed and will continue to ponder the changes. I have not had time to look at the second interation yet. I tried to compile the first one but it would not compile for me but it is not the compiling but the changes that matter. I struggle to understand a lot of the compiler error messages in the IDE.  I have found a free debugger for C that is supposed to be very good - http://visualmicro.codeplex.com/. Have not had the time to even go to that site yet however as time permits will try it out. When I used to do build process simulation models for industry I would build myself a little control panel in order to make it easy to change variables. I can see that by moving setpoint variables into the initialization part of the sketch it makes it easy to make changes without having to find the variables each time in the sketch. Yay.
         : I am eager to put together the hardware for the diversion control you have coded up and try it out. I see that you changed its name. When you are ready so am I. If you let me know what it uses for an lcd then I will order another one if I need to as I want to continue to operate the udc as we develop this more sophisticated pwm pid diversion controller. Thanks

Just for fun here is the 2 pid 2 speed sketch I am working on now. So far it is running well with the understanding that I do not have the lag element physically hooked up to the relay yet. I am biasing the  diversion voltage setpoint of the lag controller ahead of the lead controller to get the lead / lag response to be as it seems it should be.

Is coding an addiction... I am starting to think of so many things that can be done. I am thinking about putting the narcoleptic library in the sketch in order to sleep the controller while the Classic is resting.....


Will
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on August 02, 2015, 11:34:41 AM
Hi Will,

I'm still up and hard at it, and haven't yet replied to your emails yet.
I have the first release for you to take a look at.

The code is fairly intense in relation to the code we have so far been working with, so, strap on a safety harness and parachute as well :)

The archive file attached has a number of files you will need.
It includes the libraries for an updated TimerOne, DDModbusMaster and BasicTerm.

These libraries are in a folder called private_libraries.
Take these library files and place them into your private Arduino library location.

Next is the actual project files, and these comprise the main file and header as well the included files.
From the archive, copy the folder called 'includes' and placed this within your project folder itself.

Finally, copy the two main files, called main.cpp and main.h to your actual project folder.
Rename the main.cpp to main.ino for your Arduino IDE to work with it.

Now, I don't recall exactly, but you need to tell the Arduino IDE to import the three libraries, so it knows about them.
I'm sure you will have already done this before, so I'm hopeful you will be ok there.

Open up the the file called 'modbus_maps.h
You will see in here that all the actual modbus mappings and functions are done.
In this file there is three templates for three different modbus devices, a simulator, the Midnite Classic and the MorningStar TriStar devices.

At line 32 of this file you set the device you are using.
It is currently set to 10 to select the Midnite Classic template, like this;
#define CHARGE_CONTROLLER_TYPE 10

In this file, all the communication parameters are set, such as baud and slave ID.
The slave ID is the Modbus slave ID and is set to 1.
The baud is set to 19200, which I believe is correct for the Classic.

You should be able to compile and run this code in your Arduino Mega.
Full control is set for controlling 2 load elements in a lead lag method.

With lead / lag control, the lead output is always the output that is modulated by PID and PWM.
The lag output will only ever be on or off.

If the lead output gets to greater than around 95% of PID output, then the lag output is switched on.
The lag output remains on while the lead output continues to modulate.
When the lag initially comes on, the lead will need to wind down very fast to maintain the load.
The lag output will stay on while the lead output has its PID output greater than 5%.
Once the lead output PID falls below this value, the lag output turns off.

Now, there many need to be some off delay function on these controls yet, but let's try first with this.

The whole show can be controlled via a terminal that emulates a DEC VT100 or greater.
When you upload the program to the Mega and then operate the terminal application you will see an image like below on your screen.

The settings for the terminal screen are baud of 115200 and 8N1 for data, parity and stop bits.
I selected the faster speed to help things along.
The onboard LED of the Mega will flash for every poll of the charge controller, which is presently set to every 250mSec.

To connect the Mega to your Classic, connect up the RS-232 or EIA-485 to the Mega's serial 1 port.
Serial 0 (zero) is connected to your computer and serial 1 is the next available and is configured to talk to your Classic or TriStar.

Once you have your VT100 terminal application running and can see the screen as below, you are up and running.
At this point, you can enter various commands, which I will list briefly here.
Each command has a 10 second timeout.
Pressing '+' is used for increment of setpoints, and '-' is for decrement of setpoints.
You need to select a setpoint first before you can adjust it.
Press 's' for the diversion controller offset setpoint.
Press 'p' to select the PID P term.
Press 'i' to select the PID I term.
Press 'd' to select the PID D term, though this won't do a lot and is advised to leave at zero.

The PID is a full integer PID loop controller that I programmed up some years back based on fragments of other code.
So, the three terms are all integer.
I have found for best results, the P term to be between 5 and 20.
For the I term, keep it low, between 1 and 10, works well.

On the right side, you will see the two outputs and I have included a basic bar graph to indicate the level of each.
Of course, the lag output will only ever show on or off, but the lead bar graph will grow in proportion to the output value.

You can swap the lead and lag outputs by pressing the 'l' key, that is lower case 'L'.

You will see the Modbus poll counts increment on your screen with every poll of the charge controller.
I had a small problem that I only just found today with the Modbus library and have tried to contact the author about it.
It was polling at full speed, ignoring the configured poll rate.
So, for the past week with my testing, it has been polling and absolutely hammering my poor little Arduino UNO simulator.
But, importantly, not one error was recorded. Not in over a few hundred thousand polls at breakneck speed.
Tonight, I found the the problem and corrected the library to now function as intended, a nice loitering speed of 250mSec.

There is more to write, but my brain is fading at this hour.

Is coding an addiction, you ask, well, what can I say, I think like David, we are mad, totally mad, but enjoy every moment of it.
I still like to get my hands dirty in the garden or go for a nice long ride on my motorbike and tent to get away from it all.

Well, its' 01h:30 here, I'll attach the archive and image and hit the sack :)
_____
Paul

Edit: I forgot to add, the two output PWM pins are pin 11 and pin 12 on the Mega.
These are connected to Timer One output compare capture registers.

Edit2: More. If you are using a Mac or GNU/Linux, then you can simply use the terminal application as part of the operating system, it's all built in.
Go to the terminal app and list the connected devices, by;
ls /dev
Look for the connected USB device and then connect to it this way;
screen /dev/cu.usbmodem621 115200Where cu.usbmodem621 is my connected device, yours will be a different ID.
Works beautifully :)
For Windows, I'll have to research what's available and best, but I did look at those horrid site where you can download windows software, looking for a terminal application.
Maybe some of you folks will know what is a good terminal application to use.
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on August 02, 2015, 08:31:34 PM
It's morning and there is snow outside, first time in 15 years  ;D

For Windows folks, maybe this terminal application is good, Tera Term ?
Or is the name Tera not meaning Earthy, but more along the lines of Terrible or Terrifying ?
http://tera-term.software.informer.com/ (http://tera-term.software.informer.com/)
A link on that page takes me to this site for more information http://external.informer.com/o/ttssh2.sourceforge.jp/index.html.en/AA001290 (http://external.informer.com/o/ttssh2.sourceforge.jp/index.html.en/AA001290)

I'm not sure how or if you can trust those sites or how else to get application software for Microsoft Windows systems.
It brings back bad memories from many many years ago when I did use it.

Ah, looking and searching further I find a better site that talks about Tera Term and gives more background information.
From this page you should be able to get the software and install it to have a quite nice terminal that will work for both serial and SSH modes.
http://logmett.com/index.php?/products/teraterm.html (http://logmett.com/index.php?/products/teraterm.html)

When you first connect to the Arduino Mega that is running the code, it will have already started after you press the reset or upload.
The screen will need to be re-freshed and this can be done by pressing the 'c' key or by again, resetting the Arduino while you are connected via TeraTerm.

There is more work I need to do on the code yet, but this first release should be usable and give results.

Right, it must be coffee time for sure and to see if more snow is coming :)
______
Paul
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on August 03, 2015, 09:09:22 AM
I should mention again that the code I develop, I do in Eclipse IDE, not the Arduino IDE.
And in the Eclipse IDE, I choose to use indentation using tabs, not spaces.
Tabs work fast and allow me to quickly format my code into a very neat appearance.
Spaces need a lot of tapping and I would soon ware out my pinky and space bar, or cursor keys if I did have the tab reinterpreted as spaces.

What does this mean you ask. Well, the code which appears nice and tidy in my development environment will not look so great in another IDE that does not display the tabs correctly.
The Arduino IDE is a real good example of this, and it pains me to see folks struggling with this IDE, even for a short time.

Like Will has mentioned a few posts back, he was unable to successfully compile the code I had massaged.
The Arduino IDE does not highlight potential errors as you type.
It also lacks a wealth of features that really make programming so much easier and to the point of fun.
And yet, they promote the Arduino IDE as a friendly way to get started into programming micro-controllers.
There are many things about the Arduino IDE that are good for beginners, but the things that make it a struggle to use will, for the foreseeable future can only hamper its usability and friendliness.

While I say this, I also don't mean for everyone to jump on the Eclipse wagon, not unless you are really keen or see yourself doing more and more complex coding.
If you do, then I can suggest Eclipse is just pure joy to use.

I guess with my use of it, I see most of my errors while typing the code up.
Also, when I compile the code, it highlights exactly in the code by underlining the erroneous section with red.
This saves me having to wade long lists of text and trying to decipher the compiler messages.
Any error after compilation, I can simply hover my rodent over it and a popup will appear explaining the error of my ways.

Using Eclipse also allows me to write code for Arduino, and any number of other languages all at the same time.
This allows me to quickly flip form one project to another, whether that be between any number of different Arduino projects or javascript or HTML or PHP or Python.

So, returning back to my reason for this post, I had Eclipse print out the code to PDF files.
I have attached the two most important files here, being the main.cpp which handles all the main logic of the project.
The second file is the code that handles all the Modbus part of the project and is an include file, or a sub file to the main file mentioned.

Looking at these files will be far easier on the eyes, unless you have a suitable IDE such as Eclipse to view the code.
_____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on August 03, 2015, 10:29:37 AM
I use Terra Term for some things. The other popular terminal program is Putty but I like Terra Term better.

Larry
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on August 03, 2015, 10:36:14 AM
Great to hear Larry.
I just downloaded Tera Term 4.87 as a Windows exe file from the last site I mentioned.
http://logmett.com/index.php?/download/tera-term-487-freeware.html (http://logmett.com/index.php?/download/tera-term-487-freeware.html)

I might fire up VirtualBox and dust off a very tweaked version of XP I have in there and give it a spin and see what it looks like connected to the Mega running that code.

Will report back, send a search party if I don't return from the depths of VirtualBox :)
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on August 03, 2015, 11:07:11 AM
I can confirm Tera term works well, in fact it is a capable terminal program.
It only took a minute to setup and here is the proof.

The image capture is not good quality, possibly due to the way the screen capture is working with the refresh rate of Windows in VirtualBox, but on my Mac screen, it looks as good as running my native terminal app on the Mac. This is running in VirtualBox with Microsoft Windows XP super tweaked.

The Tera Term program is quick and easy to install, and can suggest it for this use.
____
Paul
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on August 04, 2015, 03:44:14 PM
      I have finished looking at the changes to my code that Paul made and have moved many of them into the latest iteration of the Uno diversion controller (udc). Thanks Paul for taking the time to go over the code and critique it. the code looks nicer now and does not use up so much memory.  I also used # define for the setpoint values of the diversion voltage bias and the diversion frequency selection which now makes them easier to find and use. Much Better.
      I downloaded the REED controller package and started setting it up. Glanced at the code and a lot of it is beyond me at this time however I need to print it out and study it. I am having a hard time getting it to compile due to the PID library not being seen by the IDE. Ran out of time and my brain got tired however I will make it work. I am a Windows based computing person so will have to get my old laptop dusted off and configured to run the REED program. Thanks again Paul. You did lots of thinking and work to create this code.
      My power supply was 5V however what I was doing was accidentally grounding out the barrel plug when I installed it into the board already powered up. The m7 diode definitely did not like this and rebelled. I have ordered some m7s and will try to replace the one on the board that has lost its magic smoke. Thinking the power supply issue through I also ordered a barrel connector splitter and some adapters that give me a screw connection from the barrel jack. This will let me power up the lcd remotely from the board and then turn them off when the Classic rests through use of a transistor. Thanks dgd.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on August 04, 2015, 03:58:06 PM
     Tomorrow I hope to get the wire and fittings I need to change the HWT over to the lead  / lag element format. Should be done on Thursday so on  Friday if it is sunny I should be able to see how it works. Already the udc is heating the tank to SP much sooner than the AUX1 system used to.
     Next I want to get the udc controlling diversion based on WBJr amp flow. It would control diversion based on voltage however if amp flow to the batteries reaches the udc amp limit SP then it would control on amps while the Classic controls the volts. This would let me over array my batteries and run the arrays up to the comfortable maximum for the Classics. If the diversion load should not be available then the udc would write a lower amp limit setpoint to the Classic in order to protect the batteries. I configured the sketch to bring in the WBJr amps and Classic amp limit registers which is working well however when I tried to write to the Classic I was not successful at all - well not very. I think this problem is suitable for the RS232 Modbus to Classic topic so will post a message there.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on October 15, 2015, 02:45:31 PM
Back in business. Following my last post in the" RS 232 to Classic" topic I believe that I have resolved my unreliability issues with the diversion controller and can move forward. Since removing the button and waiting a few months I have had no issues with the sketch.

Question:

For amp diversion control of the Classic it is necessary to write to the Classic amp limit register which I can do now however a concern of mine is that the arduino writes to it each time through the loop as I have the sketch configured. I know eeprom can be written to a finite large number of times but I cannot find out if the Classic registers may be damaged by / prematurely worn out  by a sketch writing to the same register each time through the loop. Is this a valid concern? I am thinking I could configure if / else statements to only write to the register when required if need be.

Will
Title: Re: Arduino based PWM diversion control system
Post by: dgd on October 15, 2015, 04:19:08 PM
Will,

Having a modbus register written to every time the loop() executes is something I also wanted to avoid. To achieve this I simply had a test in the loop to test if the write was wanted and if so then call another function to adjust the modbus configure appropriately then do a few modbus_update calls, test if successful, then readjust the configure to remove the write and exit back to the reading loop.
Seems to work quite well.
The classics modbus registers are not stored in EEPROM, only some values that need to be retained between resets AFAIK.

Dgd
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on October 15, 2015, 06:57:57 PM
Hi Will and David, it is good to hear of your success Will.

Yes, I suspect all this data is not stored in EEPROM, but either battery backed RAM or some other form of non-volatile memory that should not be effected by writes.
The controller also stores its real time data in there, so it really can't be memory that will suffer from over writing.

Yes, as David mentions, with the register write back to the controller, simply hold a copy of the value which can then be used to check on pass of the main loop() to see if it is any different.
You can set a small amount of 'deadband' whereby even if it is ±1 or ±2 counts either side of the register value it will not update.
This will reduce the writes.

This technique is commonly done in industrial control applications, where reducing the amount of data being transferred is sought after to improve system response between PLCs and SCADA systems.

David, I am currently building that 6 stage MOSFET solar charge controller I talked about, err, finally.
As summer approaches, the water flow is reducing and I will need to switch across to solar soon, hence the need for a charge controller.
Nice to get my hands back into electronics and designing and building.

Paul
Title: Re: Arduino based PWM diversion control system
Post by: dgd on October 17, 2015, 06:23:40 PM
Hi Paul,
I would be very interested in how you progress with the controller. I had some fun writing a recursive c++ routine to do a zero current mppt algorithm after figuring out the hill climbing p&o method. All really academic as I'm leaning more toward a brute force pwm controller with perhaps some sort of front end voltage tracker/converter.
Anyway, the arduino due web server progresses with some better report features although it's all mostly client side js code and highcharts graphs, they look just so nice.
Not a lot of interest though from midnite users although I installed servers in all 11 MN sites I support and a couple of local systems I helped set up that liked the iPad version.
Strange thing is I'm getting a fair amount of enquiries about using arduino web server with outback MX60 and FMs, using direct connection to mate port on controller. I managed to borrow an MX60
(From Able Solar in Auckland) so I'm determined to suss out that interface, seems questions have been asked about it on various forums for about 10 years now but nobody appears to have solved it
The boring answer is always to buy the mate and use its rs232 port.

Dgd
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on October 17, 2015, 10:02:32 PM
Yeah  - I don't like having to borrow my friends Outback Mate just to make a few changes to the inverter setting now and then. Some real time monitoring of an Outback inverter would be nice so you will certainly be popular if you ever get the direct connection figured out instead of having to go through a Mate.

I was kind of hoping Midnite would have their inverter on the market soon - but doesn't sound like it will be for a year or two - and in the states here the federal income tax deductions will expire by then.
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on November 28, 2015, 04:29:00 PM
I am finally finding time to get back to developing a  diversion control to maximize PV array output using the Classic and an Arduino.

I configured a thermostat to turn the PID PWM diversion on/off in response to the HWT temperature. The sensor is a conventional 10K thermistor. This thermostat is set lower than the conventional thermostat on the tank which permits very good control of temperature setpoints and on / off differential while having the conventional thermostat function as a High Temperature shut down if needed.

I also got my “button” working reliably for automatically turning the lcd display off automatically after a tunable time period. Yay!!

I am increasing the size of my array to 6.4 Kw STC and adding another Classic to handle the additional power. The system will end up at 2 arrays of 3.2 kw each â€" each with their own Classic. This much power means that the system will be able to exceed the amp maximum for charging the battery bank so I have been working on adding a battery amp limit controller to the diversion control. The long term intention is to divert excess amps to the HWT if the HWT load is available and if the HWT load is not available then the battery amp limiter will limit amps to the battery while permitting full array power to flow to the inverters.

I have attached the working stand alone PID battery amp limiter sketch. Dgd helped me with turning the RS232 write on and off as required â€" Thanks David. The control manipulates the Classic battery current limiter in response to the WBJr amp flow to maintain the amp flow to the battery at or below setpoint while permitting the current to the Classic to also rise to the Classic maximum if inverter load is available. The control works quite well but can be tuned using the PID if need be.

I am very new to arduinoing and programming. A fault with the PID amp limiter control is that when it pushes the WBJr battery amps down by reducing the Classic amp limit the Classic amps from the array will not increase again to a new larger limit setpoint until a “sweep” occurs. This means the Classic “waits” to increase amps until the next sweep. This sweep time interval is adjustable in Mode however I want to be able to force a one time only sweep in certain circumstances in order to overcome this problem. I have not done any bit shifting and I am struggling to get this to work. The control needs to read what looks like the 10th bit in table 4130 ( bit 9?) and then write to the 12th bit in table 4160 (Bit 11?) to force a sweep when the amp limit controller logic calls for a sweep. I have tried a number of sketch configurations to access these bits but I have not been successful so far. I can get values of 0 and 12288(?) however these values do not change when the load limit turns on. Part of my problem with this is that I do not understand how these tables are organized. I suspect each bit can have 2 values. I am guessing value 1 would be 0 or off and then the table hex value when on. I have studied what books I have but so far are making no meaningful progress. I have read the first few pages of the MODBUS Network Spec and I am sure the information I want is there but I do not understand it. I have also attached the read and write sketch (RW) to show how far I have made it with this latest configuration. Any help or suggestions about how to read and write to these registers  will be appreciated.

Thanks

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on November 28, 2015, 04:34:40 PM
Hmmmm......
I think I see how to do multiple attachments now.

Will
Title: Re: Arduino based PWM diversion control system
Post by: Westbranch on November 28, 2015, 05:19:20 PM
what  is a XXXXX.ino file type for?  can't seem to open it...  tks
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on November 28, 2015, 07:44:56 PM
 

.ino files are the designation for program files that the Arduino IDE uses. I am sure many IDEs will open these program files. I have one called Code Blocks that opens .ino files. The Arduino IDE can be downloaded from the following site:

https://www.arduino.cc/en/Main/Software

Will
Title: Re: Arduino based PWM diversion control system
Post by: dgd on November 28, 2015, 08:51:56 PM
Hi Will,

Good stuff, just downloaded your files and had a look at what you are doing. Nice straightforward C++ coding.
I like it  :)

I could not help thinking it would be a neat project to replace those 4 line LCD displays with a couple of web pages being updated via AJAX so an ipad. phone, PC etc, could be used to access and monitor the system via interweb.
It would probably need a Mega 2560 with the 8k ram, or Due with 96k to get the ethernet, metering web pages and SD card for web pages all working.
But you have done the real leg work here.

Nearly completed my MX60 and KID web interfaces, so this looks interesting, might look at web interface over Xmas holiday.

Will post some exampe bit field extraction and posting code soon.
Are you using ide1.6.6?  its more finnicky to get clean code compiles  :o

dgd
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on November 28, 2015, 10:28:27 PM
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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on November 29, 2015, 09:51:33 AM
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
Title: Re: Arduino based PWM diversion control system
Post by: 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
Title: Re: Arduino based PWM diversion control system
Post by: dgd on November 30, 2015, 04:25:24 PM
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;

Title: Re: Arduino based PWM diversion control system
Post by: BobWhite on November 30, 2015, 06:17:24 PM
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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on November 30, 2015, 06:38:40 PM
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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on November 30, 2015, 07:16:14 PM
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
Title: Re: Arduino based PWM diversion control system
Post by: BobWhite on November 30, 2015, 07:27:25 PM
Ill PM ya Walt
Title: Re: Arduino based PWM diversion control system
Post by: BobWhite on November 30, 2015, 07:49:21 PM
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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on December 04, 2015, 09:50:46 AM
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
Title: Re: Arduino based PWM diversion control system
Post by: dgd on December 10, 2015, 09:48:30 PM
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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on December 11, 2015, 11:43:14 AM
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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on December 11, 2015, 04:19:44 PM
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
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on December 11, 2015, 04:33:18 PM
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
Title: Re: Arduino based PWM diversion control system
Post by: AncellCavat on January 19, 2016, 12:40:14 PM
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 (http://www.7pcb.co.uk/SMT-assembly/)
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on January 24, 2016, 10:30:47 AM
Hi Ancell,

I have not used any other boards than the arduino so my experience is limited however I am enjoying coding and physical computing.

My diversion control development has slowed lately due to it being (for me ) a very cloudy winter. I am reluctant to lose Kw developing the control when I need all the power I can get. I have a stand alone PID PWM diversion control configured that diverts excess energy using amps to the batteries as a set point. This needs to be debugged and then operated long enough to gain confidence in it. Then I will add it to the existing control to divert on amps when in bulk. If the diversion load is not available the variable amp limiter will protect the system. Diversion in absorb would be as presently configured.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 20, 2016, 09:12:12 AM

I am gathering what I need to install the power system upgrade. The upgrade requires the addition of another Classic that is now resting in garage together with 6 330w mono panels. One thing I am unsure about is how to wire the two Classics to one arduino. I am guessing that I would just get a RJ11 splitter and length of suitable wire  and plug them both in to the splitter however I am unsure about this. I have a remote MNGP which I would also like connect both the Classics to although I do prefer the arduino based display that I have configured to that shows me what I want to see on one screen.  I use the centre RJ11 connection for my MNGP. Each Classic would have to have a separate address (10,11). I have read somewhere about being able to change which Classic a MNGP will read from. I am guessing that I could just use a splitter for this as well and wire the MNGP to the centre connection on both Classics.

Any help would be appreciated.

I have figured out how to add "pages" to the I2C 4X20 lcd. I think if I was building the diversion control again it would not have 4 lcds...

Will
Title: Re: Arduino based PWM diversion control system
Post by: dgd on February 20, 2016, 05:41:08 PM
Will,

You could wire each Classic into a separate serial port on the Mega or DUE, it has four serial ports.
However, this becomes complicated with the modbus library as you need to constantly rerun the modus configure with a different serial port since the lib is designed to work with only one serial port (usually rs485 with multiple devices on the rs485 bus)

You can daisy chain Classic together via serial ports, look at the online docs for the Midnite SMA Comms adaptor and in there is a nice explanation of how to do this.
You then just have the first Classic at address 10, the second at 11, third at 12 and fourth at 13
In the Arduino code just add additional modbus configures etc for devices on the additional addresses

This works very nice for me in my DUE multiple Classic web reporting system
I suppose with the decent grunt cpu in the DUE (or Cubie or BBB)  and four available serial ports it would be feasible to connect up to 16 Classics to one web reporting system  :P

dgd
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 21, 2016, 04:43:37 PM
Hmmmm....Nothing is easy. Since I have the Classics faceplate MNGP on the upper serial port, the remote MNGP on the centre serial port and the diversion control on the lower serial port I am out of ports and daisy chaining is not in the cards. I am running a mega for the diversion control and so could use a second serial port on the mega for the second Classic. I mostly just want to able to force a float ( if need be ) on the second Classic if it does not go to float in a reasonable time after the first one does or vice versa. If that is all I would do then I could just turn on the second port, force the float and then turn it off again. Once the system goes into operation I will learn if that is needed.

I am thinking if I am not reading from the second Classic but only writing and do not have to worry about data collisions that the splitter idea should work?

modbus_construct(packet8, 10, PRESET_MULTIPLE_REGISTERS, 4159, 1, writeRegsg);

The packet slaved device id would change from 10 to the second Classics id - assume 11 and then the modbus would just write to the second Classic????

Thanks

Will
Title: Re: Arduino based PWM diversion control system
Post by: dgd on February 25, 2016, 06:49:05 AM
Quote from: WillEert on February 21, 2016, 04:43:37 PM
I am thinking if I am not reading from the second Classic but only writing and do not have to worry about data collisions that the splitter idea should work?

rs232 is strictly a point to point electrical interface, you cannot have point to multi-point which is what you are proposing with a splitter
rs485 is multi point and is electrically designed to do that
..but the Classic only has rs232 hardware

Your solution looks to be having each Classic on its own serial port on the Mega.
Then re0run the modbus configure each time you want the modbus state engine to point to a different serial port.

Also just thinking you do have enough serial ports to daisy chain if the chain starts with the new Classic
Mega connects to serial 2 on new Classic, serial 3 on new Classic connects to seriall 3 on old Classic

dgd
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 27, 2016, 03:23:01 PM
Hi David,

Thanks for your reply and sharing your rs232 / 485 bus knowledge. I am hoping that I do not have to force floats with the new system configuration but would like to be ready if need be. I plan to split my array into two arrays and get the new Classic working before adding the additional panels. This should give me the experience to see if the second Classic going into float in a timely fashion is a problem.

I have been watching the diversion control work and have changed the logic in the lag element in order to get more Kw production. The new logic is working well but with the increased output  another problem ? opportunity ? becomes apparent. When the Classic sweeps it momentarily reduces its output. This causes the PID control to also reduce its output. When the sweep is over the PID must now increase its output back to where it was before the sweep. Sometimes this reduces Kw output by 50% every sweep interval. I am thinking if I could predict when a sweep is about to occur and then momentarily "lock" the PID output during the sweep time  that the sweep induced output reduction could be prevented.

Question : I am searching for the sweep countdown timer register which I think must exist. I know that I can set the sweep interval time manually. When I read register 4197 what I get is the sweep interval time setpoint in minutes. If I read 4284 what get is the number 200 which does not seem to change??? I am hoping to find a register or other indication of some kind which would show the time remaining and counting down before the Classic performs a scheduled sweep. I do not find anything on the Network Spec table that seems to be what I am looking for. Any ideas are appreciated.

Thanks

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 28, 2016, 08:52:10 AM
On the other hand I see that the Classic has a built in RTC. Maybe sweep timing is done by noting the time of the last sweet and then adding the sweep time interval onto the the clock time. The sweep would then occur when the clock time matched the sweep target time.

Hmmmm.......

Will
Title: Re: Arduino based PWM diversion control system
Post by: dgd on February 28, 2016, 07:01:42 PM
Quote from: WillEert on February 27, 2016, 03:23:01 PM
.. I am hoping that I do not have to force floats with the new system configuration but would like to be ready if need be. I plan to split my array into two arrays and get the new Classic working before adding the additional panels. This should give me the experience to see if the second Classic going into float in a timely fashion is a problem.

I think you will find that an interesting exercise. In theory, if the voltmeters in the two Classics are closely matched then both should get to float near the same time.
However in practice, I never found this to always be the case
Worst case is one goes to Float and the other which is in Absorb can't by itself maintain the Absorb voltage so drops back in BulkMPPT, probably at the Float voltage setting. Then if suddenly more PV power becomes available it will push battery back towards Absorb voltage.
Now the first Classic in Float will drop its output to Zero and after 30 seconds with FW 2079 will go to Resting.
This gets ugly and could lead to battery overcharging.

Even when both are in Absorb or Float the required current will often reach a point, especially in Float, when one Classic will supply all the power and the other will gradually supply less until its zero.
Then this Classic will go into Resting after 30 seconds.
If the first Classic moves into FloatMPPT as input power reduces then the Resting Classic will awaken but in BulkMPPT mode rather than FloatMPPT mode.
Ugly again
You will probably have to implement a form of follow-me or at least force Float to keep them synced.
The going into Resting from Float then reawakening in BulkMPPT is an issue I have not resolved yet
boB made that zero output going to Resting quite soon change to resolve a problem with the so-called reversing BUT it created another problem when using two or more Classics  ???

Anyway it will be interesting to see how you progress..

Midnite's Follow Me prevents strange things happening with different charge states, problem is it uses up all the serial ports so is of no use here.

Have Fun

dgd
Title: Re: Arduino based PWM diversion control system
Post by: dgd on February 28, 2016, 09:37:44 PM
Will,
I mostly resolved the changing charge states, especially from Absorb to Float by using the 'Absorb Ending Amps' termination that needs the WBjr.
Without the follow me cabling the only way to implement that across several Classics is to monitor the EA from the Classic with WBjr and when EA set point is reached do a force Float to the other Classics, easy enough on the Arduino with modbus lib.
Since my hot water diversion method watches the PV input voltage to Classic then when it exceeds a set point the Arduino starts PWM diversion, it gets to 100% rather promptly when one Classic takes over the Float voltage maintenance leaving the other with zero output and soon going into Resting state.
The PV input voltage on the resting Classic(s) rises towards OCV hence triggering the PWM diversion using an SSR between PV output and Classic input.
I am still surprised how cleanly this works, I just needed to understand my Classics and realise which was the Boss and who were the Sleepers  ???

dgd
Title: Re: Arduino based PWM diversion control system
Post by: dgd on February 29, 2016, 01:17:13 AM
I'm also not sure how the EA sharing over Classics is implemented in Follow-Me, ie if it requires the loopback, although that would seem unlikely as the command to follow-me could only originate with the Classic that has the WBjr.
I haven't experimented with it yet but I was rather hoping (wishful thinking) that the daisy chaining of Classics using serial ports and setting Modbus addresses from 10 through to 13 for four Classics would also allow the EA setting on Classic 10 (first in chain) to be shared to the other Classics, and perhaps battery temperature probe as well.
Does anyone know if this would work? boB? Ryan?

dgd
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on February 29, 2016, 05:35:14 AM
A quick hello to you guys to say I am still about and reading all the posts while lurking in the background.
Currently busy working on another industrial control system for the next few months.
I find it interesting the topics and ideas that are coming up.
Will, you really are getting into things now I see, great to see.

David, I'm keen to get back into my Cubie again soon as part of that long term web based control system I am developing.
Keep the good ideas flowing.

Paul
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 29, 2016, 10:39:34 AM
I am very grateful  to people on this forum who have helped me out with knowledge and suggestions as I continue to develop this Diversion Controller. I know that the control would be working anywhere near as well as it does now with out this help.  In particular Thank You Dgd for all your knowledge and insight of the Classic and communications methods - I know you have taken a lot of time to help me and reply to my questions. I am also very grateful to Paul for all the work on the preliminary controller. Thanks Paul.

I had not considered nor puzzled out the absorb / rest / bulk situation that two controls would find themselves in if there is not some form of Follow Me. There are some things that are better not to learned from your own experience. I not sure cycling the battery charge stages would be "fun"so I think I will do what I can to prevent this form of battery stage "control". This is what I think may work for me. The lead Classic (10)  ends absorb on WbJr amps. The lag Classic(s) (11+) will end on time however the timer is set so that they never get to Float before the day ends and the Classic Rests. When the lead Classic goes to Float then a float is forced on the other Classic. I think this should give good control of the end of charge using the WbJr amps and also permit coordination of the other Classics. I would have to use one of the other serial ports on the mega as Dgd suggests for this to happen. More learning for me regarding serial port configuration.......

Thanks again.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on March 01, 2016, 11:07:55 AM
Looks like register 4284 is the sweep timer I was looking for. It appears to count up until the sweep is toggled. I haven't quite figured out the conversion factor for it yet. Watching it for a while I can see why keeping delays out of the loop is very desirable because it seems like my loop update time may be too long to let this timer be of use.

Will
Title: Re: Arduino based PWM diversion control system
Post by: dgd on March 02, 2016, 03:14:42 AM
Hi Paul,
Good to see you are still watching the Midnite forums.
I have spent a lot of time playing with the Cubie and using a Chinese, from Ebay, max3232 ttl to rs232 serial board, I have libmodbus pulling data from multipe Classics. I just wish there was a bootable disk interface and software as using the SD interface, just like the DUE, is slow slow. With Apache, web page loading is not great but near acceptable, its also nice to use a better (Than Arduino IDE) gcc compiler.
Anyway, I'm getting much more code development time now and I have a couple of spare Classics in a software test bench setup. Just got a couple of 12v 150Ah (C20) SLA and some 30v 250watt PVs, all just for testing.
Also have a couple of Kids, again just for software development, I really want to get an Arduino and RPi web server and modbus interface for the Kid

dgd

PS I enjoyed reading all you Arduino forum postings, you have the patience of a saint in dealing with all those posters asking about SimpleModbus libs and other stuff. You certainly know your stuff  ;)
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on March 15, 2016, 10:53:27 AM
Progress. I have mounted the second Classic ,which is needed for the array upgrade, and powered it up. I have not split my existing array yet and connected the new array to the new Classic yet so all I can do is power it up and play with it.

I continued thinking about the problem of coordinating the charge state of two or more Classics if "follow me" is not available. I do not want to lose control of diversion while transmitting charge state to a second Classic. I changed the second arduino in the diversion control to a Mega from an Uno and got the new Classic (11) talking to the new mega (Mega 2) over serial1. The old Classic (10) is also using serial1 to talk to the old mega (Mega 1). My plan is get the 2 megas exchanging data over another of their serial ports. At present - using a matrix of digital pins I am sending charge state data between the two megas. This will let me force a float on Classic 11 when needed.

I have not seen follow me work so I am unfamiliar with how it really functions. Does it always put the following Classic in the state of the leading Classic? If the lead Classic should come out of Resting and go into Bulk I don't know if it would make sense or do harm to put the following Classic into Bulk at that time if it can't make power. Also just because one Classic goes Resting the other Classic may still be able to produce some power - would it also go Resting? I have looked for more information about what actually happens when "follow me" is in service but so far have not found to much.

I installed the second battery temperature sensor for the second Classic. The two temps read .9C different from each other although they are located within an inch of each other on the same battery. I think coordinating two Classics to work at maximum safely and get diversion happening smoothly may be more interesting? challenging? than I thought. Of interest also is that the two Classics sense the battery voltage .8 different from each other also but possibly that will change when Classic2 produces power or I can tweak that.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert 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
Title: Re: Arduino based PWM diversion control system
Post by: NariParish 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 (http://www.7pcb.com/HDI-PCB.php)
Title: Re: Arduino based PWM diversion control system
Post by: WillEert 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
Title: Re: Arduino based PWM diversion control system
Post by: Westbranch 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....
Title: Re: Arduino based PWM diversion control system
Post by: WillEert 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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert 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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert 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
Title: Re: Arduino based PWM diversion control system
Post by: Westbranch on August 21, 2016, 09:18:14 PM
Will, what program makes .INO files?
Title: Re: Arduino based PWM diversion control system
Post by: paul alting 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
Title: Re: Arduino based PWM diversion control system
Post by: Westbranch on August 21, 2016, 09:43:29 PM
Thanks Paul  :)
Title: Re: Arduino based PWM diversion control system
Post by: WillEert 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
Title: Re: Arduino based PWM diversion control system
Post by: paul alting 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
Title: Re: Arduino based PWM diversion control system
Post by: dgd on November 05, 2016, 01:52:06 AM
Quote from: WillEert on November 04, 2016, 08:36:32 PM
..... 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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert 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
Title: Re: Arduino based PWM diversion control system
Post by: WillEert 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
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on November 15, 2016, 10:24:00 PM
Interesting panel structure - you get use under it .
But with the panels so steep - what do you do in the summer ? Just get a lot less power or is there a way to tilt them ?

Larry
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on November 16, 2016, 11:05:58 AM
Hi Larry,

This building is a combination wood storage / array mount structure. I needed a firewood storage building as I have been storing my firewood under  a tarp in the winter to keep the snow off it. Digging wood out from under a snow covered tarp in a Manitoba winter has needed to be done but is not always pleasant. The new arrays primary purpose is to give enough power to enable us to do a meaningful amount of heating in the winter. The tilt angle of the new array is designed to maximize output in Nov and Jan. The first array is tilted to maximize output in Dec. My logic is that if I have enough power in the winter then I will have enough power in the summer. This tilt angle also sheds snow very well. With the added day-length in the summer  the difference in power output is not that great - about 20% or so. We also use much less lighting in the summer due to the added day-length. We are not big fans of LCD lighting and use good old incandescent light bulbs. The heat the incandescents create in the winter is good for us and we use them very little in the summer.

So I built a structure to to store wood and act as an array mount in the hopes the added power would mean that I would not have to burn wood.....

Cheers

Will
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on November 16, 2016, 01:53:57 PM
Okay - makes sense to me Will . Except for not finding any types of LED lights that are suitable ?

I have quite a collection of different types of LED bulbs and LED strip lights. They certainly are not all equal in the quality of their light. Some are very good and bet you would be hard pressed to find difference between incandescent.

But if you are electric heating anyway then those incandescent are perfect
!

Larry
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 02:56:34 PM
I have been running my system with two arrays for a few months now. I thought I would post a few photos of it's operation. The two arrays are 4.4 and 4.9 kw for a total of 9.3 kw stc.

This first photo shows the system. The two Classics are 150s. I divert excess power to my hot water tank using AC and a Crydom Evolution Dual relay. The inverter on the right is the diversion inverter. The center and left inverters are the load inverters. The diversion inverter is also the charging inverter. I can supply full load with my load inverters while charging. The logic is - If I need to charge then I do not have enough power to divert. This system lets me use a small generator that runs at an economical speed while also supplying all my loads. The hot water tank has 2 2kw elements in it. They can operate simultaneously. The diversion control first maximizes out the lower element and then turns on and maximizes the upper element (Paul - Thank You for this idea).

The diversion control diverts if the amperage coming in to the batteries, measured by the WBJr, exceeds setpoint (presently 65A) and also diverts if the voltage exceeds the divert voltage setpoint (presently .3 V below the Classic setpoint) when in Absorb, Float or Float Mppt. Amperage diversion at this time is done using the upper element in the tank. Voltage diversion starts with the lower element in the tank. All diversion setpoints change when the Classic setpoints are changed. The control reads the Classic and then adjusts the diversion control setpoints. The control also dynamically limits the amps flowing to the batteries, once again measured by the WBJr. This presently set at 70A. There are 2 megas in the diversion control. The first operates the 4 PID controls (Amp diversion, Amp limiting,Voltage diversion 1 and Voltage diversion 2) and displays on the two left hand and upper right hand 4X20 LCDs. It interfaces with the left hand Classic 150 (#10). The second mega interfaces with the right hand Classic 150 (#11). It also has the thermostat function and the does addition of KW and W from both arrays. It runs the lower right hand LCD. Both Arduinos read and write to each other using a serial without blocking system. It is not lightning fast but works well.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 03:06:00 PM
This photo of the diversion control shows the system when it is resting at the start of the day. All PIDs are turned off. The Thermostat shows "OFF" which means it is not active. I use Dgds method of switching the relay control voltage on or off to control the relay and therefore power to the HWT (Thanks David). If it says "ON" then the relay will not turn on and power will not flow to the elements. Upper and Lower are the two elements. C=00 is a counter I put in to watch the load limiter.

W
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 03:27:05 PM
This next photo shows the system in Bulk. Amps flowing to the batteries (23.4) are less than setpoint. This seen on the upper right lcd to the right of JR SP. Total amps coming in are TAmps 30.5. Amps from each Classic are 13 and 17.5. The Classic limit (CL SP) is set at 75A. The actual amp limit setpoint(ClLmt) is 75A.

The lower right LCD is displaying the charge mode the individual W and KW from each Classic. It also totalling the W and KW. The HWT temperature and setpoint can be seen.

The amp diversion is turned on (AOn). This means it will  divert when required. Amps to the batteries are below setpoint so the % diversion is 0.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 03:32:11 PM
This next photo shows the diversion control actually doing something!!!!!

Incoming amps are 80.2. The amp diversion is at 31%, diverting .63 of a KW to the HWT. WBJr Amps are being controlled at 65.2 with a diversion setpoint of 65.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 05:19:00 PM
The solar day continues. I only have the amp diversion coded to work on the upper of the tank elements at this time. This means that after that element is at maximum (2KW) the amps will continue to rise.

This photo shows the the upper amp diversion element at 100%, diverting 2 KW to the HWT. The amp limiter has turned on and is at 21.4%, writing a setpoint of 58A to the two Classics. The Classics are controlling at 59.2A and 59.6A. The code smooths the WBJr amp flow reading which makes it hard to tune the PIDs for the amp controls. Total amps is 118.8A with 71.6A going to the batteries (SP = 70A).

Attached is also a photo of the Classics when load limiting.

The system is doing 6783W instantaneously  and has produced 4.6KW for the day.
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 05:25:03 PM
Well we have made it to absorb voltage.

Voltage diversion has started on the lower element. Amp diversion is still taking place on the upper element however the amp limiter has shut down.The amp limiter set point ramps up to the Classic Limit setpoint (75A) before breaking the connection and shutting down. It took me a long time to get this to work as I wanted it.
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 05:29:10 PM
More absorb.

As the batteries charge and will no longer take in excess of the amp diversion set point the amp diversion turns off. The diversion is now taking place on voltage control only. This photo shows the lower element at 97% diverting 1.94 KW to the HWT.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 05:35:48 PM
More absorb

As the batteries charge and the day progresses more KW become available for diversion. In this photo the lower element is at 100% and the upper at 82.7%.  KW to the tank are 3.66. Note that when the upper element is on more than 5%  the code lowers the lower element setpoint by 1 Volt. This ensures that only the upper element PWMs and "locks" the lower element at max. This setpoint change reverses when the upper element turns off.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 05:45:45 PM
Float

Life is good. KW to tank at max - 4KW. System running at 6088W with 24KW produced. Batteries full. Since I use some of the RJ12/11 jacks on the Classic for the diversion control I cannot use the Midnite system of "follow me". Dgd offered good advice on how and when to handle forcing floats. The system finds its own way around resting to bulk to absorb. Classic 11 is set for an impossibly long absorb time - it will never end. When Classic 10 floats then Classic 11 has float forced and both the Classics are now floating. The system then finds its own way around float, float mppt and to resting. This has been working without any problems once I got the code to work.
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 05:57:30 PM
Resting at the end of the day.

All PID turned off. 39.2 KW for the day. Yay.

Will
Title: Re: Arduino based PWM diversion control system
Post by: Westbranch on February 25, 2017, 06:01:11 PM
Will, last pic before reset,  that DHW is at 153*F ? Isn't that too hot for DHW? do you  use a mixer? Or is is going into another tank first?
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 06:18:44 PM
I am happy with how the diversion control is working and how this project is turning out. I could not run my house without it making hot water which we use for domestic hot water and radiant floor heating. I think likely a device you can code yourself is never done. Without Dgds orginal code and the help from Paul and David I don't think I would have made it too far.

I have more power available from the arrays and will be installing another 2KW element in the HWT tank. My diversion inverter is maxed out so I plan to use on/off control for this element, feeding it from the load inverters. When it turns on the PWM elements will cut back and then pick up more load as they are able. Also I want to get the Amp diversion working on the lower element. It bothers me to be limiting power when I could be diverting it. Amp diversion may not work every day or work for too long but it is KW that can be produced. Also it you look closely at the photos you can see that the arrays do not always pick up the load when they could. The diversion setpoint is .3 Volt below the Classic charge setpoints. I want to widen this out to .4 or .5 volts to see if that gets me more production. This does mean however that when the thermostat opens my batteries will now be charging above the desired setpoint. I am thinking code can be added to write  lower absorb and float setpoints to the Classics when the thermostat is open and then change the setpoints back when it closes.

Code for the two arduinos attached. Amp_Div_5b etc has the pids. It should function as a black box with one Classic if desired however the thermostat function would not work as that issent from the DCT_2.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 06:28:17 PM
Hi Westbranch,

My heating system kicks in at 155F. It runs until the tank, sensed at the middle of the tank, gets to 150F and then shuts down. I have a mixer on the domestic hot water set for 118F and a mixer on the floor set for 90F. The HWT tank cycles between 155F and 150F if there is enough energy to get there and leaves me with a supply of hot water that should last me a few days if there is not enough sun make hot water. So the PV solar energy transfers through the tank, into the 60 tonnes of radiant floor.

Will
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on February 25, 2017, 07:12:47 PM
How many gallons is your hot water tank -  or do you also have another hot water storage tank that you also heat ?

That is some great work you have done . I have just started playing around with my arduino's and will have a look at your code later to see if I can figure it out.

What type of sensor are you using for hot water temperature ?

Larry
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 08:29:09 PM
My HWT is 120 USgal. It is made of 316L stainless by a company called Advance MetalPres. http://metalpres.ca/ I went with this tank because of the high temperatures I want run it at. I also bought the Corro-Protec non-sacrificial anode for it. The tank has two heat exchangers in it. The floor goes through the upper one, cooling the tank when the heating system runs. The lower one I do not use but if I get old and do not want to do wood any more I could heat the tank with a propane condensing boiler or something. The entire house would run fully automatically then. Our goal is to reduce our carbon footprint as much as possible however. 120 gal of water at 150F will go a long way when it is  mixed down to 118F.

The sensor is a conventional 10K thermistor. They originally came from Heliodyne and then I got some from AltE before they got out of thermal. The tank has 3 thermo wells located near the bottom, the middle and near the top. The middle sensor location controls the system very well. I installed another sensor at the middle position. I just shoved it under the foam insulation which holds it closely to the tank. It works just as well as the thermo wells. I've been working on an Arduino data logger for the heating system but that is slow going.

Will
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on February 25, 2017, 09:38:00 PM
Thanks for the info Will
I have been playing around with one wire DS18B20 temperature sensors. I guess one advantage to those is you can run a bunch of them on one line and since they have individual addresses you can assign them to whatever you want.

The other new device I have been playing around with is the ESP8266 - specifically the Wemos Mini variation board of it. They only cost $5 or less and have wifi built in . For experimenting now I have three one wire sensors and a DHT 11 temp / humidity sensor on it . The thing is so simple - you just hook up the sensors and then you can connect  up to its built in webpage and see the data. I am still learning on that but it has a lot of potential since it can do some controlling too.

Your have engineered a very well thought out home heating system at  your house. Nice to hear you are now reaping the rewards of all your hard work at learning how to code all that .

Larry WT9M
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 25, 2017, 10:12:49 PM
Hi Larry,

I had no luck with the DS18B20 sensors. I liked the idea of them. I could get meaningful readings from them but once in a while they would suddenly read high and then go back to a correct reading. Weird. They would work at short distances but I need to go from the power room to the HWT which is about 25'.  I tried various wires and resistors and code. Finally I just moved on. I have do have a lovely collection of them which I look at sometimes.

Will
Title: Re: Arduino based PWM diversion control system
Post by: mike90045 on February 25, 2017, 10:45:46 PM
What happens if you don't consume enough hot water and the tank tops out at boiling ?    Say if you are gone for a couple days ???
Title: Re: Arduino based PWM diversion control system
Post by: dgd on February 26, 2017, 03:10:01 AM
Will,
Thanks for your updates on your water heating project. I enjoyed reading your posts, technical stuff, makes a change from the general newbie questions that have been the majority of forum postings the last few months.
Those one wire temperature sensors, I found a high running rubbish reporting rate if the cables from computer to sensor was more than a half metre or so. I had four of these on or about my tank and tempering valve so I installed a remote $3 arduino mini cpu that reads temp data (and flow meter data) and rs232 serial connected 12 metres to the main web server Due.
dgd
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 26, 2017, 07:49:06 AM
Hi Mike,

The second Arduino (Classic11) has a thermostat function coded into it. You can see the HWT temperature on the top line of the lower right LCD. The setpoint of the thermostat is 157F. So if the heating system is not running (summer) or something goes wrong at 157F the thermostat function activates. It sends a signal to to the Classic10 Arduino. The Classic 10 Arduino turns the PID off and stops diversion into the tank. The Classics then function as normal, controlling their output to the battery and system load. The thermostat turns diversion on again at 152F. If all goes wrong each element has a conventional thermostat, located at the tank, that will turn them off at 180F.

Will
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 26, 2017, 08:03:48 AM
Hi Dgd,

I have two Grundfos VFS flowmeters in my system. These measure temperature as well. One for the floor and one for the HWT. The goal is whole house energy data logging. I want to be able to calculate how much energy the wood stove puts into the tank and how much the floor gets. Getting the Grundfos to work is giving me fits. I had them working with a breadboard but when I soldered it up they stopped working. I had made notes of the circuit but when I went back to a breadboard they did not work anymore. Auurrgghh.. I also went to a 16 bit adc for better resolution. It seemed to work well and was easy to configure. This is a long term project, not because I want it be but because it is. ::)

Will
Title: Re: Arduino based PWM diversion control system
Post by: TomW on February 26, 2017, 10:22:12 AM
Quote from: WillEert on February 25, 2017, 10:12:49 PM
Hi Larry,

I had no luck with the DS18B20 sensors. I liked the idea of them. I could get meaningful readings from them but once in a while they would suddenly read high and then go back to a correct reading. Weird. They would work at short distances but I need to go from the power room to the HWT which is about 25'. 

Will

Yeah , I have to massage my logs to eliminate "flyers" in the data like 69,70,69, 180 degrees. Its annoying but I still use them for general monitoring but would not trust them for "mission critical" uses because of those occasional wide swings in accuracy. Of the dozen or so I have in use they have all been pretty solid as far as durability is concerned. I got a bunch of them for like 50 cents a piece on Feebay some years back quite a deal so I  am using them until I get annoyed enough to get replacements or they fail. Or we need something better.

For environmental use I have been playing with "La Crosse" remote wireless sensors and RTL-SDR dongles to sniff the RF the broadcast. Even cheap ones give good, reliable data once you dial in the data stream. this unit includes humidity.

Using rtl_433 to grab the stream from a LaCrosse TX141TH-Bv2 sensor using the rtl-sdr dongle on a Raspberry PI 3 B.



2017-02-26 09:13:29
        Temperature in deg F:    34.34 F
        Humidity:        57 %
        Sensor ID:       9d
:       LaCrosse TX141TH-Bv2 sensor
        Battery:         OK
        Test?:   No
2017-02-26 09:14:19
        Temperature in deg F:    34.34 F
        Humidity:        57 %
        Sensor ID:       9d
:       LaCrosse TX141TH-Bv2 sensor
        Battery:         OK
        Test?:   No



I like no cables as this solid masonry house is hard to run cable discretely from my "control center" in the dungeon. Err man cave.  ;)


Just some other ways to grab temperature.

All good fun!

Tom
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on February 26, 2017, 11:46:45 AM
 Will
To calculate the amount of energy going into water you will need flow rate - if I remember the formula correctly BTUH = DeltaT x 500 x gpm. The temperature differential  are easy to get but that flow rate is the tough one . Hope you can get the data from those flow meters. 

Regarding one wire ds18b20 false temps - these guys seem to have solved the problem with a CRC check in their code
https://community.particle.io/t/ds18b20-dallas-temperature-readings-jumping-high-at-random-intervals/15555/33

Tom - I was just at the La Crosse Technology Factory outlet store in La Crosse the other day. Didn't buy any sensors this time though. I have 3 or 4  of their wireless temp displays hanging up on the wall here - got them at garage sales for a dollar or two - ha ha . They are all usually within 2 degrees or so of each other. Also have the full fledged weather station that I got there last year for $50 - works great interfaced with linux weewx program running on raspberry pi . If I have all the ports open you can see the data here on pi weewx webpage.
http://207.190.123.229/weewx/

Larry

Title: Re: Arduino based PWM diversion control system
Post by: WillEert on February 27, 2017, 09:30:19 AM
Hi Larry,

Thanks for the link for DS18B20 CRC code. It did not occur to me to try a code solution to the bad data problem.

One thing I am learning about coding is the concept of using code to reach a goal rather than hardware. When I was adding the amp diversion PID to the diversion control I initially thought of running another control wire to the another relay. This would then go to another element in the tank. Then I thought - Why not use the existing element and relay channel and with code change the output pin to the two control wires. From there I got to - Use all the existing hardware and just change which PID sends a signal to the Arduino relay output pin. It took a bit of trial and error with the PWM timer configuration but it works. No hardware or crawling around in my attic pulling wires or buying relays and elements. Much better and also less costly.  :)

Will
Title: Re: Arduino based PWM diversion control system
Post by: TomW on February 27, 2017, 10:51:17 AM
Larry;

Thanks for the CRC info.

Might get to use it when I task one of the Pi3's with watching temps. Most of mine are currently in use on CAI Webcontrol boards and as far as I know there is no way to check CRC on them they just dump the data to their web interface. 

So many "minicomputers" here I can't keep track due to being afflicted with  CRS (Can't Remember Shtuff).

Anyway, nice to know its not just me with the issue.

Appreciate the share.

Tom
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on July 09, 2017, 12:30:54 PM
I am starting to code the changes needed to charge the Chevrolet Bolt that we brought home last week I bought an opensource Electric Vehicle Supply Equipment (EVSE) from OpenEVSE to charge the car with level 2 charging (240V). I have been charging the car with the level 1 charger (12A 120Vac) EVSE that comes with it. This is quite slow. The goal is to integrate the car into the existing diversion control.

The car has the charger built into it. In can take a maximum of 32A of 240Vac current. The EVSE writes the charge rate to the car and makes sure that all is safe. Minimum charge rate is 6A @ 240 V.

The OpenEVSE communicates by TTL and I should be able to read / write to it with the Arduino. It will turn on, turn off and can adjust the charge rate in 1 amp increments. Actually it will do more thatn this but this is what I need it to do. I think it is what is required for the system.

So somehow I have to determine when I have energy available for the car. #1 I need to take care of my house battery requirements. #2 I need to make hot water. #2 1/2 I need to charge the car and #3 I need to heat the house. Sometimes I may need to charge the car more than I need hot water. I can always burn wood to heat the house but that was really the idea. Hmmmmm....so I need a load priority system and maybe more panels.

Also my HWT diversion inverter is maxed out so I plan to charge the car using my house load inverters. I have 8.8 Kw of capacity there. So I need to configure loadshedding so that if the car is @ 6KW and the stove turns on and then the well pump I am way over my inverter capacity and would need to drop load quickly.

Fun.

Will

Title: Re: Arduino based PWM diversion control system
Post by: WillEert on July 20, 2017, 09:41:25 AM
My OpenEVSE charger has appeared. I bought the kit and have assembled it. I had to rewire part of the Power room to get it power but it is now plugged in to a 40A 240V circuit. The Bolt charger takes a maximum of 32A 240V. I have been able to write charge limits to it and also turn it off "sleep" and turn it on with the Arduino. This code has been integrated into the diversion control Classic 11 Mega. The car charger is physically located about 24' of wire from the diversion control and the 5Vdc TTL serial seems to reliably writing to the EVSE over this distance using Cat5. I have configured some preliminary logic to turn it on and off which will test today.


On
if (hot water tank >=140 && SOC >= 90% && Total incoming watts >= 2000) - turn on at 6A (1440W).

Off
if (charger is turned on && Total incoming watts <= 1500) - go to sleep.

When I get this working then I need to confgure a means of increasing and decreasing the charge rate while continuing to charge the batteries and make hot water. I configured a calculation that determines aproximately how much load the Magnum inverters have on them. This is working well and will be used for charger load limiting and load shedding if need be.

Last night when we turned our power off it turns out, even though the EVSE was sleeping, that the Bolt could detect the power loss. Although I have the charge interrupt "beeper" turned off in the Bolt the Bolt also has a power loss beeper. Quite a surprize. Chevy did not stint on the beeper decibals when they installed the noise making device.  How annoying. This one I found and turned off quite quickly using the Bolt Power options menu.

It also turns out that when the OpenEVSE is powered down in sleep mode when it powers back up it defaults to charger "ON'. This means if you leave the charger attached to your car (as I want to) that when you turn your power first thing in the morning the car charger now starts to drain your batteries with glee - not good.  I put a few lines of code in the Arduino SetUp to sleep the EVSE as the arduino reboots which looks like is working.
 
Fun. The new OpenEVSE level 2 charger is able to charge the car much more quickly than the Chev supplied Level 1 charger which is good. It also does both Level 1 and 2, each of which has adjustable amp settings. I am thinking I will get another one and a box of receptacle adapters and throw it in the trunk to take with me where I go. As my wife says - It is not like we can hitch hike to a generating plant and get can of electrons if we run out.

My gas bills are much less now for some reason????????

Will

Title: Re: Arduino based PWM diversion control system
Post by: WillEert on July 26, 2017, 08:47:39 PM
I have the car charger working withe the diversion control. You could not do this without the ability of reading and writing from the Classic and getting the WBJr data. The OpenEVSE system uses a command system called RAPI. Here is link to the RAPI code.

https://github.com/OpenEVSE/open_evse/blob/stable/rapi_proc.h

The charger sleeps at night and in the morning, when there is energy available for charging turns itself on at the minimum charge rate. As more energy becomes available for the car it increments the charge rate up and then as less is available decrements the charge rate down.
I am going to lower the baud rate as I have had one instance of a garbled LCD screen that appears to be a baud symtom. Also I would like to read from the EVSE so it feeds back to the diversion control. I have ordered a spare controller unit so I can play with it on the bench.

Attached is the charger code. It is stand alone code that is not integrated with the diversion control to make it easier to understand. The code is a form of energy management system as it chooses wheer to put excess energy not required by the batteries. It is well commented.

Will
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on July 26, 2017, 10:27:15 PM
That is some cool stuff Will ! You get stuff done .
Now all I need is an EV - ha ha .  I am looking forward to drive via sun.

Larry
Title: Re: Arduino based PWM diversion control system
Post by: BenNelson on November 14, 2017, 09:44:14 AM
Hi Will,

Thank you SO MUCH for working on this! (Along with everyone who HELPED Will work on this!)
I just got HOME POWER issue 182 yesterday. The best part of the whole magazine was your letter describing this system! (I came to this web page from the link in the article.)

I've just started working with Arduino and also recently discovered the fact that the control signal from EVSEs is variable without causing an EV to error out. Pretty much the only EVSE I've found that lets you easily modify the output current is the OpenEVSE. (On most EVSEs, the signal is set by the physical circuitry inside the box - usually just a particular resistor!)

I've also been interested in learning more about Whole Home Energy Monitoring systems and starting learning a bit from the Open Energy Monitor web page. (https://openenergymonitor.org (https://openenergymonitor.org))On there, there's at least one person who used the monitoring system to then control the output of the OpenEVSE. When I'm done, I'd like to have an energy monitoring system which generally directs whatever EXTRA solar I have to my electric car. I happen to be on a grid-tie system, but it's not always advantageous to "sell" the power back to the utility.

Thank you for your write-up in HOME POWER. It had enough detail for people to really understand what you are doing, without getting bogged-down in technical details.

I'm glad to see that there are other people out there experimenting and taking a lead in how we can best make, direct, and use electrical energy.
Title: Re: Arduino based PWM diversion control system
Post by: mtdoc on November 15, 2017, 02:11:21 PM
Hey Will,

I'm very interested in your OpenEVSE diversion project as well. We have a Chevy Volt and just added a Chrysler Pacifica PHEV. I have an OpenEVSE kit ready to assemble and am planning installation of a second large PV system this summer (hopefully using the new Midnite inverter!).   Ultimately would love to develop a smart diversion system to manage EV charging.

Your project looks great.  But you GitHub link appears to be broken.. :(.   Any updates appreciated.

Thanks!
Title: Re: Arduino based PWM diversion control system
Post by: paul alting on November 15, 2017, 06:10:14 PM
The link to OpenEVSE above from Will is not quite correct as it was pointing to a file that no longer is at that location.

The GitHub repo is okay though and the correct link should be as follows:
https://github.com/OpenEVSE/open_evse (https://github.com/OpenEVSE/open_evse)
This links to be base repo for OpenEVSE and from there you can access the files and code for Arduino.

OpenEVSE GitHub site is a collaborative of a number of people and you can also see more at their official site:
http://www.openevse.com/ (http://www.openevse.com/)

For RAPI code, there are two locations for two different codes, and are as follows:
From OpenEVSE GitHub: https://github.com/OpenEVSE/open_evse/tree/stable/utils/rapi_checksum (https://github.com/OpenEVSE/open_evse/tree/stable/utils/rapi_checksum)

From lincomatic GitHub : https://github.com/lincomatic/open_evse (https://github.com/lincomatic/open_evse)

Where you will find the actual files for rapi_proc Arduino code.
https://github.com/lincomatic/open_evse/blob/stable/rapi_proc.cpp (https://github.com/lincomatic/open_evse/blob/stable/rapi_proc.cpp)
https://github.com/lincomatic/open_evse/blob/stable/rapi_proc.h (https://github.com/lincomatic/open_evse/blob/stable/rapi_proc.h)

Sam Lin aka GitHub member Lincomatic is a contributor to OpenEVSE.

Hope that clears things up for people  :)

Will, sounds like you have been making great strides in developing your system and wonder if there is a link to the article mentioned in 'Home Power' ?
Also, it would be good to see a schematic of your connection or wiring layout if you have.
_____________
Paul - VK7KPA
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on November 15, 2017, 08:34:47 PM
Will's article in Home Power magazine issue 182  is on page 21 in the Mailbox letters from readers section. I just looked on Home Power website and they don't let people download articles without subscription though sometimes they will post some articles on their web page.  His six paragraph letter probably doesn't have any other info than is already on this forum topic  , though it is a good concise summary of his project. Maybe when Will gets on he can post his letter on here.

Larry 
Title: Re: Arduino based PWM diversion control system
Post by: boB on November 16, 2017, 07:40:32 PM

Great article letter Will !

boB
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on November 19, 2017, 09:10:27 PM
Thanks for the comments on the letter to Home Power. I am pleased they printed it however I have not read it as I get a "solid" copy in the mail, which has not yet arrived. I attach the two sketchs I am running in the diversion control at this time. I have not made any changes fo a couple of months now and the control is working very well. I get most of the power available to the array. Excess power, not needed by the batteries is sent to the HWT. The control limits KW to the HWT and sends excess to the EVSE.

The EVSE is on the CLSC 11 sketch however it gets input from the CLSC 10 for some data. The control is two arduino Megas that communicate by TTL serial with each other. Each Mega also uses one port for uploading and the serial display. Each Mega also uses one port to read and write to their attached Classic 150 using RS232. CLSC 11 uses it's last port to do TTL serial with the openEVSE for car charging.

There are not enough Classic 150 ports left for "follow me" so Classic 11 follows Classic 10, using Arduino code, when Classic 10 floats. Both Classics have exactly the same Absorb and Float setpoints as the system seems to work best when it is set up that way.

Classic 10 is doing the diversion into the domestic hot water tank. It needs to be fast as it is PWMing the SSR. It gets a thermostat signal from Classic 11 if the HWT gets to setpoint (which it does in the summer or if the heating system is S/D). It stops PWM to control the tank temperature.  It also calculates a setpoint for use by the EVSE, to increase or decrease the car charge rate, when the thermostat is active and no power is flowing to the HWT. In addition Classic 10 calculates the Magnum inverter load for use by the EVSE load shedding function. There is an amp limiting function which prevents excess amp flow to the batteries. ClSC 10 calculates this and both Classics are controlled simultaneously with this function. Amp limit control is quite convoluted. The WBJr is invaluable.

CLSC 11 follows behind CLSC. It forces float and does amp limit control as required. It senses the DHWT temperature and sends the thermostat signal to CLSC10 when required. It has the EVSE control in it.

I have put the pinouts in each sketch. The sketches are well commented - in particular CLSC 11 as it was developed later. I have had experience now attempting to follow other coders programs and it can be difficult to try to understand what the person is doing sometimes, let alone how they are doing it.

I am happy, with in the boundaries of my time, to help out anyone who is attempting to get the OpenEVSE charger or a diversion system working. David (DGD) and Paul (Alting) both gave me invaluable time and help as I developed this sytem and learned coding which I am grateful for.

Will
Title: Re: Arduino based PWM diversion control system
Post by: mtdoc on November 28, 2017, 12:36:09 AM
Thanks for the additional info Will.

I'm going to revisit this once I get my new system installed - hopefully this coming summer.
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on March 15, 2018, 11:18:45 AM
I have managed to get the arduino reading from the OpenEVSE to the control. Here is a stand alone sketch showing the method I am using to read the charge state of the car into the control.

Will
Title: Re: Arduino based PWM diversion control system
Post by: dgd on March 16, 2018, 12:59:26 AM
..interesting, I will be trying this, thanks for your perseverence with this project
Dgd
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on May 05, 2018, 04:49:58 PM
I don't really think this applicable to anything Classic or Arduino but it is a form of humor.

We were coming home the other day in the Bolt and had 25%SOC and showing about 90 Km range remaining on what is affectionately known as the guess-o-meter. Suddenly I received the warning - Low Propulsion Power Speed Reduced (or words to this effect). The Bolt slowed to about 50 Km/hr and I thought - gee - seems very early to run out of power with 25% and 90 Km showing. Within seconds the SOC  "bars" went from a very restful Green color to orange and black and stated to disappear. Within 1 Km we were by the side of the road with no power or range showing - dead in the water. We do not subscribe to OnStar nor do we have a cell phone ( no service where we are). Walking is healthy and sometimes the only option. After accessing a phone a neighbor got us home and I loaded my generator in ICE car.

At first the Bolt did not like the generator electrical quality but after I sped it up we met its parameters and it started charging. You can meet a lot of nice people in rural Manitoba who see the gas can (for the generator) beside your car and stop to help. Upon seeing an electric car they do not know if they should just laugh or drive away quickly pondering their near escape.

Turns out (most likely) that the Bolt is similar to other SOC systems in that they need to get completely full periodically to reset and know what the SOC actually is. Charging using an offgrid system and not worrying about a lithium battery bank needing to get completely full it seems I confused the Bolt system by going too long without giving it a "full" charge. Something the EV designers, I am sure, did not anticipate. Oh to be a square peg in a world of round holes.

Is the future of tow trucks to have a large battery bank on board and a very nice quick charger available to help out with this kind of problem?

Bolt booked for a diagnostic this week to ensure we do not have a low cell group problem. Most unlikely but a remote possibility.

Will
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on May 05, 2018, 10:55:53 PM
Do they do firmware updates for the Bolt ? So if they discovered problem with SOC and fixed it - can you as a consumer load it in ? Or does the deal have to do it ? And wonder if they would give a detail of things they fixed or just say the generic  updates.

Larry
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on May 06, 2018, 09:06:51 AM
They do firmware updates for the Bolt. It appears with the SOC that they are increasing the definition of the battery voltage measurement. From what they said it sounds to me like increasing the # of bits in the ADC. Also they are doing a radio upgrade. At this time you cannot turn the radio off!! You can mute it but not turn it off. In an all electric car this has to wondered at. You cannot do the firmware upgrades yourself. They are called a recall and done by the dealer at no cost.

The Bolt uses Canbus and using an Arduino with a suitable reader ODP reader all battery data can be obtained by a person who is not afraid to learn.

Here is link to good article on Bolt battery packs.

https://electricrevs.com/2018/04/02/new-details-emerge-as-a-few-bolt-ev-packs-continue-to-fail/

Will
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on May 06, 2018, 01:58:00 PM
You can't turn the radio off ? That is so odd ! Be fun to put a switch on the power lead to it , shut it off , and see if the whole car shuts down - ha ha !

I just looked at that article and looks like they are using onstar to send data up to the mothership all the time - so that radio must be part of the onstar system and they want the data from you !

Larry
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on May 07, 2018, 08:44:26 AM
The only thing about OnStar is if you do not pay for the diagnostics package then perhaps they might get the data but you and Chevrolet does not...... Using OnStar charging can be turned on and off as they choose, whoever "they" are. I suspect this is a move towards V2G. Sometimes I consider drilling a hole through the antenna or otherwise disabling it as I am not a big fan of the big brother is watching you concept. 

Will the Luddite
Title: Re: Arduino based PWM diversion control system
Post by: ClassicCrazy on May 07, 2018, 08:54:52 AM
Not sure where the antenna is located or access to it but disconnecting the coax to the antenna would work. Or wrapping the antenna in tin foil will make it ineffective. Keep in mind that if you disconnect it , some agents may come knocking on your door ! ha ha .

I know someone who has a Tesla and that car is always hooked up to Tesla central command.

Larry
Title: Re: Arduino based PWM diversion control system
Post by: Westbranch on May 07, 2018, 10:54:30 AM
A friend with OnStar in his truck found out the hard way a few years ago, when  not on a "scheduled" (numbered) Highway in BC, that OnStar rescue service does not work without cell service.... that may be the reason they did not contact you about a bad battery....??

Thanks for the link to the battery issue..
Title: Re: Arduino based PWM diversion control system
Post by: WillEert on June 01, 2018, 07:47:57 PM
I think I will continue my car battery adventures in the batteries section.

Will