Using MIAC to keep us safe

Here at Matrix we are very proud of the fact that we manufacture many of our products right here in our own factory.  I’ve been working here for about eight years, and in that time, our manufacturing capability has grown from just me hand soldering Locktronics carriers in the corner of a store room, to a team of half a dozen technicians with access to drilling, milling, laser cutting, and surface mount PCB manufacturing facilities.  Part of my job is to commission new production machinery and to work closely with the rest of the team to ensure that everyone can use the new machines as safely as possible.  Our latest new bit of kit is a CNC milling machine, which we’ll use to improve the quality of our Locktronics and Automatics products. However, installing such a powerful new machine presented us with a few challenges before we could begin using it in earnest!


The machine we bought suited all of our technical requirements perfectly – as you can see from the photo, it’s very sturdy, and although we’ll use it mostly for plastic parts, it could potentially sculpt 3D shapes from aluminium.  Of course, such a machine could also do some rather nasty “3D sculpting” of body parts if there were an accident – and the machine came “out of the box” with no safety features installed!   In particular…

  • We bought the machine with no enclosure of any kind.
  • The spindle (cutting part of the machine) cannot be controlled either by programming the tool path, nor from the remote control handset – it just went at a fixed speed that could only be set on the machine itself..
  • There are no “interlock” switches on the machine.  These are commonly fitted to machine tools to ensure that the machine is fully safe before it can be powered; or to prevent locked enclosures from opening while the machine is still active.

This is quite normal, as every machine shop has different needs, and, as a provider of machine control solutions to industry, with a development office full of talented engineers (and plenty of cool gadgets), we figured that we could modify the machine ourselves to meet the particular safety needs here at Matrix.

Following our risk assessment, we distilled our requirements down to the following…

  • The machine should be fully enclosed while working.
  • The spindle (motor for the cutting tool) should not start until the enclosure is safely closed.
  • The enclosure should remain locked until the spindle has stopped (this can take nearly a minute!).
  • The motors controlling the cutting head’s position must remain active at all times to enable setting up of jobs.  (It requires both hands to use the remote controller, so we were confident that the position could not change while the operator had their fingers anywhere dangerous!).

The next stage was to research the components of the machine’s control hardware to see what inputs and outputs we might be able to interface with.  I can’t imagine how I’d have done this without the internet – at one point I was having to draw (no doubt hilariously inept) approximations of Chinese characters into image recognition software so that I could decipher error messages!  But in the end, I found just what I was looking for – a connector on the spindle’s power inverter with pins corresponding to the two vital functions we needed…

  • Remote spindle speed control.  This is operated by a simple DC voltage between zero (motor stop) and 10V (top speed – about 4000rpm).  This is a bit of a bonus, just being able to turn it on and off would suffice for our safety system – but spindle speed is very critical to the quality and efficiency of cutting, and this would give us a way to safely alter the speed without exposing the machine.
  • Actual speed output.  Finding this was the real “Eureka” moment.  In any safety critical system, it is very important to have “closed loop” control.  When the machine is commanded to perform an action, we must have a way to check that the action succeeded – if we were to command “stop the spindle”, but there was a fault that prevented this, it would leave the machine in an unsafe state.  It also takes quite some time for the spindle to speed up and slow down, and the machinist may not be able to see or hear whether the spindle is running or not – being able to sense that the machine really is safe allows us to control a locking mechanism that ensures that there can be no mistakes,


As the machine also requires a very noisy extractor unit and cooling pump, we decided to simply build a small partitioned off cubicle in one corner of the machine room – with the machine controlled remotely by a handset outside the doors.  This means that the machine has plenty of room around it to ease setup and maintenance, and operators are shielded from most of the noise.  A large acrylic window in one side and the acrylic panelled doors allow the operator to keep an eye on the machine while jobs are running.

To keep the enclosure locked, I chose electrically operated magnetic locks.  These amazed me – it only takes around 0.5 A at 12 V for one of these to have a holding force of nearly a ton – the door itself would break well before the lock separated.  As mentioned before, having a “closed loop” is very important for safety, and these locks also incorporate a sensor that ensure that the lock is truly engaged.  For less than £50 each, a very cost-effective solution.


When choosing a control system, I was rather spoiled for choice!  I could easily have used e-blocks, an ECIO, or one of our Raspberry Pi or Arduino extension boards.  But luckily (I’m not the most decisive of chaps!), one contender stood out immediately.  The MIAC (Matrix Automotive & Industrial Controller) is a perfect fit for a job like this; it has eight digital/analogue inputs, relay outputs, transistor outputs with PWM, a display and plentiful control buttons – all neatly encased in a sturdy “top-hat” rail mounting box with screw terminals.  It also has protective circuitry to ensure that it keeps on doing its job even if there is a fault in the rest of the system – a safety system is no use at all if it crashes whenever something potentially dangerous happens!

