The Blog

Data logging

I always find data fascinating. It gives me an insight into the overall functioning of a system. Data can be used to make intelligent decisions based on past events or trends. Data gives us visual graphs of performance and often a single glance at a group of data points presented the right way gives us a wealth of information.

Wattmon captures data on current and voltage input and load, and logs average values on a per-minute basis. Wattmon also computes battery capacity every minute and updates internal registers. It also has a system log for events of importance. All these collected data points can be used at any point to figure out the system state of both wattmon and the solar setup and battery bank. A battery status Graph immediately shows you the lowest and highest state of charge throughout the day making it simple to see if your batteries are either too depleted or too quickly charged.

Battery Status

Battery Status Graph per day

Solar Input Graph

Solar Input Graph per day showing KWh generated

Load Graph and Main Charge

Load and grid charge graph showing reduced charge hours compared to before

The solar and inverter graphs show watts generated and consumed throughout the day with a kwh total. Wattmon has helped me personally reduce my grid energy consumption at the cynergy office. I have a 1kw solar array and two 180 ah batteries. My inverter cum grid charger was always connected to the grid, meaning that my batteries were always full and the solar power was totally wasted. In addition, I was being billed for all my usage of energy. Within one day of installing wattmon it was evident that I had sufficient solar energy to run my office totally off the grid most of the time. The wattmon device communicates with a wattmon relay to switch on and off the grid charger when required. I have set it so my battery never depletes below 10% (it is at 90% state of charge) which will give me a longer life. So generally at night my relay charges the batteries for half an hour or so, and this may happen a few times during every night. So I have cut my reliance on the grid almost completely thanks to wattmon.

Comment (0) Hits: 2944

Prototypes and installing

Prototypes

We have decided to start the production of 50 devices for more thorough testing. A few wattmon boxes are already running in the field and I am actively monitoring and fine tuning the firmware and web interface but so far the feedback has been positive.
Installing The main issue so far during installation was getting Internet connectivity to the battery room. This proved to be challenging using wifi even though I have a dongle specifically designed to bridge Ethernet and wifi. In the end I had to run Ethernet cable from the main adsl router.
Connecting up the wattmon current sensors is easy - but requires everything to be switched off beforehand as the battery wires need to be pulled through the hall sensor. Power is taken for the battery terminals directly allowing for the voltage to be sensed as well. I am thinking of adding an external sense input for high voltage sensing.

Firmware issues

So far the major problem has been erratic behaviour on the login, session handling had some major bug that made it seem to behave very unpredictably. I squashed a bunch of bugs and traced the problem finally to http headers. Large headers with lots of accept tags would cause the http server to miss the cookie tag and hence the session would remain uninitialised. In firmware 1.39 this issue has been solved. There was also a problem with the way post requests were parsed. I have now tested it with over 50 parameters and it works smoothly, which should be sufficient for most embedded developers.

Comment (0) Hits: 2843

RS-485 Communication

 

IEE-485

The IEE-485 standard is the approved version of the RS-485 standard. Both of these terms are used interchangeably when referring to the two-wire bus topology defined by this standard. Communication happens over a pair of wires referred to as A and B or D+ and D-. For maximum performance a twisted pair cable is used between nodes. At each transceiver, the D+ line is pulled high using a 470 ohm or greater resistor depending on the voltage of the bus. Th D- line is pulled low with another resistor of the same value (in wattmon, I use 470 ohms). At the source and end of the line, a 100 ohm resistor needs to be connected between the D+ and D- lines - this is called a terminator.

The transceiver

The communication is managed by an RS-484 transceiver device. I use the SP3078 since it operates at 3.3V but for 5V operation a MAX485 will work fine too. These 8 pin devices have a D+ pin, and a D- pin which would be connected to the resistors as described above. In addition, there is an RO pin, which would be connected to your MCUs RX pin, a DI (data in) pin which connects to your MCUs TX pin, and a DE and RE pair of lains which enables the transmit mode on the transceiver. These can be tied together are one is Inverted, allowing the same logic signal from an MCU Pin to toggle their state properly.

