The Clock Extraction Problem: How Barcode Scanners Find Their Rhythm Without a Metronome |
Subtitle: A Deep Dive into Self-Clocking, Edge Timing, and the Art of Decoding Variable-Speed Scans - with Real-World Designs from Symbol, Zebra, Honeywell, Datalogic, Microchip, and NXP |

|
Opening Summary |
Imagine trying to read a piece of music written without a time signature, where the tempo changes constantly. This is exactly the problem that a barcode scanner's decoder faces. The scanner does not have a fixed clock that tells it how fast the barcode is moving past the photodetector. The scanning speed varies from scan to scan, and even within a single scan, as the user's hand accelerates or decelerates. The decoder must somehow extract the timing information from the barcode signal itself. This is the clock extraction problem. |
The solution is self-clocking. The barcode itself contains the timing information. The narrowest bar or space defines the fundamental unit of time - the 'module.' All other bar and space widths are integer multiples of this module. The decoder's task is to find this module width from the measured pulse durations and then use it as a ruler to measure all the other elements. |
This article is dedicated to the clock extraction problem. We will explore the concept of self-clocking, the algorithms used to estimate the module width, and the challenges of dealing with variable scan speeds. We will look at how major companies have implemented clock extraction in their products. We will see how Symbol (now Zebra) used a simple but effective technique in the LS2208, based on finding the shortest pulse. We will explore Honeywell's use of a more sophisticated histogram-based method to estimate the module width. We will examine Datalogic's use of a running-average technique to adapt to speed changes during the scan. We will also look at Microchip's and NXP's reference designs, which include detailed examples of clock extraction algorithms. |
By the end of this journey, you will understand that clock extraction is not a simple measurement but a sophisticated estimation problem that must handle noise, distortion, and speed variations. |

|
Full Article |
Section 1: The Clock Extraction Problem - The Need for a Ruler |
The decoder receives a sequence of pulse widths - the durations of the high and low states of the comparator's output. These durations are measured in timer counts (e.g., microseconds). But the decoder does not know the module width - the fundamental unit of the barcode. The module width is the width of the narrowest bar or space. It is the ruler that the decoder needs to measure all the other elements. |
The module width is not fixed. It depends on the scanning speed and the print quality. A faster scan produces a smaller module width. A slower scan produces a larger module width. The decoder must estimate the module width from the pulse widths themselves. This is the clock extraction problem. |
The clock extraction problem is challenging because the pulse widths are not perfect. They are distorted by noise, jitter, and variations in print quality. The decoder must be robust to these distortions. |

|
Section 2: The Self-Clocking Principle - The Barcode as a Clock |
The barcode is a self-clocking code. This means that the timing information is embedded in the code itself. The narrowest bar or space defines the clock period. All other bar and space widths are integer multiples of this period. |
The self-clocking principle is fundamental to barcode decoding. It allows the decoder to handle variations in scanning speed. The decoder does not need a separate clock. It extracts the clock from the barcode signal. |
The self-clocking principle is used in all major barcode symbologies, including Code 39, UPC, and Code 128. |

|
Section 3: Estimating the Module Width - The Shortest Pulse Method |
The simplest method for estimating the module width is the shortest pulse method. The decoder finds the shortest pulse in the entire sequence of pulse widths. This shortest pulse is assumed to be one module wide. The module width is set to the duration of this shortest pulse. |
The shortest pulse method is simple and effective. It works well when the barcode has at least one narrow element. The method is used in Symbol's LS2208 and in many other scanners. |
The shortest pulse method is vulnerable to noise. If a noise spike creates a very short pulse, the module width will be underestimated. To mitigate this, the decoder may use a median filter or a histogram-based method. |

|
Section 4: Symbol's LS2208 - The Shortest Pulse Method |
Symbol's LS2208 uses the shortest pulse method to estimate the module width. The decoder captures a complete sequence of pulse widths from the barcode. It then finds the smallest pulse width in the sequence. This smallest pulse width is used as the module width. |
The LS2208's module width estimation is robust enough for most hand-scanning applications. The scanner's designers have tuned the algorithm to handle the typical variations in scanning speed. |
Section 5: The Histogram-Based Method - A Robust Approach |
The histogram-based method is a more robust approach to estimating the module width. The decoder constructs a histogram of the pulse widths. The histogram is a bar chart that shows the number of pulses of each width. The histogram will have peaks at the module width, at twice the module width, and at three or four times the module width. |
The decoder finds the first peak in the histogram. This first peak corresponds to the module width. The histogram-based method is less vulnerable to noise than the shortest pulse method. The histogram averages the pulse widths, reducing the impact of outliers. |
Honeywell uses a histogram-based method in their imaging scanners. |

