3.2 Analog Input vs Digital Input

The demodulator may be used on PWM streams representing either analog or digital data. While the PWM pulses per se have no notion of representing digital or analog data, there are subtle differences in the way the samples are processed. In the application note, this is controlled using a C preprocessor symbol (ICP_ANALOG).

Analog samples are presumed to represent relatively smooth, though possibly noisy readings, and are presumed to arrive continuously, where the most recent values are taken to be the most important. Thus, when the demodulator is configured for analog data:
  1. Samples are queued continuously, and queue overruns are ignored.
  2. A moving average is maintained over the queue elements (the most recent N samples), and this value is returned by icp_rx().
  3. icp_rx() does not 'consume' queue elements, so the queue never empties; two calls within a single PWM period will return the same value.
Digital samples are treated as distinct, ordered items, with no relevance to one another. Thus, when the demodulator is configured for digital data:
  1. Samples are queued in a circular fashion, and queue overruns are not permitted (new elements are thrown away).
  2. No smoothing (moving average) is performed.
  3. icp_rx() always returns the oldest queued item.
  4. Each call to icp_rx() 'consumes' a queue element. If the queue is empty, an 'idle' indicator (100% duty cycle) is returned.

These are the only differences between the two schemes. Some applications, which use PWM for analog data might yet prefer that data be handled according to the rules for 'digital' data (the reverse however may not be possible).