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
).
- Samples are queued continuously, and queue overruns are ignored.
- A moving average is maintained over the queue elements (the most recent N
samples), and this value is returned by
icp_rx()
. icp_rx()
does not 'consume' queue elements, so the queue never empties; two calls within a single PWM period will return the same value.
- Samples are queued in a circular fashion, and queue overruns are not permitted (new elements are thrown away).
- No smoothing (moving average) is performed.
icp_rx()
always returns the oldest queued item.- 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).