← Back to notes

Board simulator: Example 6.1

The RenewableSwitchOver board running Example 6.1. The simulator runs the sketch's own logic, with the same whole-number sums, against a model of the RES, the battery, the MOSFET switches, the L298N and the pump. Change the RES and watch what the Arduino reads, how it switches the supply, and how the ramp keeps the pump current down.

Renewable source

t = 0.0 s

A solar panel or small turbine sags when it supplies current: this is how much.

Changes the sketch so startRamp() jumps straight to full drive: a direct start through the L298N.

Example 6.1: the sketch, as it runs

running now · ran in the last 2 s, fading · setup() or changeSupply(): a decision that just happened. loop() runs once every millisecond; it reads the RES on one pass in 100. Press a Step button to pause and step through one pass at a time (▶ Run carries on), or use slow motion.

Graphs

Graphs ▾

Analogue input: A0 reading

on the RESon the battery491 / 552 thresholds, dead band shaded

RES voltage at J3

open circuitat the terminals, sagging under load

Pump drive: PWM duty and pump voltage

level as a duty cycle (%)average pump voltage (V)

Pump current through the L298N

pump currentL298N limits: 2 A continuous, 2.5 A peaks

Scope: the PWM now (3 periods, about 6 ms)

IN3 (D3): the pump is driven while it is LOWvoltage across the pump

The board

RESQ4 via D13
BatteryQ3 via D12
D4 Renew OND3 Battery ON
PinNetNow
A0AnalogIn
D13renewableOn
D12batteryOn
D3InC (IN3)
D2InD (IN4)
D4Enable

Variables

onBattery
level
rampFrom
time since rampStartMs
last reading
kToBattery / kToRes

What happened

The sketch prints nothing: this log is the simulator's commentary on what each decision did.

The model

Battery 12 V; diodes D1/D2 drop 0.8 V; the L298N drops 1.8 V; pump winding 2 Ω, 0.8 A running at full speed, load rising with the square of its speed. The divider is set so A0 sees 0.300 of the RES voltage, as kRatioPermil = 300 assumes. Readings jitter by ±1 count.