PV System Rewired

In August I ordered a Midnite Solar Mini-DC Disconnect and last month I finally got time to install it into my PV system. The Mini-DC is a small breaker panel/enclosure specifically targeted PV systems like mine. The enclosure has one 250A breaker and room for five small, DIN-rail breakers as well as mounting holes for the shunt(s). Below is an image of the rewired system and a close up of the Mini-DC.

Rewired PV system

Rewired PV system

Close up of Mini-DC internals showing the two shunts

Close up of Mini-DC internals showing the two shunts

The Pentametric has arrived

The Bogart Pentametric arrived in the mail yesterday and I connected it to a 12V power supply in my study. Connecting it was straight forward following the wiring diagram printed on the cover of the input unit. The connectors are of high quality. After applying power I hooked it to the serial port of my PC using a standard serial cable. Using the PMComm software from the Bogart Engineering web site configuring the unit was very easy. Below is a picture of the setup. In the middle in the bottom is the Pentametric input unit and serial interface connected to the Atmel Xplain board. The Xplain board is connected to an nRF24LE1 evaluation board (left) through SPI and this board sends a radio packet with the measured data every second. To the right is the nRF24LE1 receiver board showing the battery voltage, 13.8V. The battery in this setup is a laboratory type power supply.

Pentametric input unit and computer interface (lower middle)

Pentametric input unit and computer interface (lower middle)

Instructions for communicating with Pentametric via the serial interface can be found in this document: How to access data via the RS232 port from the PentaMetric battery monitor.

I will post the full source code here after it is finished but here is a preview of the “short read” command:

bool pentametric_short_read(unsigned char a, unsigned char n, unsigned char *msg)
{
unsigned char crc, i;
putchar(usart_data_, 0×81);
putchar(usart_data_, a);
putchar(usart_data_, n);
crc = 0×81 + a + n;
putchar(usart_data_, ~crc);
crc = 0;
for(i=0;i<n;i++)
{
msg[i] = getchar(usart_data_);
crc += msg[i];
}
crc += getchar(usart_data_);
if (crc != 0xff)
return false;
return true;
}
bool pentametric_short_read(uint8_t a, uint8_t n, uint8_t *msg)
{
    uint8_t crc, i;

    putchar(usart_data_, 0x81);
    putchar(usart_data_, a);
    putchar(usart_data_, n);
    crc = 0x81 + a + n;
    putchar(usart_data_, ~crc);
    crc = 0;
    for(i=0;i<n;i++)
    {
        msg[i] = getchar(usart_data_);
        crc += msg[i];
    }
    crc += getchar(usart_data_);
    if (crc != 0xff)
        return false;
    return true;
}

Atmel xmega and the Xplain evaluation and demonstration kit

As written in the previous post I am going to use the Pentametric Battery Monitor to measure the current in/out of the batteries. This means that I need to move the control of my monitor system from nRF24LE1 to a more powerful board with more than one serial port. I have thought about this and have made up my mind to use an xmega  micro controller from Atmel. Mainly because I have used the AVR micro controllers in several projects in the past and that the xmega have many serial ports (USARTs). The ATxmega128A1 found on the xplain evaluation and demonstration kit has eight (!) USARTs. Pictured here is the xplain board connected to an nRFgo board via SPI:

Xplain and nRFgo motherboards

Xplain and nRFgo boards

Below is a basic diagram of the new system. On the USART on xmega side I will use MAX3232 RS232 Transceivers and on the SunSaver (SS) MPPT side I will use the Morningstar PC Meterbus Adapter that converts the SS RS485 bus to RS232. The Pentametric use a similar converter, the Bogart PM-100-C.
Basic block diagram of new system

Basic block diagram of new system

Wireless transmitter prototype board

Here is a picture of the new prototype board mounted in my tool shed. The nRF24LE1 module is the same but I have moved it from the nRFgo motherboard to a prototyping board. I have also added a LM317 voltage regulator and an RS232 driver.

nRF24LE1 module

nRF24LE1 module

I have also made up my mind to order the Pentametric Battery Monitor from Bogart Engineering and use it for current measurement instead of the circuit described below. The Pentametric has a computer interface that can be used to read out all data captured. This means I also need a micro controller with more than one serial port. More on that later.

What’s All This MPPT Stuff, Anyhow?

