Overview
- Object ID : 4442 (2024-03-06 09:26:57)
- Author : evanh
- Content : Code
- Microcontroller : Propeller 2
- Language : SPIN2
- Categories : Sensor, Signals
- Licence : MIT
- Tags : ADC, Instrumentation
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.