Measuring time-encoded signals

Measuring time-encoded signals

While we were making improvements to the Yocto-PWM-Rx for our previous post, we noticed that this device has considerably changed since its conception in order to cover more use cases than the once planned initially. To help you navigate into all these possibilities, we summarize in this post the different working modes.



Measuring pulse-width modulated (PWM) signals

The basic working mode of the Yocto-PWM-Rx is the measure of a signal encoded in periodical pulses of varying lengths. The frequency is usually constant, and the useful value is coded in the duty cycle, that is the ratio between the duration of the pulse and the duration of the whole period. In some rare cases, its the absolute duration of the pulse which encodes the transmitted value.

True PWM signal
True PWM signal


For this working mode, the Yocto-PWM-Rx can work with frequencies from 0.1Hz to 250kHz. The read value is refreshed 50 times per second. The expected input signal is a clear alternation of pulses with a regular frequency. The corresponding parameters are:

  • pwmReportMode: PWM_DUTYCYCLE or PWM_PULSEDURATION
  • debounce: 0 ms (disabled)
  • bandwidth: 16'000 kHz (i.e. 16 MHz, the default value corresponding to the maximum)

The configuration interface of the Yocto-PWM-Rx enables you to directly convert the decoded duty cycle into a corresponding physical value if necessary.

Measuring frequency-modulated (FM) signals

Some simpler sensors encode a value not in the duty cycle but directly in the frequency of the signal (frequency modulation). The Yocto-PWM-Rx can also decode this type of signal and provide an instantaneous measure of the frequency of a signal made of regular high/low alternations, but with a varying frequency.

FM signal
FM signal


For this working mode, the Yocto-PWM-Rx can also work with frequencies from 0.1Hz to 250kHz. The read value is refreshed 50 times per second. The corresponding parameters are:

  • pwmReportMode: PWM_FREQUENCY
  • debounce: 0 ms (disabled)
  • bandwidth: 16'000 kHz, in any case for frequencies above 25kHz. Below 10kHz, you can choose to lower the bandwidth to 1'000kHz, or even 100kHz, less for frequencies lower than 1kHz.

Measuring noisy frequency-modulated signals

When the measured signal comes from a mechanical contact such as a reed switch, you can't expect that it is made of regular alternations. At best, there will be high frequency rebounds, at worst there will even be multiple triggers, as described in our previous post. If the signal periodicity remains clearly visible thanks to the presence of stable flats during each period, the Yocto-PWM-Rx can still measure the frequency.

Complex periodic signal
Complex periodic signal


For this working mode, the Yocto-PWM-Rx can work with frequencies from 0.1Hz to 25kHz only. The read value is refreshed 50 times per second. The corresponding parameters are:

  • pwmReportMode: PWM_FREQUENCY
  • debounce: 0 ms (disabled)
  • bandwidth: typically 1'000 kHz. For a fundamental frequency below 2kHz, you can choose to lower the bandwidth to 100kHz, or even 10kHz or less for frequencies below 500Hz.

Note that you don't need to explicitly enable the measure of a noisy signal: it's the normal working mode of the module for signals up to a maximum of 25kHz.

Measuring the average frequency of irregular pulses

All the frequency estimations described above are computed on the basis of the measure of the period. Some applications based on the detection of near-random events, such as Geiger counters, generate irregular frequencies that are better measured by counting over a given time period. Therefore, you can also select a counting per second (CPS) mode, and a counting per minute (CPM) mode, the later actually being an estimate of the count per minute based on counting over the latter six seconds.

Slow pulses
Slow pulses


For this working mode, the Yocto-PWM-Rx can work with frequencies from 10CPM to 250'000CPS only. The read value is refreshed once per second. The corresponding parameters are:

  • pwmReportMode: PWM_CPS or PWM_CPM
  • debounce: 0 ms (disabled)
  • bandwidth: 16'000 kHz (i.e. 16 MHz, the default value corresponding to the maximum)