I have put my project on hold while waiting for the SSOP-20 adapter for the PGIA mentioned below. This adapter makes it much easier to solder these tiny IC’s to a prototyping board.

SSOP-20 PCB Adapter
SSOP-20 PCB Adapter

I ordered the adapter from micro4you but similar adapters are available from other sources.

 
Now to the subject of this posting; MPPT. MPPT stands for Maximum Power Point Tracking and is a (as used in solar charge controllers) method or algorithm to get the maximum available power from the photovoltaic (PV) modules. In principle this is easy but is very tricky to implement in practice. Below are some articles I have found on the subject.
 
 
Article by Stephen Woodward in Electronic Design: Maximum-power-point-tracking solar battery charger
 
PhD thesis by Dezső Séra (abstract only available on-line): Real-time Modelling, Diagnostics and Optimised MPPT for Residential PV systems
 
Various articles by Dezső Séra on his home page: Homepage for Dezső Séra
 
DIY: MPPT
Discussion forums:
I hope Bob Pease did not mind that I used his very informative articles as an inspiration for the title of this post.

Not quite there yet

I visited my cabin last weekend to try out the Modbus functions below on the SunSaver MPPT. I also had implemented a test-version of the RF protocol so I could check the radio range. I have my solar system in a tool shed about 10 meters from my cabin. This combined with about two meters of snow should be more than challenging enough for the tiny PCB antenna on the nRF24LE1 modules.

Surely enough, the radio did not like these conditions. I had to place the receiver in a window facing the tool shed and the transmitter in the door opening on my tool shed to be within range. Luckily I had two other modules with SMA connectors and matching 2.4GHz antennas that I could use. With these modules the radios functioned flawlessly.

Below is a picture of the transmitter (with PCB antenna) in the tool shed. The SunSaver MPPT is on the wall to the left. The box on the wall, in the middle is the Bogart Engineering Trimetric and the big blue box partly in the right of the picture is a Victron Energy Inverter/Charger. On the floor are two SunXtender AGM batteries with the nRFgo evaluation board on top of the battery to the right.

nrfgo2

RF packet format

The 2.4GHz radio in the nRF24LE1 is very easy get on air quickly but it gets really fun when using the Gazell library included in the nRFgo SDK. The only thing we have to do is to edit some default values in a header file and add the source files to our project. Most of the default values can be left unchanged and I changed three of them; I reduced the bit rate from 2mbps to 250kbps, increased the payload length to 32 bytes and the RX period to 10ms.

Even if we do not need the full 32 bytes payload length at once, I will use this length from start so I do not need to increase it later. I will also add a packet type to the beginning of each packet such that I can add other packet types later. For example the SunSaver MPPT store 32 days of historical data that can be read out through the Modbus. Maybe I will add this in a future version of the firmware. The figure below shows the suggested format for RF packet type 1.

RF packet type 1 format

RF packet type 1 format

Here:
PID is a packet identifier that increments for each packet sent. This makes it easier for the receiver to keep track of any lost packets (more on this later).
VB is the battery voltage reported by the SS MPPT
VP is the solar array voltage reported by the SS MPPT
VL is the load voltage reported by the SS MPPT
VI is the inverter voltage (not used yet)
IL is the load current reported by the SS MPPT
IC is the charge current reported by the SS MPPT
IS is the shunt current measured by the ADC discussed below
II is the inverter current (not used yet)
TA is the ambient temperature reported by the SS MPPT
TB is the battery temperature  reported by the SS MPPT
TI is the inverter temperature (not used yet)
All currents and voltages are split into high byte and low byte (e.g. VBH and VBL). If they are read from he SunSaver MPPT they are sent in the format read. The blank boxes are for future expansion.

More about prescaling

I have been rethinking the range of my analog input again. It would have been nice to have a better resolution on the lowest input voltages (currents) so I will redesign the input stage onemore time. My goal is 10uV (10mA).

I have also spent a few days programming and trying out the ADC in the nRF24LE1 and the resolution is closer to 10 bits than 12 bits. This together with the requirement of measuring 10mA calls for a prescaler with variable gain. Two or three gain settings would suffice.

I have ordered samples of a programmable gain amplifier (PGIA) from Linear Technology and if I receive them I will use this amp instead of making  my own. Here are details about the PGIA: LTC6915 – Zero Drift, Precision Instrumentation Amplifier with Digitally Programmable Gain

