Saturday, 18 May 2019

Monitoring Single Pole Switch

Summary
This post illustrates how a single pole switch contact can be monitored using a microcontroller which provides a pulsing output and corresponding monitor inputSimilar to a previous postmultipole switch debounce, a PSoC CY8CKIT-049 42xx development board was utilised with an external switch.


Single Pole Switch Pulsed Output / Input
Single Pole Switch Pulsed Output / Input
 
Manufacturers of safety equipment such as Pilz, Leuze and Honeywell use more comprehensive redundancy and self-checking techniques which use a variant of the pulsing output. Additional reading relating to the pulsing implemented by safety equipment manufacturers is available in technical documentation such as that from NHP, Allen-Bradley or even National Instruments to name a few.

The technique implemented in this post is an example for  the hobbyist. For more advanced safety implementation, a dedicated safety PLC or External Device Monitoring (EDM) solution should be considered.

Monitoring
Monitored inputs are commonly found in safety critical components or systems however these are rarely used in hobbyist designs. The hardware used by a hobbyist, as with any device, is prone to mechanical failure or wiring issues. Assuredly providing basic signal monitoring can assist in fault diagnosis. For this blog, shorts between cables carrying signals and power rails can be detected using pulsed signals. Furthermore false activation in such a failure is significantly lessened.

Pulsing Described
In this example pulsing refers to a fixed frequency, series of pulses with a predefined duty cycle. For ease in generating those pulses in an electronic circuit, the shape of the pulse usually represents rapid changes between two potentials as shown below.
Pulsing Signal Example
Pulsing Signal Example
 
Output Implementation
Regardless of the processor type, implementing a pulsing output is usually a novel task using a timer. For the PSoC processor a PWM component was utilised to generate the pulsing output.


PSoC PWM Component
PSoC PWM Component
 
The PWM component was configured to produce a 50% duty cycle output. Shown below is the waveform produced at the output pin (P2_6).


PSoC PWM Component Output
PSoC PWM Component Output
 
Input Implementation
For debouncing and verifying the input pulse, a number of active components were used in the design although there are other solutions which may achieve a similar result.


Debounce and Pulse Detection
Debounce and Pulse Detection
 
The input pin (P2_4), which would usually be driven from the pulsed output, is passed through a glitch filter for the purposes of removing any unwanted noise or signal bounce. The filtered signal is then output to two components, an edge detector and a timer.

Using the edge detector a rising edge pulse generates a short pulse to drive the set pin of a SR flip flop. The flip flop output then remains true until the reset input is activated.

The timer is configured so a rising edge starts the timer counting and a falling edge reloads the timer count value. With the timer count value being greater than the input pulse width, the one shot timer is constantly reset when connected to a pulsing signal. When the pulsing signal is removed the timer expires and reset the flip flop.


Timer Configuration
Timer Configuration
 
If the input signal is not pulsing the SR flip flop may be triggered from a bouncing signal but is subsequently reset. The reset of the flip flop is a result of the timer expiring, caused by the timer not being reloaded on a falling edge.

Input Signal (Pulsing)
Shown in the image below are the typical signals when the pulsing output is first connected to the input.

The yellow trace (CH1) displays the input pin with the 50us high, 50us low signal.

Shown in the pink trace (CH4) is the output of the glitch filter. As the input signal is without any bounce the input pulse passes through glitch filter with the delay defined in the component which in this design was 40us.

When a valid rising edge has been detected after the glitch filter the edge detector generated a short 10us pulse, as shown in the green trace (CH2).

The blue trace (CH3) is the output of the timer compare which is not active due to the pulsing signal being active.



Waveforms for Pulsing Input Signal
Waveforms for Pulsing Input Signal

Input Signal (Non-Pulsing)
Shown in the image below are the typical signals when a non-pulsing signal is first connected to the input.

The yellow trace (CH1) shows when a voltage was applied to the input.

Some 50us later the glitch filter provides its output as shown in the pink trace (CH4).

A valid rising edge is detected from the glitch filter as shown in the green trace (CH2).

After the rising edge from the glitch filter starts the timer there is no subsequent falling edge to reload the timer. As a result the timer expires, as shown in the blue trace (CH3) causing the flip flop to reset.


Waveforms for Non Pulsing Input Signal
Waveforms for Non-Pulsing Input Signal
 