Note that at the request of users wanting to work with CPS and CPM units but using the instantaneous frequency estimation based on the measure of the period, there are two hybrid modes PWM_FREQ_CPS and PWM_FREQ_CPM which work exactly like PWM_FREQUENCY. The only difference is the unit used to express the measured frequency.

Counting high-frequency pulses

Sometimes, rather than measuring the pulse frequency, it is useful to only count the pulses. You can configure the Yocto-PWM-Rx as a pulse counter enabling you to measure pulses of a few hundreds of nanoseconds only. The module can count all the edges (increasing or decreasing), or each pulse.

Fast
Fast


The counter is reset to zero at module start up, and with the call to the reset() method. The read value is refreshed 50 times per second. The corresponding parameters are:

  • pwmReportMode: PWM_EGDECOUNT or PWM_PULSECOUNT
  • debounce: 0 ms (disabled)
  • bandwidth: 16'000 kHz (i.e. 16 MHz, the default value corresponding to the maximum)


Counting slow pulses

If you want to count slow pulses coming from an electromechanical relay or from a mechanical switch for example, you must enable the protection against rebounds, otherwise one single commutation can trigger several tens of micro-pulses. With the protection against rebounds, all the oscillations following an edge are ignored until the end of the debounce period.

Pulses with rebounds
Pulses with rebounds


The counter is reset to zero at module start up, and with the call to the reset() method. The corresponding parameters are:

  • pwmReportMode: PWM_EGDECOUNT or PWM_PULSECOUNT
  • debounce: 25 ms (typical value for a relay)
  • bandwidth: n/a kHz (ignored parameter, always 100kHz)


Counting noisy periods

In the same way that we allowed the frequency measure for noisy signals with frequency modulation, we added the possibility to count the number of detected cycles, independently from the number of edges. As for the frequency measure, this function is possible only for frequencies which do not go over 25kHz only.

The counter is reset to zero at module start up, and with the call to the reset() method. The read value is refreshed 50 times per second. The corresponding parameters are:

  • pwmReportMode: PWM_PERIODCOUNT
  • debounce: 0 ms (disabled)
  • bandwidth: 1'000 kHz typically. Below 10kHz, you can choose to lower the bandwidth to 1'000kHz, or even 100kHz, less for frequencies lower than 1kHz.


For all intents and purposes, you can also use the additional method get_edgesPerPeriod() to obtain the number of detected edges during the previous period. If the input signal is a noiseless frequency-modulated signal, the number of edges is of two. The noisier the signal, the higher will this number be.

Reading a debounced-state

You can also use the Yocto-PWM-Rx to simply read the input value, after applying the debounce filter.

The corresponding parameters are:

  • pwmReportMode: PWM_STATE
  • debounce: 25 ms (typical value for a relay)
  • bandwidth: n/a kHz (ignored parameter, always 100kHz)


Reading quadrature-encoded signals

Finally, you can also interpret conjointly the two inputs of the Yocto-PWM-Rx to decode the signal produced by a quadrature counter. It is a double frequency modulated signal, phase-shifted by 90 degrees, thus making it possible to differentiate the direction of rotation.

Quadrature-encoded signal
Quadrature-encoded signal


To use the quadrature decoder, the two PWM inputs can be set in any mode, but with the following settings:

  • debounce: 0 ms (disabled)
  • bandwidth: 16'000 kHz (i.e. 16 MHz, the default value corresponding to the maximum)

You must however enable decoding with the set_decoding() method on the quadratureDecoder object. You can then use the latter to read the counter value, or read the speed at which the counter changes. Note that the protection against rebounds is not pertinent for a quadrature counter, because quadrature encoding leads to an intrinsic cancellation of possible oscillations.

Conclusion

While not aspiring to replace a high-end digital signal analyzer, the small Yocto-PWM-Rx quickly provides the answer to many common scenarios of time-encoded binary signals analysis. If you factor in the fact that it supports a large range of input voltages (+/- 30V) and that its input is electrically isolated, it easily earns its place in the all-purpose tool drawer of the electronic handyman...

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.