Prescaling the voltage from the shunt

I have changed my mind about the range of the voltage across the Trimetric shunt. As I said below it is very unlikely that I will ever charge the batteries at 100A so I reduce this requirement to 50A (my Victron charger has a limit of 50A as well). On the other hand I sometimes use power tools that for short periods use more than 1200W so I increase the other limit to 110A. This means we will get an input voltage from -110mV to +50mV.

As mentioned below I will use a non-inverting summation amplifier to offset the input voltage to the 0V to 1.2V required by the nRF24LE1:

Non-inverting summing amplifier.

Non-inverting summing amplifier.

The output voltage for this amplifier is given by this equation:

Vo = (1+R4/R3)(Vi R2+Vr R1)/(R1+R2)

Where Vr is a reference voltage that we will choose such that the voltage at the input is 0V when Vi is -110mV. If we set R1=R2 then Vr=110mV. Using these values and the fact that we want full scale (Vo=1.2V) on the ADC input when the input voltage is 50mV we get

R4/R3 = 14

The only task left then is to choose impedance level because there are an infinite number of resistor values that fits these equations. There are numerous articles on the net on this issue so I will not go into great detail here other than saying that in similar designs in the past, values from 10KΩ to 100KΩ ± has worked for me. Therefore I will start with these values: R1=R2=20KΩ, R3=10KΩ and R4=140KΩ.

To generate Vr I will use a simple voltage divider on the 3.3V supply voltage and run the divided voltage to a spare ADC input on the RF24LE1. Again there are an infinite number of resistor values to choose from and the voltage will be more stable with a low impedance level than with a high. On the other hand we are on a limited budget current-wise here so I will set a current limit on the divider to 1mA (3.3KΩ).

Voltage divider

Voltage divider

With the standard resistor values R5=3.3KΩ and R6=120Ω we get Vr=116mV which is close enough. The exact value is not important since we will sample Vr together with Vo and use both in the equation to calculate Vi.

Reading the SunSaver MPPT Input Registers

 

The SunSaver uses the Modbus in RTU mode to communicate with any external (master) device as detailed in the SunSaver MPPT MODBUS Document. In the first version of the wireless remote meter I will only use the data in the Input Registers of the SunSaver. Detailed examples of the message format with CRC values can be found in the Modbus Specification. C-language source code for the CRC calculation can be found at the end of the Modbus Serial Line Protocol and Implementation Guide. Using the information in these documents and the uart library from the nRFgo Software Development Kit (SDK) a function to read the Input Registers of the SunSaver can be written easily:

 

#define SS_MODBUS_ADDR 0x01

static void modbus_send_msg(uint8_t n, uint8_t *msg)
{
  uint8_t i;
  uint16_t crc;
  crc = crc16(msg, n);
  msg[n] = crc & 0xff;
  msg[n+1] = crc >> 8;
  for (i=0;i<(n+2);i++)
    hal_uart_putchar(msg[i]);
}

bool ss_mppt_read_input_registers(uint8_t a, uint8_t n, uint16_t xdata *buf)
{
  uint8_t xdata msg[256];
  uint8_t i;
  uint16_t reg;
  msg[0] = SS_MODBUS_ADDR;// Default SunSaver MPPT Modbus Address
  msg[1] = 0x04; // Read Input Registers
  msg[2] = 0; // MSB of register address
  msg[3] = a; // Register address
  msg[4] = 0; // MSB of number of registers to read
  msg[5] = n; // Number of registers to read
  modbus_send_msg(6, msg);
  if (hal_uart_getchar() != SS_MODBUS_ADDR)
    return false;
  if (hal_uart_getchar() != 0x04)
    return false;
  if (hal_uart_getchar() != (2*n))
    return false;
  for (i=0;i<n;i++)
  {
    reg = hal_uart_getchar();
    reg <<= 8;
    reg |= hal_uart_getchar();
    buf[i] = reg;
  }
  // Ignore CRC:
  hal_uart_getchar();
  hal_uart_getchar();
  return true;
}
 

 

Please note that only minimal error checking is done on the response from the SunSaver; the inter-character delay as per the Modbus spec. is not checked and the CRC is ignored. A check on these will be implemented in a future version of the firmware.

 

Also note that the code above uses keywords specific to the Keil C51 compiler. I will try to port the code to the free SDCC compiler after the code is finished.