When you need to send data, enable TX mode by pulling high or low (depending on the transceiver) the TXEN pin, wait a very short while, and then simply send your data out the TX pin as with standard serial communication. The great thing about RS-485 is that you can daisy chain devices together, and sending data from one device to every other connected device is automatic. However, this also creates room for collisions and data loss. If a device transmits while another one is already transmitting this can create real trouble in communication. There are different ways to tackle this, and I have researched the various protocols extensively before deciding on Modbus, which is a master-slave protocol. Using master-slave type communication ensures that no device will ever transmit unless it first receives a request from the master device, in this case the wattmon box.

Other protocols of interest were uLan, which uses a 9 bit data stream, with the ninth bit set for commands. This has the great advantage that the microcontroller does not need to receive every byte and parse it, but can listen for a specific pattern and only process relevant packets of data. I decided against it because I wanted to go with an industry standard that I could easily interface with and also because 8 bit data streams are easier to work with in small embedded hardware. Another option was a token passing system, and a time sliced communication method. The choice made will depend very much on the application. In wattmon, I wanted the ability to add multiple devices to the same bus, and at the same time I didn't need these devices to every initiate communication with the wattmon master. Ever device is polled automatically through a poller task ensuring hassle free communication.

Comment (0) Hits: 3394

Introduction to Modbus

Modbus

So what is modbus? I have heard many people ask me this and the reason it is confusing is because the term modbus is used with a variety of hardware and comes in different flavours: modbus RTU and modbus ASCII. Modbus is in itself a master-slave protocol intended to transfer small packets of data between a master and one or more nodes over a physical medium such as a serial wire. Some modbus devices only support rs-232 whereas others support RS-485, and even Ethernet. Modbus RTU and modbus ASCII differ in the way they transfer the data across, RTU mode uses a more compact packet whereas ASCII mode formats data bytes as strings. An example of each is shown below:

11 03 00 6B 00 03

The complete ASCII request is made by first adding the message delimiting characters. A colon is added to the start of the message, the LRC, carriage return and line feed are added to the end:

  : 1 1  0 3  0 0  6 B  0 0  0 3  7 E  CR LF

Each character is now treated as an ASCII character and replaced with it's hex value to give the final message, making a total of 17 bytes.

Modbus Registers

Every modbus device has zero or more registers, coils and digital inputs. Every register has an address between 0 and 65535. Normally registers are grouped together at certain addresses. In wattmon for example, digital inputs are at 1000, digital outputs at 2000, read only registers at 3000 and writable registers at 4000. I have seen different implementations of modbus that do not adhere completely to the specifications and interchange holding registers and input registers. Holding registers are used to set a value, either permanently in the EEPROM of a device or temporarily, such as an analog output. Input Registers generally give live readings of some digitised signal such as a current.

Wattmon devices have calibration registers which store calibration constants in EEPROM. All current sensors digitise the filtered analog signal and place the raw reading in one input register. A second register is used to store the calculated value. For example, a single channel sensor has a 12 bit range over 100 amps bidirectional current. The adc gives a reading of approx 2048 at 0 current, 4096 at 100 amps and 0 at -100 amps. But due to different factors this is sometimes off by a few points. For example, the 0 current could be at 2032, 2054 or something close.

One calibration register used in these sensors is an offset register. This is subtracted from the reading before further processing. Next, the reading needs to be scaled. This is done by multiplication and division since registers are 16 bit integers. For example, a 50 amp sensor typically is multiplied by 302 and divided by 10. This gives 30.2 mA per adc change. By pure calculation you would expect 2048/50 or 40.6 and this may vary from device to device, so every one needs to be calibrated against a known current. Wattmon includes one register for the multiplication factor and one for the division. Finally, a fourth register is used to allow the sign to be inverted, if the wire was pulled through in the wrong direction. The following shows an example of the registers:

holding registers:
Register 4000: 2032
Register 4001: 302
Register 4002: 10
Register 4003: 0

At adc reading 2000, input registers would look like this:

Register 3000: -966
Register 3001: 2000

Register 3000 is the calibrated value and indicates a current of -9.66 amps.

For a good simple reference on modbus, visit simplymodbus.ca

Comment (0) Hits: 3228