Shop OBEX P1 Docs P2 Docs Learn Events
Can the ADC be used in non-smartpin mode? — Parallax Forums

Can the ADC be used in non-smartpin mode?

roglohrogloh Posts: 5,168
edited 2020-10-30 03:32 in Propeller 2
During some MicroPython work I was reading through the P2 documentation and experimenting around with pins in different modes. It appears from this statement that the ADC may be enabled when OUT=1, implying you can somehow use it in this non-smartpin mode:
for smart pin mode off (%MMMMM = %00000):

             DIR enables output

             for non-DAC_MODE:
                 0x = OUT drives output
                 1x = OTHER drives output
             for DAC_MODE:
                 00 = OUT enables ADC, P[7:0] sets DAC level
                 01 = OUT enables ADC, P[3:0] selects cog DAC channel
                 10 = OUT drives BIT_DAC
                 11 = OTHER drives BIT_DAC

But if so, how do you read it? I've tried setting :

WRPIN to $148000 which enables the 990 ohm DAC at its midpoint, and

DRVH = 1<<Pin to enable the pin's OUT bit

I do see the pin's output is at the midway voltage level of 1.66V, but I don't see any activity with either RDPIN or the input bit of this pin, which both remain stuck at 0. Isn't the ADC meant to accumulate/report samples when OUT=1 or does the ADC do nothing unless the pin is in a real Smart pin mode (ie. MMMMM<>0)? How is it used here with MMMMM=0?

Update: Never mind, I think I got it working after trying the ADC mode without DAC. Somehow the DRVH operation in ADC+DAC mode didn't take effect properly the first time I tried it, I've repeated this a few times since and it seems to be toggling the read back pin input value for both ADC, and ADC+DAC modes. It appears it's just the raw bitstream you get back directly via the input pin and you'd have to average it's value over time yourself to use it, or otherwise use a Smartpin mode to accumulate highs to do it for you.




Comments

  • AribaAriba Posts: 2,682
    I think if you redirect the A input of an adjacent pin by -3..+3 you get the ADC bitstream of the selected pin if this pin is in ADC mode, so can use an adjacent pins ADC smartpin mode to evaluate the ADC value from the bitstream.

    Andy
  • Yeah okay, that could be handy if you didn't want to mess with the original pin's smart pin mode in any way and you have a free nearby pin.
  • evanhevanh Posts: 15,191
    rogloh wrote: »
    Update: Never mind, I think I got it working after trying the ADC mode without DAC. Somehow the DRVH operation in ADC+DAC mode didn't take effect properly the first time I tried it, I've repeated this a few times since and it seems to be toggling the read back pin input value for both ADC, and ADC+DAC modes. It appears it's just the raw bitstream you get back directly via the input pin and you'd have to average it's value over time yourself to use it, or otherwise use a Smartpin mode to accumulate highs to do it for you.
    Correct. Good example of the distinction between a pin config and a smartpin config.

Sign In or Register to comment.