|
Section 6: Honeywell's Histogram-Based Module Estimation |
Honeywell's imagers use a histogram-based method to estimate the module width. The decoder constructs a histogram of the edge-to-edge distances (the pulse widths) from the captured image. The histogram is then analyzed to find the first peak, which is the module width. |
The histogram-based method is more computationally intensive than the shortest pulse method, but it is also more accurate and robust. Honeywell's use of the histogram-based method contributes to their scanners' excellent performance on low-quality barcodes. |
Section 7: The Running-Average Method - Adapting to Speed Changes |
The running-average method is a technique for adapting to changes in scanning speed during a scan. The decoder maintains a running average of the pulse widths. The running average is updated with each new pulse. The module width is estimated from the running average. |
The running-average method is useful when the scanning speed varies significantly during a scan. The decoder can adapt to the speed changes in real-time. |
Datalogic uses a running-average method in their industrial scanners. |

|
Section 8: Datalogic's Running-Average Module Estimation |
Datalogic's industrial scanners use a running-average method to estimate the module width. The decoder maintains a running average of the pulse widths. The running average is updated with each new pulse. The module width is estimated from the running average. |
The running-average method allows Datalogic's scanners to handle the rapid speed changes that can occur on conveyor belts. |
Section 9: The Module Width and the Barcode's Print Quality |
The module width is affected by the barcode's print quality. A poorly printed barcode has a larger module width variation. The decoder must be robust to the variations in print quality. |
The module width estimation algorithm must be able to handle the variations. The histogram-based method is more robust to print quality variations than the shortest pulse method. |

|
Section 10: The Module Width and the Scanning Speed |
The module width is inversely proportional to the scanning speed. A faster scanning speed produces a smaller module width. A slower scanning speed produces a larger module width. The decoder must estimate the module width from the pulse widths. |
The module width estimation algorithm must account for the scanning speed. The decoder does not need to know the absolute scanning speed. It only needs to know the relative module width. |
Section 11: The Module Width and the Distortion |
The barcode signal is often distorted. The distortion can be caused by print quality, scanning speed variations, or noise. The module width estimation algorithm must be robust to distortion. |
The histogram-based method and the running-average method are both robust to distortion. They average the pulse widths, reducing the impact of distortion. |

|
Section 12: The Module Width and the Noise |
The noise is a random variation in the pulse widths. The noise can cause the module width estimation to be inaccurate. The decoder must be robust to noise. |
The histogram-based method is more robust to noise than the shortest pulse method. The histogram averages the pulse widths, reducing the impact of noise. |
Section 13: The Module Width and the Jitter |
The jitter is the uncertainty in the edge timing. The jitter is caused by noise on the comparator's input. The jitter causes the pulse widths to vary. The module width estimation algorithm must be robust to jitter. |
The histogram-based method and the running-average method are both robust to jitter. They average the pulse widths, reducing the impact of jitter. |

|
Section 14: The Module Width and the Quantization Error |
The quantization error is caused by the timer's finite resolution. The timer counts in discrete steps. The quantization error is one timer count. The quantization error can affect the module width estimation. |
The quantization error can be reduced by using a higher-frequency timer. A 1-MHz timer gives a 1-microsecond resolution. A 10-MHz timer gives a 0.1-microsecond resolution. |
Section 15: The Module Width and the Histogram Peaks |
The histogram of the pulse widths will have peaks at the module width, at twice the module width, and at three or four times the module width. The decoder finds the first peak in the histogram. The first peak corresponds to the module width. |
The first peak is the smallest peak in the histogram. The decoder must find the first peak accurately. |

|
Section 16: The Module Width and the Histogram Bins |
The histogram is constructed by binning the pulse widths. The bins are intervals of pulse widths. The width of the bins determines the resolution of the histogram. A smaller bin width gives a higher resolution but requires more data. |
The bin width is typically chosen to be 1-2% of the expected module width. |
Section 17: The Module Width and the Histogram Smoothing |
The histogram can be smoothed to reduce the noise. Smoothing is done by averaging the adjacent bins. The smoothing reduces the impact of random variations in the pulse widths. |
The smoothing is typically done with a moving average filter. |

|
Section 18: The Module Width and the Histogram Peak Detection |
The decoder detects the peaks in the histogram. The peaks are the local maxima in the histogram. The decoder finds the first peak, which is the module width. |
The peak detection is done by finding the bin with the highest count. |
Section 19: The Module Width and the Histogram Threshold |
A threshold can be used to reject low-count bins. The threshold is a minimum number of counts per bin. The threshold removes the noise from the histogram. |
The threshold is typically set to a small fraction of the total number of pulses. |

|
Section 20: The Module Width and the Symbology |
The module width estimation is independent of the symbology. The module width is the fundamental unit of the barcode, regardless of the symbology. The symbology determines how the module widths are combined to form characters. |
Section 21: The Module Width and the Quiet Zone |
The quiet zone is a white margin before and after the barcode. The quiet zone is not used to estimate the module width. The quiet zone is used to detect the presence of a barcode. |

