arduino

Watchdog 

Like a junkyard-dog, but quiet. 

Table of Contents

All dangerous complex control systems need a watchdog to make them safe if things go wrong. Pinball machines are a fire hazard; bespoke pinball machines even more so.

What does a Watchdog do?

Basically it looks at things and either makes a noise when it sees something it does not like, or does something, like attack potential thieves, or in my case, shuts down the power to the not-yet-smoking pinball machine. It’s also good at reducing the chance of blowing up electronics or burning out coils.

I mentioned in Visual Current Limitation Device (VCLD) and in First Decisions (Buried in a footnote), that I had some troubles with MPF crashes and coils left on. Basically:

…OPP coils enabled directly by MPF won’t disable if MPF crashes, but will, if their current is sufficiently high, sit there and burn away. You can’t rely on OPP disabling coils if MPF fails. Autofire coils are shut down, but explicitly enabled coils are not. This may feel like a bug, but it is part of the design of OPP.

This made me bring-forward my watchdog design, so I could trust it to turn the coil power off if MPF fails.

In selecting a microcontroller for the watchdog (and most other projects), I could have picked from oodles, including the STM32 that OPP uses. I narrowed the selection down to those that were cheap, well supported, could use MicroPython and C (if needed) as well as an Arduino development environment, and had to have quick development times, because I’m making a pinball machine, not a computer-science project, so minimal debugging.

I also want the chip on a carrier board or module, because I have a life.

Why MicroPython and C?

Great question, MPF uses Python, and if i have to start working outside MPF, there is an opportunity for common code use between MPF and my microcontrollers. C (sharp and flat) because that is the way to fast I/O.

Why Arduino?

It looks a lot like C, and development time is quite short, because it’s designed for novices and tolerates a lot of badly formed code. And there are gazillions of people willing to help. And anybody who want to borrow my code will likely be using Arduino.

Selection

UnitPriceSpeedNote
Raspberry Pi Pico 2040CheapFast2 cores.
Some other 2040ExpensiveFast2 cores.
Arduino (any genuine)ExpensiveSlow 
Arduino (any clone)MidSlow. 
Arduino (ATTiny)MidSlowTiny memory.
STM32 seriesCheapFastComplex development environment.
ESP32MidFastCommon
Lots of others~~There were plenty I discounted out of hand, mainly because I had never used them.

Notes: Cheap is less than $6, Mid is < $10, anything over that is expensive.

So I selected the Raspberry Pi Pico 2040 because it is fast, cheap, available from a shop in easy driving distance, and has 2 cores – very handy for watchdogs.

2040.
2040.

In keeping with overarching goal #4, Economy I didn’t buy expensive breakout boards, but made one from project board and headers from China.

project-board.
project-board.

Watchdog Hardware

Here is a video of MPF driving an OPP board, connected to a MOSFET board, driving a Gottlieb relay. The 1 second pulse is monitored by the watchdog.

MPF

 
Technical stuff only interesting to people interested in using MPF

This is for version 5. MPF now have version 6 config files, and there are differences :-)

In coils.yaml

coils:
c_watchdog_sti_0:
number: 0-0-0
default_pulse_ms: 8
tags: Watchdog-0

In config.yaml

show_player:
mode_attract_started:
watchdog0: 

shows:
watchdog0:
- time: 0
coils:
c_watchdog_sti_0: pulse 1s # Number is ignored

Arduino

This is the pseudo-code for the watchdog. The WiFi was a later addition, and allows the watchdog to be reset without prying the machine open.

Application: Watchdog
Type:
Version: V2, wifi
Works: Yes
Works with:
Pcode:

Very fast loop through things we monitor and remember if they
are good or bad. Remember if we have seen a high and if we have
seen a low for our watchdogs. Seeing a high and a low in a cycle
means watchdog is working. Flag as Ok.

Within the loop, every cycle that is longer than a watchdog
period, check the goodness of our flags. For watchdogs, only
take notice of their status if there has been one cycle of the
watchdog - otherwise assume the watchdog has not started yet.

When we detect the first watchdog transition, enable the cyclic
monitoring and coilpower relay.

When cyclic monitoring is enabled, if the watchdog ceases,
uControler and coilpopwerr relay are disabled.

High temp is checked every loop.

A web server is provided with credentials from arduino_secrets.

What it does

So basically, the watchdog does nothing after it’s turned on, except run its web page and wait till it sees something from MPF.

When it sees a signal from MPF, it turns the coil power on.

It then looks for a pulse from MPF every second. If it does not get one, it turns the coil power off and goes into a shutdown state; which can be reset by a power cycle, or through its web interface.

It also monitors temperature, not well, but adequate. It will shut off power around 50 degrees Celsius on the chip; I’ll still be playing up till then :-)

Future

There is plenty of I/O and compute left over, so I’ll add the rest of the power supply supervisory functions to it, basically turning on and off all the different things, and ensuring the different voltage rails have the volts they need. I might even run an attract mode out of it so I can shut down the rest of the electronics to save energy.

Diagrams

I’ve changed my layer design, I hope it’s the last time I make a change.

  1. CONTROLLER SOFTWARE - Where the game rules live.
  2. IO PROCESSOR - The device that connects to switches, solenoids, lights, etc.
  3. SUB-PROCESSORS - devices connected to IO PROCESSOR, watchdog and mechanism controllers, etc.
  4. I/O HARDWARE - This is what I call transisters, SCRs, MOSFETS, Relays and Switches, etc. Relay logic for the old school and electromechanical pinball fans.
  5. PINBALL HARDWARE - Drop Targets and such.
Five Levels Of Control With Watchdog.
Five Levels Of Control With Watchdog.

Alert
UPDATE