1 of 23

Small Hydro Power Plant with Elixir

Part 2

Nerves Conf EU

2025/09/10

1

2 of 23

Outline

  • System map, network topology and devices
  • Communication between nodes
  • Generator Control and fault monitoring
  • Off-site & On-site working

2

3 of 23

System map

3

MODBUS devices

MODBUS devices

Hub

Hub

Erlang Cluster

SDC

PGC

DIO

Temp

Volt

RPM

DIO

Volt

SoC

optical fiber

turbidity, water level

SoC: battery’s State of Charge [%]

Control Plant

Collects and pushes data to WEB

4 of 23

4

PGC

Hub

Bus line Multimeter

Gen line Multimeter

Rotation meter

DIOs

DIOs, temps

Modbus TCP

Device

Modbus TCP/RTU Converter

RS-485 bus

5 of 23

Why we chose MODBUS TCP

  • CONS
    • The data are not pushed from the MODBUS device
      • We must poll the data periodically
  • PROS
    • Everything is IP based, independent from the `devices`
      • This plant may be used for decades�we may need to change the Nerves device itself
      • Many devices support MODBUS TCP/RTU. So they're interchangeable.

5

6 of 23

Momentary switches without interrupts

The switches on panel can work with 100ms data polling loop.

For this system, this duration is sufficient.

6

7 of 23

Which MODBUS TCP library we use

We choose our own way.

Make things under control, this is the core library of our system.

If there is a bug, that’s our bug. ��We can immediately fix it ourselves.

7

8 of 23

  • Support both TCP/RTU
    • use :gen_tcp for TCP
    • use Circuits.UART for RTU
  • Can make gateway
  • Support both client/server

Give it a try�and give us feedback

8

Modbuzz

TCP

Client

Modbuzz

RTU

Client

Any

TCP/RTU

Client

Modbuzz

TCP/RTU

Server

Modbuzz

TCP

Server

Modbuzz

RTU

Client

Any

TCP

Client

9 of 23

Communication between nodes

9

MODBUS devices

MODBUS devices

Erlang Cluster

SDC

PGC

DIO

Temp

Volt

RPM

DIO

Volt

SOC

GenServer.call with {:global, term}

name registration

:erpc.call(node, module, function, args)

10 of 23

Let’s dig in about control

We don't use any PLCs to control. �So, how do we control the plant?

10

Input Valve

Needle Valve

11 of 23

Writing `Sequence` with GenServer

11

part of Run sequence

12 of 23

12

part of Run sequence

13 of 23

How it works

13

Generator

Power

Bus

Power

14 of 23

Adjust to sync with the bus line

  • Voltage
    • adjusted by AVR device
  • Frequency
    • adjusted by actuator
  • Phase
    • just wait for a match

14

AVR

actuator

automatic synchronizer

CB

15 of 23

Fault monitor checks ex.

  • Node connectivity
  • Head tank water level, turbidity
  • Generator coil temps, bearing temps, over rev
  • Protection relays like OCR, OVR-UVR, UFR, …
    • C: Current, V: Voltage, F: Frequency

Check their values and run the fault sequence if needed.

15

But what if the fault monitor crashes?

16 of 23

Stop safely even if what happens 1

  • When the fault monitor crashes.

16

FM

FMM

Fault Monitor Monitor

FM

FMM

FMM detects it and

invokes `EmergencyStop` sequence

17 of 23

Stop safely even if what happens 2

  • When our app fails and a Nerves device fails.

17

Make heartbeats and monitors them with primitive devices.

When the beats stopped, invoke `EmergencyStop` circuit.

18 of 23

Off-site working

  • Test programs using Mox and Mock
  • Design system ⇔ read devices spec
  • Confirm devices behavior and write the program

18

test target�

ex)

needle valve

sequence

device’s mock

interface

19 of 23

On-site working

  • Integration tests
  • We faced several issues what we didn’t know off-site, ex.
    • the 3rd needle valve didn’t work due to an initial defect
    • the needle valve opening required to stabilize 1200rpm (before sync)
    • the delay between needle valve operation and water level response
  • What helped us,
    • Write code that is easy to change
    • mix upload.hotswap to change code on the fly
    • LiveDashboard metrics

19

20 of 23

  • Can replace the code on a running Nerves�without `mix upload firmware`

  • NOTE: The updated code is not persistent

  • We used this for�RPM hover logic / water level control logic …

20

PGC

21 of 23

  • Metrics tab

21

Processes tab

22 of 23

Our happy moment

22

23 of 23

Let’s keep building fun things with Nerves.

Thank you.

23