Skip to the content
PCBKitNew board
2 layers56.7 × 25.4 mmBatteryMonitorATTiny3224, the printed circuit board in 3D

BatteryMonitorATTiny3224

ieb/BatterySensor1

A Modbus RTU Battery Current and Voltage sensor board based Attiny3224, MAX485, MAX9918 chips.

Size
56.7 × 25.4 mm
Copper layers
2
Thickness
1.6 mm
Parts
24
Nets
20
Pads
82
Tracks, vias
265, 17
Pours
4
Routed
Yes
KiCad
KiCad 4
Created
17 Jun 2022
Updated
15 Jul 2022

Overview

BatteryMonitorATTiny3224 is an open-source printed circuit board by ieb, from the ieb/BatterySensor repository on GitHub. It is a 2-layer board of 56.7 × 25.4 mm with 24 parts on 20 nets, routed with 265 tracks and 17 vias.

It is built around the ATTINY3224-SSU, MAX3485ED and RS485, with the AMS1117 among its other parts. Its parts include 9 resistors, 7 capacitors, 5 ICs and 3 connectors. It belongs with the sensors and measurement boards and the AVR (ATmega, ATtiny) boards of this library.

Main components

4

README

README.md

Battery Sensor

Aim is to create a low power smat shunt batter sensor reporting volage, current and temperatire over ModbusRTU.

Shunt is measured using a MAX9918 shut amplifier amplifying 48x a 75mV/100A shunt scaled down to 50mV to keep the MAX9918 input optimal. Temperature by a 10K NTC read by ADC using an interpolation table. Voltage by direct ADC with a voltage divder RS485 by MAX485

Protocol

Modbus RTU - bigendian

Holding registers - function 3 to read, 6 to set

Stored in EEPROM, which is typically reset on a firmware upgrade.

OffsetNametypedetails
0Device Adddressint161-254 modbus address, default is 2
1Voltage offset adjustmentint16Offset in 0.1mv steps eg 10 = 1mV
2Voltage scale adjustmentint16scale in 1/10000th eg 10000 = 1x
3Current offset adjustmentint16offset in 0.1mA steps eg 10 = 1mA
4Current scale adjustmentint16scale in 1/10000th eg 10000 = 1x
5Temperature offset adjustmentint16offset in C in 1/1000th eg 1000 = +1C
6Temperature scale adjustmentint16scale in C in 1/1000th eg 1000 = 1x
7Serial Numberint16Device serial number, once set cannot be changed

Input Registers - function 4 to read

OffsetNametypedetails
0Voltageint16Units 0.01V
1Currentint16Units 0.01A
2Temperatureint161 = 0.01C
1001Recieveduint16count of frames recieved
1002Sentuint16count off frames send
1003Errors Recieveduint16count off frames recieved with errors
1004Ignoreduint16count off frames dropped
1005Errors Sentuint16count off error frames send

Other functions

  • 17 - report - 4 bytes, uint8 device type (0x01), uint device on (0xff), int16 serial number (0xXXXX)

Exceptions are reported as per ModbuRTU Spec.

MCU

Platform ATTiny8224 Could have also used a ATTiny84, but this has no uarts and requires ICSP programming. Programmming using jtag2udpi on an Arduino Uno with avrdude.conf setup for the ATTiny8224, running at 5V.

Voltage

The ATTiny ADC in 16bit using 4096 refrence through aa 32K/10K divider, gives withing 10mv of a 4 digit multi meter after calibration setting (0.9954 register 2 set to 9954). Hard to tell which is more accutage, probably the ADC. Voltage is stable with the LSB changing +- 1 or 2.

Current

Multiple frustrating attempts with a current amplifier, eventually abandoned.

The originam MAX9918 had an unstable 75mV offset from the reference resistors at 0A which would not go, chip might have been damaged during soldering or the EP ground plane was not good enough.

2x INA169 that I had from years ago could not be made to amplify the input correctly at the required 47x gain. Looking back I had tried INA169 before and had problems eventually abandoning.

Now trying the Attiny3224 ADC + PGA at 16x which measures down to 0.0019mV perbit below 64mV differntial on the 16bit range with a 1024mV refrence, however this might really be 0.015625mV resolution as the 16 bit is oversampling 12bit. If it is, this represents a resolution of +-20mA which is perfectly reasonable for a 100A/75mV shunt. Quick testing indicates this is stable and repeatable with 10R on the input lines for protection from misconnection and 100nF accross the ADC inputs to remove high frequency components.

If that fails I will use one of the Alegro Hall chips, althought I prefer the simplicity of a shunt.

debugging

Performed over serial on the second uart at 115200 baud. Modbus is at 9600 baud 8N1

Building with DEVMODE (see main.cpp) defined allows the rs485 serial to be diverted to Serial1 and test patterns to be pasted from testpatterns.txt over the monitoring serial line.

Testing can be done with

text
        pio run -e native 

which produces a native binary then

text
        cat testpattern.txt |  ./.pio/build/native/program

Which checks exercises the RS485 protocol using test patterns checking the response.

Programming

Currently using jtag2udpi, via an Uno, but setting fuses seems hard Needs a modified avrdude.conf file to add support for the attiny3224 pio run -t fuse -e attiny3224 does appear to work.

