Compact Algorithm Filters 16 Digital I/O Signals In Emebbed Systems

Sept. 18, 2000
This idea presents a piece of firmware that has proven to be both compact and extremely useful in several field applications involving embedded controllers. The concept originated when one of our embedded-system customers had problems in...

This idea presents a piece of firmware that has proven to be both compact and extremely useful in several field applications involving embedded controllers.

The concept originated when one of our embedded-system customers had problems in the field with a programmable indexer for a stepping motor. It turned out that an inverter mounted into the main electrical box was emitting significant electrical noise. This noise emission was so powerful that it would occasionally activate the digital input of our indexer.

What the customer requested was an increase in the time constant of the filter on the indexer board. Due to the physical dimensions of the required capacitor, however, this was impossible. Another option was to increase the software filtering. But while a large filter time constant was acceptable for this client’s application, it wasn’t suitable for all installations.

Writing a filter routine would be the ideal solution. It would have to be small, fast, and programmable for a range of values that customers could adapt to their applications. A small but quite powerful routine resulted.

Using a time constant ranging from 1 to 16 ms, the algorithm (implemented in assembly on an MC68332-based embedded system) filters 16 digital inputs. Listed below is the algorithm’s goal:

  • Set the n-th bit of exit_input_status if and only if all n bits of the filter_body elements are logic-one.
  • Reset the n-th bit of exit_input_status if and only if all the n bits of the filter_body elements are logic-zero.
  • In all other cases, the contents of exit_input_status are left unaltered.

Algorithm operations:

The algorithm defines a buffer of 16 unsigned 16-bit integers (UINT16) as a filter shift register, a 16-bit integer (UINT16) to store the previous filtered status of the input, and an unsigned 8-bit byte (UBYTE) to store the time constant of the filter as follows:

Ram definition:
UINT16 filter_body (16)
UINT16 previous_state
UBYTE filter_time_constant

Algorithm operations for a 16-ms time-constant:

  1. AND the entry_input_status and each of the filter_body elements
  2. OR the entry_input_status and each of the filter_body elements
  3. XOR the result of #1 and #2
  4. NOT the result of #3
  5. OR the result of #1 and #3
  6. AND the result of #2 and #4
  7. AND previous_state and result of #5
  8. OR the result of #7 and #6
  9. Save result of #8 into previous_state
  10. Shift all filter_body elements down by one position to push out the oldest input reading from the filter and insert the newest input reading.

To accomplish this functionality in my MC68332 embedded system, the routine shown in the listing is called every 1 ms.

Sponsored Recommendations

What are the Important Considerations when Assessing Cobot Safety?

April 16, 2024
A review of the requirements of ISO/TS 15066 and how they fit in with ISO 10218-1 and 10218-2 a consideration the complexities of collaboration.

Wire & Cable Cutting Digi-Spool® Service

April 16, 2024
Explore DigiKey’s Digi-Spool® professional cutting service for efficient and precise wire and cable management. Custom-cut to your exact specifications for a variety of cable ...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!