Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Swapping digital input/output (http://www.chiefdelphi.com/forums/showthread.php?t=84472)

ay2b 21-03-2010 03:21

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.

ay2b 21-03-2010 03:52

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?

Joe Ross 21-03-2010 14:21

Re: Swapping digital input/output
 
Quote:

Originally Posted by ay2b (Post 940217)
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?

Last year, switching I/O directions caused a delay in all DIO. See http://forums.usfirst.org/showthread.php?t=10460

Not sure if anything changed for this year.

EricVanWyk 21-03-2010 17:32

Re: Swapping digital input/output
 
Quote:

Originally Posted by ay2b (Post 940221)
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?

Sounds like you are on the right track to me. Personally, I'd use a FET instead of a diode to eliminate the .6V, but it likely doesn't matter.

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