Fuses must be set to ensure the chip clock speed matches the compiled code. This only needs to be done once per chip. It its not done the serial output doesnt sync with the baud rate and garbage is seen on the serial line.

text
pio run -t fuses -e attiny3224

Looking at megaTinyCore support in the Arduino IDE using SerialUDPI is much better and more advanced.

text
pio run -t upload -e attiny3224 

works ok for the moment.

Board

For full details see the pcb/* In outline.

text
        ------------------------------------------
        | a           1 2 3 4 5                 A|
        | b   MAX                      MAX      B|     
        | c   RS485   Atting3224       9918     C|     
        | d                                     D|     
        |     AMS1117                           E|
        ------------------------------------------     

        a = GND
        b = Vin (12v)
        c = RS485 A
        d = RS485 B

        1 = GND
        2 = +5V
        3 = UDPI
        4 = Debug RX
        5 = Debug TX

        A = Battery +Ve
        B = Shunt -
        C = Shunt +
        D = GND
        E = NTC

Test client

in testclient/ requires python3. install with

text
pip install -r requirements.txt

run with

text
python3 batterymon.py

TODO

  • Check MAX9918 amplifier - Abandoned using MAX9918 as it had 75mV offset from its reference point and a lot of instability. Have switched to a pair of INA196 current amplifiers which so far draw much less current and seem stable
  • Test temperature
  • Test voltage
  • Test current - switched to direct to ADC which gives good 0mA stability, need to verify linearit
  • Test RS485
  • Write Python Modbus RTU Controller to test for real.
  • Calibrate
  • Integrate with CanDiagnose controler to act as ModBus Controller for 1..n battery sensors.

Parts

24
QtyValueFootprintReferences
510KResistors_SMD:R_0805R101, R103, R104, R105, R108
3100nFCapacitors_SMD:C_0805C105, C106, C109
210uFCapacitors_SMD:C_1206C101, C104
247KResistors_SMD:R_0805R112, R113
2INA169TO_SOT_Packages_SMD:SOT-23-5_HandSolderingIC103, IC104
11nFCapacitors_SMD:C_0805C107
122KResistors_SMD:R_0805R102
1270RResistors_SMD:R_0805R114
1AMS1117TO_SOT_Packages_SMD:SOT-223-3Lead_TabPin2U101
1ATTINY3224-SSHousings_SOIC:SOIC-14_3.9x8.7mm_Pitch1.27mmIC102
1BatConnect:bornier5P102
1CCapacitors_SMD:C_0805C108
1MAX3485EHousings_SOIC:SOIC-8_3.9x4.9mm_Pitch1.27mmIC101
1ProgPin_Headers:Pin_Header_Straight_1x05P103
1RS485Connect:bornier4P101

Questions

How big is the BatteryMonitorATTiny3224 PCB?

It measures 56.7 × 25.4 mm and has 2 copper layers, 1.6 mm thick.

What parts does the BatteryMonitorATTiny3224 use?

24 parts, built around the ATTINY3224-SSU, MAX3485ED, RS485 and AMS1117. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the BatteryMonitorATTiny3224 KiCad files?

From the ieb/BatterySensor repository on GitHub, at the commit this page was made from: the board is pcb/BatteryMonitor/BatteryMonitorATTiny3224.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the BatteryMonitorATTiny3224 design in my own project?

Its repository states no licence, so its author keeps all rights: ask ieb before reusing the design.

Similar boards

  • 2 layers70.6 × 28 mmModusBatteryMonitor, the printed circuit board in 3D

    ModusBatteryMonitor

    ieb/ModbusShunt

    Modbus Battery monitor using IN219 Attiny3224 on a 100A 75mV shunt.

    17 parts
  • 2 layers100 × 100 mmExplorer, the printed circuit board in 3D

    Explorer

    anyshake/explorer

    🌏 Detecting seismic wave using 3 geophones and 3-axis accelerometer, pack & send data to AnyShake Observer over RS232 / RS485 serial.

    266 parts100
  • 2 layers62 × 73.7 mmDoorBirdPico, the printed circuit board in 3D

    DoorBirdPico

    fraxinas/DoorBirdPico

    A custom Raspberry Pi Pico PCB design and code to add functionality to the DoorBird Voip entryphone.

    42 parts4
  • 4 layers54 × 100 mmOxrs black 004, the printed circuit board in 3D

    Oxrs black 004

    austinscreations/Oxrs-Black

    a custom rack controller that is based of the rack32 but includes some upgrades and major changes

    92 parts1GPL-3.0
  • 2 layers100 × 50 mmGnss, the printed circuit board in 3D

    Gnss

    bclswl0827/openstation

    An open source, cross-platform, easy-to-use satellite automatic tracking system with hardware & software solutions.

    42 parts1
  • 2 layers64.9 × 64.9 mm485modue, the printed circuit board in 3D

    485modue

    latonita/kicad-various-shematics

    Various projects schematics and pcbs

    23 parts1
  • 2 layers139.9 × 85.8 mmPas hw, the printed circuit board in 3D

    Pas hw

    NGOQUOC98/ESP32_MODBUS_PCB_MASTER

    This project was in development phase - we will remove this remark after release

    198 parts1
  • 2 layers94 × 56.3 mmRemote unit, the printed circuit board in 3D

    Remote unit

    danielmcmillan/irrigation-system

    Hardware and software for irrigation control and monitoring

    63 partsMIT