Final Thoughts
The example provided in this blog is by no means ideal, however it is an example of what can be achieved with a smattering of logic components and a timer.

False triggering resulting in a latched output is possible in this example using a non-pulsed signal. Other solutions may benefit from less or no false triggering although the reaction time may be slower. As always, the importance of each factor is part of the design consideration.

On the matter of device resources, the example implementation for the Cypress PSoC requires around 20% of the UDB resources making for heavy device utilisation. Certainly a component such as the glitch filter could be implemented outside the PSoC with passives and a Schmitt trigger.

Downloads
The PSoC Creator 4.2 project for the example in this blog was saved as a minimal archive.

Mutlipole Checker PSoC Creator 4.2 Project
Single Pole Switch Monitoring PSoC Creator 4.2 Project

Sunday, 5 May 2019

Multipole switch debouncing PSoC

Summary
This post looks at a solution using PSoC components to debounce a multipole switch. For testing, an industrial roller lever switch from German switch manufacturer Bernstein was used with a Cypress CY8CKIT-049 development board.


Bernstein Switch
Bernstein Switch
Single pole vs Multipole 
Single pole switches and buttons are commonly used in applications which are non-critical, require no redundancy or have no specific safety requirement. Consider examples such as the reset button on the Cypress CY8CKIT-049 development board or the light switch in a house.

The multipole switch usually contains multiple contact options for various industrial applications. The contact options are Normally Open 'NO' and Normally Closed 'NC' with various brake and make, effectively open and close, options. Consider an example such as the changeover switch for an electric railway signal box or the end stop switch on a gantry crane.

Signal Bouncing
Multipole switches may use the same mechanical actuation design as their single pole counterparts which gives rise to similar signal characteristics. One difference however is that the contacts in a multipole switch may not actuate at the same time.


Bernstein Switch PSoC Test Setup
Bernstein Switch PSoC Test Setup
The test setup in the image above shows the connections between the CY8CKIT-049 development board and the Bernstein switch. Both contacts use a 5V DC supply.


Multipole Switch with Bounce
Multipole Switch with Bounce
Shown in the capture above are the NO and NC contacts of the Bernstein switch when actuated. No bounce is shown for the NC signal (Yellow channel 1) as it switches OFF and the NO signal (Green channel 2) shows signal bounce for less than 5msec as it switches ON.

To remove the unwanted bounce in this design without using external filtering or other components, the two switch signals were debounced in the PSoC using digital 'components' built from Cypress termed Universal Digital Blocks (UDB).

Simple Multipole Glitch Filter (PSoC)
Simple Multipole Glitch Filter (PSoC)
In the example above the Glitch Filter component was used to debounce the two input signals from the switch. The outputs of these filters was combined to drive the on-board LED. For illustrative purposes the filters were not been combined into a single component with a bus.

The filter component was configured for 20ms for both filter components.


Glitch Filter Configuration
Glitch Filter Configuration
Running the example project in the PSoC development kit produces a clean debounced waveform as shown in the capture below. Note the 20ms delay between input and output waveforms.


Multipole Switch Debounce Turn ON
Multipole Switch Debounce Turn ON
The connections for channel 1 and 2 to the switch remain the same as the previous capture. The additional connections for Blue channel 3 show the filtered NO signal and the Pink channel 4 shows the NC signal.

Shown below is the turn OFF waveforms.


Multipole Switch Debounce Turn ON
Multipole Switch Debounce Turn OFF
Fault Blocking
The dual pole switch in this example uses contacts, which in resting condition, are in the opposite state. The addition of another gate and an enable control to the output LED connections provides some fault detection. That is, the two inputs must be in opposite states for the LED to be active.


Simple Multipole Glitch Filter with Fault Detection (PSoC)
Simple Multipole Glitch Filter with Fault Detection (PSoC)

Final Thoughts
Debouncing multipole switches with a PSoC can be achieved using only a digital solution (UDB). The filter components used in the solution require no code however some 25% of the available resources are utilised. Where practical, multiple switches with multipole contacts could be debounced using a suitable multiplexer.

Downloads
The PSoC Creator 4.2 project below with the glitch filters was saved as a minimal archive.
Mutlipole Checker PSoC Creator 4.2 Project
Multipole Checker PSoC Creator 4.2 Project