Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:07 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Electronics : 150V 45A MPPT - roll your own

     Page 47 of 50    
Author Message
poida

Guru

Joined: 02/02/2017
Location: Australia
Posts: 1418
Posted: 11:42pm 16 Nov 2023
Copy link to clipboard 
Print this post

something like this:

void sanity_check()
 {
 // check if battery connected, solar input exists, determine tracking mode, etc.
 // this is called once a second
 //

 // check for non zero current values once a minute, only in NIGHT mode and only once an hour when in night mode
 // if there is, increment cal_sensor_count
 // when it gets to 60, zero it and recalibrate
 //  
 int i;
 if (timeout_check(6,( (track_mode == NIGHT) && ( (fabs(Iin) > 0.1) || (fabs(Iout) > 0.1) )))
   {
     cal_sensor_count ++;
     if (cal_sensor_count > 60)
       {
         cal_sensor_count = 0;
         i = adc_average(IIN,25000);    // get input current sensor offset
         nvd.z_iin = i;                 // save it
         i = adc_average(IOUT,25000);   // etc.
         nvd.z_iout = i;
         nv();                         // write to non volatile ram
       }
   }
..
..

wronger than a phone book full of wrong phone numbers
 
flyingfishfinger
Senior Member

Joined: 12/09/2020
Location: United States
Posts: 110
Posted: 07:34pm 17 Nov 2023
Copy link to clipboard 
Print this post

Thinking out loud: The output side is also zero at night. The controller does require some current to run, but that is derived from a regulator connected to the battery terminals, so THAT current does not pass through the output sensor. We should be ok there.

Another consideration: Since we are effectively compensating for temperature drift at night only, we would still be accumulating error during the day when it warms up. So we are only solving half the capacity problem, maybe a bit more than half if we assume that a calibration in night mode near morning and evening reduces the error relative to daytime temperatures. Can we do better?
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 10:04pm 17 Nov 2023
Copy link to clipboard 
Print this post

I guess the most straight forward way to find the current offset is to periodically switch the MOSFETs off for a couple of seconds. The output must then be zero so the offset is whatever the current sensor is now reading. Compensate for that till the next rearing.
Perhaps this could be done either at the start of a max. power scan, or once per hour.
 
flyingfishfinger
Senior Member

Joined: 12/09/2020
Location: United States
Posts: 110
Posted: 11:10pm 17 Nov 2023
Copy link to clipboard 
Print this post

That sounds like an excellent idea.

I would lean towards once an hour, since we probably want to wait for the main capacitors to finish discharging before we take a measurement (i.e build in a small delay). If we did that once a minute it may reduce the efficiency of the system measurably.
 
poida

Guru

Joined: 02/02/2017
Location: Australia
Posts: 1418
Posted: 11:12pm 17 Nov 2023
Copy link to clipboard 
Print this post

I'm setting up the test system now
I like the idea of an hourly recal of the offsets.
Should be easy to code.
wronger than a phone book full of wrong phone numbers
 
flyingfishfinger
Senior Member

Joined: 12/09/2020
Location: United States
Posts: 110
Posted: 11:18pm 17 Nov 2023
Copy link to clipboard 
Print this post

  poida said  I'm setting up the test system now


Wow you are really on it! Appreciate the willingness to work on this - it'll be good for everyone else too I think :)
 
poida

Guru

Joined: 02/02/2017
Location: Australia
Posts: 1418
Posted: 12:40am 18 Nov 2023
Copy link to clipboard 
Print this post

done and tested.

this will recal the current sensor zero every 60 minutes.
It "costs" a few seconds of no charging when it runs.

This version is for the I2C LCD builds


mpptv5_BV_tempco_I2C_night_recal (2).zip


I tested it by having the serial console open and I check the
zero offsets for the two current sensors.
In my case they are 127 and 124 counts for the input and output sensors

I then applied a 1 Amp current through a sensor, using an isolated supply.
This immediately adds 1 Amp to the displayed value.
Then when recal is done, that 1 Amp is removed and not surprisingly
the zero offset have changed to allow for that 1 Amp

Later, I removed the 1 Amp and again recal sorted out the zero offset.

For those who want to play with this, each time the recal code is run, the menu is refeshed on the console so that means we can see that it ran and we can see the new values.

The code I added is


// this will return true once a minute, so with the counter it will run once an hour
 // if night mode, easy, just calibrate
 // if not night mode, stop the converter, wait a bit, then cal. and then re-enable back into absorb mode
 // mppt mode will be enabled automatically if needed
 //
 if ( timeout_check(6,1))
   {
     cal_sensor_count ++;
     if (cal_sensor_count > 60)           // should be 60 for an hour. testing will have it at 2 or something
       {
         cal_sensor_count = 0;           // one hour is up time to recal current sensor zero points
         if (track_mode != NIGHT)
           {
             //stop it
             buck_stop(3);
             track_mode = NIGHT;
             //wait. maybe need this to let caps equalise with battery and solar inputs
             dlay(2000);
             //recal
             i = adc_average(IIN,25000);    // get input current sensor offset
             nvd.z_iin = i;                 // save it
             i = adc_average(IOUT,25000);   // etc.
             nvd.z_iout = i;
             nv();                         // write to non volatile ram
             //restart, set 60 sec timer for mppt close to 60 seconds to more quickly get to mppt scan
             one_min = 55;
           }
         else
           {
             // it's night mode  
             i = adc_average(IIN,25000);    // get input current sensor offset
             nvd.z_iin = i;                 // save it
             i = adc_average(IOUT,25000);   // etc.
             nvd.z_iout = i;
             nv();                         // write to non volatile ram
           }
       }
   }


inside the sanity_check() code block
wronger than a phone book full of wrong phone numbers
 
flyingfishfinger
Senior Member

Joined: 12/09/2020
Location: United States
Posts: 110
Posted: 01:52am 18 Nov 2023
Copy link to clipboard 
Print this post

Nice!!

By the way, if anyone is just pasting the new section into existing code we need to also add:

- "int i" to the top of sanity_check()
- "cal_sensor_count" to one of the "volatile int" declaration sections at the very top of the program.

One other observation: This code does NOT have the freq_scale fix discussed a few pages back, it should be added to "init_controller()" right?
Edited 2023-11-18 11:53 by flyingfishfinger
 
flyingfishfinger
Senior Member

Joined: 12/09/2020
Location: United States
Posts: 110
Posted: 01:58am 18 Nov 2023
Copy link to clipboard 
Print this post

Also, I believe you have an error in the red part. The if statement has an extra "(", just adding this bit of code will cause compilation to fail.

  poida said  [...]

The fix is in Red


if (nvd.pwm_freq != 20 && nvd.pwm_freq != 40)
  {
  // set default at 20 kHz
  timer1_period = 833;
  baud_waits = 1;
  ints_second = 19200;
  freq_scale = 1;
  }
else
  {
  timer1_period = nvd.timer1_period;
  baud_waits = nvd.baud_waits;
  ints_second = nvd.ints_second;

  if ((nvd.pwm_freq == 20)
     freq_scale = 1;
  else
     freq_scale = 2;

  }



Edited 2023-11-18 12:00 by flyingfishfinger
 
poida

Guru

Joined: 02/02/2017
Location: Australia
Posts: 1418
Posted: 02:33am 18 Nov 2023
Copy link to clipboard 
Print this post

FF:
you ARE good
thanks for finding loose ends of unfinished work of mine.

i2C version with above fix for PWM frequency change bug

mpptv5_BV_tempco_I2C_night_recal.zip


and the serial LCD version with the new hourly current sensor offset cal
(includes the fix for PWM freq change)

mpptv5_BV_tempco_day_totals_current_sense_recal.zip


maybe it would be good if we use these two uploads as "the current version"
from now on.
wronger than a phone book full of wrong phone numbers
 
nickskethisniks
Guru

Joined: 17/10/2017
Location: Belgium
Posts: 458
Posted: 10:51am 18 Nov 2023
Copy link to clipboard 
Print this post

Depending on the amount or type of solar panels attached there runs a small reverse current during the night.
This could also contribute to the offset deviation.
I saw the LCD displays a current if you load the input (solar panels side) with a resistor.

An extra series diode or mosfet could fix that if you don't mind the extra loss.

I'm currently thinking about a new controller board, An extra opamp circuit with an adjustable offset (+-2.5V) could double the resolution and possible lower the offset fault.

Switching to an pin compatible lgt8f328 could also increase the 10 bit resolution to 12 bit. Without changing the code much. I have those running the lcd's with great result, I also have 1 for reading a pressure sensor in my rainwater buffer.

Another problem I have is when the controller is connected to a computer or something else the Vref is on a slightly different level. I had to add An external reference to the boards to do correct calibration.
 
Ziki_the
Newbie

Joined: 13/04/2023
Location: Yugoslavia
Posts: 39
Posted: 11:01am 18 Nov 2023
Copy link to clipboard 
Print this post

  nickskethisniks said  
Another problem I have is when the controller is connected to a computer or something else the Vref is on a slightly different level. I had to add An external reference to the boards to do correct calibration.


Did you tried to cut wire +5V in usb cable? So +5 from usb and +5v from brain board do not mix..
I did that.
Pozdrav iz Srbije
 
soudirector

Newbie

Joined: 14/05/2023
Location: Nigeria
Posts: 26
Posted: 12:24pm 18 Nov 2023
Copy link to clipboard 
Print this post

  poida said  FF:
you ARE good
thanks for finding loose ends of unfinished work of mine.

i2C version with above fix for PWM frequency change bug

mpptv5_BV_tempco_I2C_night_recal.zip


and the serial LCD version with the new hourly current sensor offset cal
(includes the fix for PWM freq change)

mpptv5_BV_tempco_day_totals_current_sense_recal.zip


maybe it would be good if we use these two uploads as "the current version"
from now on.



Is the calibration the same?
how times flies
 
soudirector

Newbie

Joined: 14/05/2023
Location: Nigeria
Posts: 26
Posted: 12:48pm 18 Nov 2023
Copy link to clipboard 
Print this post

I am have not gotten this to work. When cal. i type in the VIN but i still have NANU display.

in the serial monitor window

it will change to this

13:37:44.084 -> C - cal. Input Volts     inf ( nan V)  

But VOUT display whatever i put there.

What am i not getting right ?





how times flies
 
nickskethisniks
Guru

Joined: 17/10/2017
Location: Belgium
Posts: 458
Posted: 07:00pm 18 Nov 2023
Copy link to clipboard 
Print this post

  soudirector said  I am have not gotten this to work. When cal. i type in the VIN but i still have NANU display.

in the serial monitor window

it will change to this

13:37:44.084 -> C - cal. Input Volts     inf ( nan V)  

But VOUT display whatever i put there.

What am i not getting right ?




[/QUOTE

I think you need to " zero " it first
 
nickskethisniks
Guru

Joined: 17/10/2017
Location: Belgium
Posts: 458
Posted: 07:09pm 18 Nov 2023
Copy link to clipboard 
Print this post

  Ziki_the said  
  nickskethisniks said  
Another problem I have is when the controller is connected to a computer or something else the Vref is on a slightly different level. I had to add An external reference to the boards to do correct calibration.


Did you tried to cut wire +5V in usb cable? So +5 from usb and +5v from brain board do not mix..
I did that.


Nop, that was to easy, I didn't think about doing it that way
Good suggestion, that should do the trick as Well, but doing it my way the nanoboard stays unmodified but it needs and extra line of code.
Edited 2023-11-19 05:09 by nickskethisniks
 
Ziki_the
Newbie

Joined: 13/04/2023
Location: Yugoslavia
Posts: 39
Posted: 09:00pm 18 Nov 2023
Copy link to clipboard 
Print this post

@nick
Just use usb cable for programing nano, cut insulation and cut red wire.
No need for nano modification...
Pozdrav iz Srbije
 
nickskethisniks
Guru

Joined: 17/10/2017
Location: Belgium
Posts: 458
Posted: 09:11pm 18 Nov 2023
Copy link to clipboard 
Print this post

  Ziki_the said  @nick
Just use usb cable for programing nano, cut insulation and cut red wire.
No need for nano modification...


I would probably come up with that in my sleep this night, but at the moment I was writing I couldn't see the most obvious solution...thanks for making me blushing again. I hope I can score some points again to honor my "guru" status.  
 
Ziki_the
Newbie

Joined: 13/04/2023
Location: Yugoslavia
Posts: 39
Posted: 09:34pm 18 Nov 2023
Copy link to clipboard 
Print this post

@nick
This was quick and dirty solution, maybe will help someone else.
And guru status is deserved, no blush  
Pozdrav iz Srbije
 
mab1
Senior Member

Joined: 10/02/2015
Location: United Kingdom
Posts: 209
Posted: 01:26am 19 Nov 2023
Copy link to clipboard 
Print this post

  soudirector said  I am have not gotten this to work. When cal. i type in the VIN but i still have NANU display.

in the serial monitor window

it will change to this

13:37:44.084 -> C - cal. Input Volts     inf ( nan V)  

But VOUT display whatever i put there.

What am i not getting right ?



I think had something similar - one of the cal values 'inf' and wouldn't reset: i think i cleared it by selecting the 'set defaults' (option Z?), but this does mean you have to re-do all the zeros, cals and setpoints again.
 
     Page 47 of 50    
Print this page
© JAQ Software 2024