Shop OBEX P1 Docs P2 Docs Learn Events
Smart Pin Offset [Solved] — Parallax Forums

Smart Pin Offset [Solved]

JonnyMacJonnyMac Posts: 9,102
edited 2021-09-23 04:18 in Propeller 2

Full disclosure... I have a horrible headache and may not be thinking straight. I have a pin, we'll call it APIN (P33) and I want to use it as an ADC to monitor the voltage on P32. It seems like this would be the setup:

  pinstart(APIN, P_MINUS1_A | P_ADC | P_ADC_1X,  12-1, 0)

No joy. If I remove P_MINUS1_A and change APIN to 32, it works fine.

Comments

  • Silly me. Pin offsets do not work with analog circuitry.

  • evanhevanh Posts: 15,915

    And not just for the ADCs. All the low-level pin functions are separate from smartpins and cogs.

  • evanhevanh Posts: 15,915
    edited 2021-09-23 07:19

    Funnily, a revB silicon can do what you want via it's paired pin. That's the one, and only, difference between revB and revC parts.

  • RaymanRayman Posts: 14,641
    edited 2021-09-23 15:51

    You can monitor the analog voltage of another pin using offset.
    But, that other pin has to be put into ADC mode for it to work.

  • evanhevanh Posts: 15,915
    edited 2021-09-23 16:06

    Rayman's got a point. What is P32 already doing that you wanted to use P33's smartpin for monitoring it? P33 smartpin can happily be used to collect ADC bitstream from P32. But P32 has to be the ADC pin to measure the voltage on pin P32.

  • Background: I had never worked with the comparator mode and wanted to give it a try. I ended up jumping the two pins together; CPIN is setup as a comparator with a known threshold, APIN is setup as an ADC so I can read the input and then watch the comparator pin. Easy stuff, but I hadn't done it before. So that I don't have to lookup commands again, I made the dirt-simple object to set a pin as a comparator with a threshold (0..3300mv). We're going to use it in a JonyJib project to monitor the state of a camera tally light.

  • evanhevanh Posts: 15,915
      threshold := 0 #> (255 * threshold + 1650) / 3300 <# 255      ' convert to byte, with round to nearest
    
  • evanhevanh Posts: 15,915

    Cool, yep, thought it would be along those lines. The low-level pin functions only have a single input path into the cogs/smarptins, therefore can only support one function at a time. Jumpering the pins together externally is best solution.

  • Good idea to round-up. I changed the conversion to

      ' convert threshold to byte (with round-up)
    
      if (threshold <= 0)
        threshold := 0
      elseif (threshold >= 3300)
        threshold := 255
      else
        threshold := (255 * threshold + 1650) / 3300 
    
  • evanhevanh Posts: 15,915

    :) I used the technique a lot a long time ago (the wrapping machines again). I'd not used it much in recent years until someone recently asked why Spin2's muldiv64() wasn't very precise with an example. I showed how it was just the rounding. I made for him a round to nearest version, that I named muldiv65(). and since then I've been using the technique quite a lot myself. Eg: https://forums.parallax.com/discussion/comment/1528983/#Comment_1528983

Sign In or Register to comment.