Smart Pin Offset [Solved]
JonnyMac
Posts: 9,102
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.
And not just for the ADCs. All the low-level pin functions are separate from smartpins and cogs.
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.
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.
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.
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
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