![]() |
Swapping digital input/output
I have a sensor which I would like to use which requires swapping a pin between input and output. Basically you set the pin to output/high, charge a capacitor, then set it to an input and time how long until the input reads low. Is there an easy way to do this with WPILib?
Based on my reading of the code, the current objects do not allow swapping the direction of a DIO pin. To change this would require modifying the DigitalModule class, probably cloning the AllocateDIO method to make a SetDIO method which would call m_fpgaDIO->writeOutputEnable to change the direction. Next I'd probably want a wrapper class which combines the DigitalInput and DigitalOutput classes. Finally I'd want a class similar to (or perhaps actually using) the Counter class which would have an interrupt on the falling edge to stop a timer which gets started on direction change. Does this sound like the right track? Am I missing anything? Is there an easier way to do this? Has anyone else done this already? Thanks. |
Re: Swapping digital input/output
I just thought of this:
Maybe the Ultrasonic class, two I/O pins and a diode would solve the problem: Charge the cap through a diode from an output pin. This corresponds to the "ping" in the Ultrasonic class. When the output pin goes low, the diode prevents the cap from being discharged by the output pin, and the input pin can be used to measure the discharge rate. Thoughts? |
Re: Swapping digital input/output
Quote:
Not sure if anything changed for this year. |
Re: Swapping digital input/output
Quote:
Out of curiosity, what sensor are you using? Datasheet link please! |
| All times are GMT -5. The time now is 23:55. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi