8-bit SAR ADC

An 8-bit instrumentation ADC using the Comp-DAC pin input mode operating as a SAR ADC.
Share this object
<

Overview

Content

Further reading - https://forums.parallax.com/discussion/174441/measuring-floating-pin-voltage-adc-from-just-the-built-in-comparator/p1

pub  sar_adc( pinnum ) : level | bit
' This routine makes use of the comparator's unloaded inputs
' to measure the floating voltage of the pin.
' Returns an unsigned 8-bit value in "level", GIO to VIO volts
'
  pinf( pinnum )
  level := 0

  repeat bit from 7 to 0
    wrpin( pinnum, P_LEVEL_A | ((level | (1<<bit)) << 8) )    ' set comparator DAC level
    waitus(2)                         ' DAC settle time is about 1.0 us
    level |= pinr( pinnum ) << bit    ' pin voltage higher than comparator's DAC

  wrpin( pinnum, 0 )    ' clean up

There are no downloads available for this object.

Leave a Reply