The hardware system is very simple.  As you can see from the circuit diagram, there are very few external components – so few in fact, that I just used a scrap of Veroboard to build the circuit.  The only other components were a handful of screw terminals, so that the main installation would need little more than a wire stripper and a screwdriver.

Circuit Diagram

At the top of the diagram, you can see the circuitry for the locks.  Relay Q1 of the MIAC turns power on and off for both locks – the relays can handle several Amps, so two 0.5 A locks are no trouble.  The switch sensors also have relay outputs, the positive power rail is fed via both sensors in series to MIAC input 1 – a 10k resistor connects the input to ground to ensure that there is a very definite “off” condition if either lock fails.

The interface to the power inverter is a little more interesting, as we can see if we compare the inputs and outputs that need to be connected.

  • MIAC output (to set the speed) can only be digital (possibly PWM)  ->  Inverter takes a DC voltage.
  • Inverter speed output is PWM  ->  MIAC inputs can be either digital or analogue.

So for the speed control signal, we definitely have to translate between two different types of signal – and possibly for the speed sensor signal too.  To do this, we first need to know what one of these mysterious “PWM”s look like.

PWM means Pulse Width Modulation.  A PWM signal is digital – it can only be on or off.  The signal usually turns on and off at a fixed rate – a never ending series of “on” pulses, separates by “off” periods.  However, the length of each pulse can be varied, with the length representing some important value, such as the speed of a motor.  PWM is used in a huge variety of control systems – it’s the most primitive way of representing an analogue value using a digital signal.


Both the MIAC and the Inverter can generate PWM signals, so we don’t have to worry about how to make one – however, neither have a built-in way to turn PWM back into an analogue value, and doing so is a perfect example of how the same problem can be solved using tradition analogue circuitry or the bits and bytes of software.

Towards the bottom of the circuit diagram you can see the analogue hardware solution – nothing more than a single capacitor and a single resistor.  When we have a PWM signal that is half-on and half-off, we want an output voltage of about half the “on” value.  The capacitor acts as a ‘reservoir’ – when the PWM signal is on, the reservoir fills up, when the PWM signal is off, the reservoir empties.  The resistor controls how fast the filling and emptying can happen.  The longer the pulses, the more the resevoir fills, and the less it empties – so the output voltage ends up being in proportion to the length of the pulses.  This is a trick well worth remembering – very few microcontrollers have analogue outputs, and this is a really simple way to simulate them whenever precision is not critical.

The resulting voltage is passed to the inverter input (VR) via another of the MIACs relays.  This ensures that the capacitor is quickly discharged, and the DC voltage pulled to zero, as quickly as possible when shutting down.

The circuit for the speed sensor signal is nothing but a wire! – the PWM signal here will be decoded by the program running in the MIAC.  Naturally, for this, I’ll be using FlowCode!  A job like this perfectly highlights just how much time and effort FlowCode can save.  On many other platforms, we’d now be at the stage of setting up configurations, getting sub-components talking to each other, and all the other tedious housekeeping that comes before the interesting stuff.  Not here – the MIAC is a single FlowCode component – I simply open a new project using the MIAC target template, then drag a MIAC icon onto my system panel.  Once on the panel, the MIAC model is fully interactive – its display and buttons let me simulate my work in progress to ensure that the system is going to work before the hardware is even assembled.


To decode a PWM signal digitally, we need to constantly monitor the MIAC input pin to see if it is on or off, and keep a measure of each time period.  As the MIAC will also be handling inputs from the operator and the logic of the locking system, we need to ensure that the PWM measurement routine will always be measuring, no matter what else the MIAC may be doing at the time,  For this reason, the measurement is done using an interrupt routine.  An interrupt is an event that tells the controller to pause, call a special routine, then go back to whatever is was doing before.  In this case, we use an interrupt that fires automatically at very regular time periods (interrupts can also be fired by changes to input pins).  The timer for this is very fast and accurate, so measuring the pulse width is a simple matter of how many times the interrupt macro gets called while the input is high.  Some simple scaling of this value then tells us the true RPM of the spindle.


The rest of the MIAC program handles the actual logic of reading the control buttons, showing information in the display, and, of course, controlling the locks and machine so that everyone is safe.  I won’t try to describe all that here –  I hope this screenshot will show very nicely how FlowCode’s graphical flowcharts do a wonderful job of conveying the meaning of a program, even for us humble machinists!


The system sailed through its PAT testing, and has now been successfully turning out Locktronics carriers for a month or two – and we’re relishing the prospect of the new products it’ll make possible (and, of course, safely!).

Best wishes


3,137 total views, 6 views today

Leave a Reply