Go to Post In FIRST you have the right to remain silent, anything you say can and will be held against you and your associates in the court of public opinion. - Koko Ed [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 19-02-2009, 13:09
Shinigami2057 Shinigami2057 is offline
Slackware Is Your New God (Mentor)
AKA: Harry Bock
FRC #1350 (Rambots)
Team Role: Programmer
 
Join Date: Oct 2006
Rookie Year: 2006
Location: Johnston, RI
Posts: 106
Shinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really nice
Using a GPIO pin for both input and output.

Our team would like to use an ultrasonic rangefinder that uses the signal pin for both input and output (ping control and echo are on the same data line).

How would you go about using WPILib to switch a GPIO pin between input and output? Specifically, I'd like to do something along the following lines:

Code:
 DigitalOutput ping(12);
 Counter echo(12);
 echo.SetSemiPeriodMode(true);

 /* ... */
 ping.Pulse(pingPulseWidth);
 double range = echo.GetPeriod();
This is very easy to do with most microcontrollers, but I can't see an easy way to do this with WPILib. Any tips from the WPI guys?
__________________
One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
Reply With Quote
  #2   Spotlight this post!  
Unread 19-02-2009, 14:16
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Using a GPIO pin for both input and output.

I can't find the post right now, so I can't be sure I'm remembering this properly. I recall someone who should know saying that reconfiguring a pin between input and output "stalls" the FPGA briefly and can mess up other measurements.

What happens if you try connecting the sensor's signal line to a pair of GPIO lines, one input and one output? I don't know whether the FPGA ignores sidetone or if it relies on the sensor itself to not respond to its own signal.
Reply With Quote
  #3   Spotlight this post!  
Unread 20-02-2009, 12:41
oddjob oddjob is offline
Registered User
no team
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Earth
Posts: 118
oddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to behold
Re: Using a GPIO pin for both input and output.

Our team used two cRIO pins for a Radio Shack "parallax" ultrasonic sensor. The cRIO output pin is wired through a small signal diode (e.g. 1n4148) to the sensor SIG pin. The diode cathode is oriented towards the SIG pin. Add a 1K resistor between SIG and ground (because there is a weak pull down on the SIG pin and the pull up in the cRIO will otherwise cause the SIG pin to go high when the sensor floats the pin). Wire SIG to a cRIO input pin. The diode serves to "remove" the cRIO output from the circuit when the output goes low and allow the sensor to drive the pin high and low. It a quick and dirty fix rather than adding a true isolation circuit, and the forward voltage drop is not important in this application.

Then write your own ultrasonic code so that it doesn't look for a high going pulse until the outgoing trigger is finished and returns to a low e.g. modify the existing source code like this:

Code:
void Ultrasonic_SIG::Ping() 
{ 
  // TODO: Either assert or disable, not both. 
  wpi_assert(!m_automaticEnabled); 
  SetAutomaticMode(false); // turn off automatic round robin if pinging single sensor 
  m_pingChannel->Pulse(kPingTime); // do the ping to start getting a single range 
  while(m_pingChannel->IsPulsing()) {}; // wait for the pulse to end 
  m_counter->Reset(); // reset the counter to zero (invalid data now) 
}
Or add your own method to the existing ultrasonic.cpp file, or create a new class that inherits the ultrasonic class, or however you prefer to modify the code.

It's a little complicated but we have our Parallax sensors working.
Reply With Quote
  #4   Spotlight this post!  
Unread 21-02-2009, 13:18
Shinigami2057 Shinigami2057 is offline
Slackware Is Your New God (Mentor)
AKA: Harry Bock
FRC #1350 (Rambots)
Team Role: Programmer
 
Join Date: Oct 2006
Rookie Year: 2006
Location: Johnston, RI
Posts: 106
Shinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really nice
Re: Using a GPIO pin for both input and output.

Thanks a lot for the replies, Alan and oddjob. I had considered the use of two GPIO lines and tristate buffers to ensure that at least one of the lines was always disconnected, but as long as the single diode approach works without causing appreciable noise, I'll give it a shot.

Thanks for the code sample, oddjob! I'll report back on its success when it's implemented.

To the WPILib/FPGA guys:
I'd be nice to have the option bypass the FPGA completely and allow users to implement their own GPIO logic, for those willing to take the plunge.
__________________
One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
Reply With Quote
  #5   Spotlight this post!  
Unread 21-02-2009, 15:24
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: Using a GPIO pin for both input and output.

Take a look at the I2C interface schematic for another implementation.

Quote:
Originally Posted by Shinigami2057 View Post

To the WPILib/FPGA guys:
I'd be nice to have the option bypass the FPGA completely and allow users to implement their own GPIO logic, for those willing to take the plunge.
Can you explain what you mean by this? I am unsure as to what feature you want to add. The direction change timing is a function of the module, not of the FPGA image. The provided image doesn't get in the way unless you ask it to.
Reply With Quote
  #6   Spotlight this post!  
Unread 24-02-2009, 12:24
oddjob oddjob is offline
Registered User
no team
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Earth
Posts: 118
oddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to behold
Re: Using a GPIO pin for both input and output.

We don't have a spare cRIO so I'm not doing any coding now. Often I2C is a special hardware module in the microcontroller and that module takes care of the I2C data line direction. Also, I2C data and clock are open drain connections.

For our robot, it would be great to have a direction controllable pin. Call it whatever, maybe DigitalPin, with a method to control the pin drive mode.

Get() to read the pin.
Set() to set the pin. (the pin needs to be set to drive for the pin to change).
DriveMode() to drive or float the pin.

If there is no FPGA constraint to changing drive mode at run time, the DigitalInput and DigitalOutput classes could be obsoleted by DigitalPin.
Reply With Quote
  #7   Spotlight this post!  
Unread 24-02-2009, 20:04
Shinigami2057 Shinigami2057 is offline
Slackware Is Your New God (Mentor)
AKA: Harry Bock
FRC #1350 (Rambots)
Team Role: Programmer
 
Join Date: Oct 2006
Rookie Year: 2006
Location: Johnston, RI
Posts: 106
Shinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really nice
Re: Using a GPIO pin for both input and output.

Quote:
Originally Posted by EricVanWyk View Post
Take a look at the I2C interface schematic for another implementation.



Can you explain what you mean by this? I am unsure as to what feature you want to add. The direction change timing is a function of the module, not of the FPGA image. The provided image doesn't get in the way unless you ask it to.
Thanks for the clarification; I was under the impression the FPGA was handling the digital I/O as well. If the digital I/O is left untouched, what is the expected delay of changing the direction? Is it enough to warrant using a custom circuit with two pins?

One more quick question: is there any more concrete documentation on what exactly the FPGA does and does not do, and perhaps documentation on how to interface directly with the cRIO functionality? Looking at the WPILib implementation, there's a lot of headers without corresponding source files in the DIO/ChipObject interfaces. If I'd like to work on my own interface/API, would it be possible to get more specific docs or would I have to use WPILib as a reference to how to use the hardware?
__________________
One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
AnalogChannel as both an accumulator AND a normal input? Jared Russell C/C++ 2 31-01-2009 10:14
Dashboard Analog Meters and GPIO? Geek_Girl Programming 1 17-12-2008 09:50
Analog pin output data 3DWolf Programming 3 22-01-2008 10:23
roll pin into output shaft m1k3 Kit & Additional Hardware 18 15-01-2008 16:18
using set screw or dowel pin/pin to hold on drill motor coupler thinggy Travis Covington Motors 1 04-02-2002 03:02


All times are GMT -5. The time now is 14:50.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi