Reading the output state of a smartpin
ManAtWork
Posts: 2,176
in Propeller 2
Is it possible to read back the current logical state of a smart pin? I need multiple PWM output pins where the Y values are written by cog A. With a second cog B I'd like to process analogue feedback. I have to establish a blanking time when the ADC input samples are ignored for several µs after a state change of a PWM output to suppress switching noise and to allow settling of the SINC filters.
My idea was to monitor the PWM pin states and compare them to their last values in my ADC polling loop. If the states differ I set a counter and the next N values are ignored. However, this doesn't work (directly) because for smart pins the IN value reflects the event bit and not the pin state. Is there a possibility to bypass this without wasting an extra pin (and use the -3..+3 source selector)?
I need many pins, 4 PWM and 4 ADC pins per motor for each of 4 motors means 16 PWM and 16 ADC pins. Wasting another 16 for feedback is something I'd like to avoid. I could "emulate" the PWM counter and calculate the transition times in software but that doesn't look "smart" at all.
My idea was to monitor the PWM pin states and compare them to their last values in my ADC polling loop. If the states differ I set a counter and the next N values are ignored. However, this doesn't work (directly) because for smart pins the IN value reflects the event bit and not the pin state. Is there a possibility to bypass this without wasting an extra pin (and use the -3..+3 source selector)?
I need many pins, 4 PWM and 4 ADC pins per motor for each of 4 motors means 16 PWM and 16 ADC pins. Wasting another 16 for feedback is something I'd like to avoid. I could "emulate" the PWM counter and calculate the transition times in software but that doesn't look "smart" at all.
Comments
But that one pin could cycle through its six neighbors
Then I have to pre-calculate the blanking windows and run a software counter to track the PWM state. Shouldn't be too complicated although I have hoped to get rid of that cycle-counting with the P2 smart pins.
Thanks, Rayman.
I'm not exactly sure what would happen if you set interrupt on state change of a pin that is in smartpin mode...
I'd guess it wouldn't let you track the actual state of the pin, but hard to say...
But anyway, it's also possible to predict the PWM state change with a simple counter. There are 32 ADC samples per PWM frame. For demodulation of the AC signal I have 3 possibilities based on the compare result of the sample number (n) and the PWM value (v=y<<8) reduced to 5 bits:
a) sample is before state change (n-v < 0): add to bin0, c0++
b) sample is in the blanking window (0<=c-v<3): ignore
c) sample is after blanking window (n-v>=3): add to bin1, c1++
The final result is (bin0/c0) - (bin1/c1) with c0 = number of samples in bin0 and c1 = samples in bin1. That only takes several assembler instructions, probably even less than reading the pin state and compare to the last state.
http://forums.parallax.com/discussion/171420/smartpin-diagram-now-with-p-p-bit-mode-table/p1
But it's not the diagram I meant in the last post, there was an even bigger and more detailed one somewhere.
Chip, can you hear me?
We need a P2 data sheet! A real one with ALL the information.
It's my opinion that the last person you would want to write the data sheet is Chip. Most of the what he knows about the P2 is obvious to him so he would be unlikely to relay information in a way that most people would understand. Just look at most of his demonstrations.
I have my guessed logicsim diagrams at end of that same link - http://forums.parallax.com/discussion/comment/1495168/#Comment_1495168
There is also Chip's block diagram he compiled direct from his schematics of the I/O pad ring - https://forums.parallax.com/discussion/comment/1494131/#Comment_1494131
PS: This is indicated in Rayman's block diagram with the M == 0 dotted line inside the smartpin block.
PPS: Maybe the dotted line should have an arrow head added to it.
Then I have to do it with the counter and comperator method. I'll try that.