|
Section 22: The Module Width and the Start/Stop Characters |
The start and stop characters are special patterns that mark the beginning and end of the barcode. The start and stop characters are not used to estimate the module width. They are used to identify the symbology. |
Section 23: The Module Width and the Checksum |
The checksum is not used to estimate the module width. The checksum is used to verify the decoded data. |
Section 24: The Module Width and the Decode Security |
The 'Decode Security' setting in Honeywell's scanners is related to the module width estimation. The Decode Security setting adjusts the decoder's tolerance for variations in the module width. A lower setting is more tolerant, a higher setting is more strict. |

|
Section 25: The Module Width and the Minimum Contrast |
The 'Minimum Contrast' setting in Datalogic's scanners is not related to the module width estimation. The Minimum Contrast setting specifies the minimum signal amplitude. The module width estimation is based on the pulse timing. |
Section 26: The Module Width and the ROI Threshold |
The 'ROI Threshold' in Datalogic's scanners is not related to the module width estimation. The ROI Threshold specifies the minimum contrast in the region of interest. The module width estimation is based on the pulse timing. |
Section 27: The Module Width and the Object Sense Mode |
The 'Object Sense' mode in Datalogic's scanners is not related to the module width estimation. The Object Sense mode is used to detect the presence of an object. |
Section 28: The Module Width and the Derivative-Based Threshold |
MicroVision's derivative-based threshold is not directly related to the module width estimation. The derivative-based threshold is used to improve the comparator's decision. The module width estimation is done after the comparator. |

|
Section 29: The Module Width and the Static/Dynamic Threshold |
MicroVision's static/dynamic threshold is not directly related to the module width estimation. The static/dynamic threshold is used to improve the comparator's decision. The module width estimation is done after the comparator. |
Section 30: The Module Width and the Ternary Barcode System |
The ternary barcode system uses two thresholds. The module width estimation is still used, but it is applied to the three-level signal. The module width is the narrowest pulse, regardless of the level. |
Section 31: The Module Width and the 2D Ternary Barcode System |
The 2D ternary barcode system uses the same module width estimation technique. The module width is the narrowest pulse in the two-dimensional signal. |

|
Section 32: The Module Width in Texas Instruments' TIDA-00857 |
Texas Instruments' TIDA-00857 reference design uses the shortest pulse method to estimate the module width. The design includes a code example that demonstrates the algorithm. |
The TIDA-00857's module width estimation is a simple, effective technique. |
Section 33: The Module Width in Analog Devices' Reference Design |
Analog Devices' reference design uses a histogram-based method to estimate the module width. The design includes a detailed description of the algorithm. |
The histogram-based method is more robust than the shortest pulse method. |
Section 34: The Module Width in Microchip's Reference Design |
Microchip's reference design uses a histogram-based method to estimate the module width. The design includes a complete code example for Code 39, UPC, and Code 128. |

|
Section 35: The Module Width in NXP's Reference Design |
NXP's reference design uses a histogram-based method with a DMA engine. The DMA engine offloads the edge capture, and the CPU performs the histogram analysis. |
Section 36: The Clock Extraction Problem - A Summary of Best Practices |
Based on our exploration, let us summarize the best practices for solving the clock extraction problem: |
1. Use a Self-Clocking Code: All barcode symbologies are self-clocking. Use this property to extract the timing from the signal itself. |
2. Estimate the Module Width: The module width is the fundamental unit of the barcode. Estimate it from the pulse widths. |
3. Use a Robust Method: The shortest pulse method is simple but vulnerable to noise. The histogram-based method is more robust. The running-average method adapts to speed changes. |
4. Consider the Scanning Speed: The module width varies with scanning speed. The estimation algorithm must account for this. |
5. Consider the Print Quality: The module width varies with print quality. The estimation algorithm must be robust to print quality variations. |
6. Consider the Noise: The noise can affect the module width estimation. Use a method that is robust to noise. |
7. Test the Algorithm: The clock extraction algorithm must be tested with a variety of barcodes, under a variety of conditions, to ensure it is working correctly. |

|
Final Summary |
The clock extraction problem is the challenge of extracting a timing reference from the barcode signal itself. The solution is self-clocking. The barcode contains the timing information in the form of the module width - the narrowest bar or space. The decoder must estimate the module width from the measured pulse widths. |
We have seen how major companies have implemented clock extraction in their products. Symbol's LS2208 uses the shortest pulse method. Honeywell uses a histogram-based method. Datalogic uses a running-average method. Microchip and NXP provide reference designs with detailed clock extraction algorithms. |
The clock extraction problem is a fundamental challenge in barcode decoding. The module width estimation is the key to unlocking the barcode's data. The module width is the ruler that measures all the other elements. Without a reliable module width estimation, the decoder cannot accurately decode the barcode. |