Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Interrupts on TristatePort


  • Please log in to reply
7 replies to this topic

#1 demonGeek

demonGeek

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationCanada

Posted 18 March 2011 - 08:32 PM

I'm playing with a Parallax Ping))) Sensor and was wondering what would be the best way to interface it to my Netduino.

I've found some code samples that are based on a TriStatePort but it seems to me that an InterruptPort might be a better way of doing things. The trouble is that I'm not very experienced with either of those types of port so I'm looking for some help and advice.

I tried to set an interrupt event handler on a Tristate port like this:

TristatePort tristatePort.OnInterrupt += new NativeEventHandler(Port_OnInterrupt);

but that produces a System.InvalidOperationException. No idea why...

I then tried creating an Interrupt port and event handler which seems to be fine but I don't see how to send the trigger pulse in that situation so the interrupt never occurs.

Thanks.

- Adam

#2 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 20 March 2011 - 04:44 AM

I'm not 100% sure, but I think this is not supported. I think you'll have to tie two pins together, configuring one as a TriStatePort and the other as an InterruptPort. You'll (hopefully) see two pulses on the InterruptPort: your own outgoing pulse and then later the reply from the PING)))

#3 demonGeek

demonGeek

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationCanada

Posted 20 March 2011 - 07:30 PM

I'm not 100% sure, but I think this is not supported. I think you'll have to tie two pins together, configuring one as a TriStatePort and the other as an InterruptPort. You'll (hopefully) see two pulses on the InterruptPort: your own outgoing pulse and then later the reply from the PING)))


Hey Corey,

That's what I was thinking too but I was hoping it wouldn't be the case - it seems like a waste of resources to use two pins.

I don't understand why there's an OnInterrupt event on the TristatePort if you can't use it. It makes sense that event wouldn't fire unless the port was set for input but it seems I can't hook the event at all.

The obvious option is to abandon interrupts and just go with the TristatePort for everything but an interrupt seems tailor-made for this type of operation...

- Adam

#4 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 21 March 2011 - 01:30 AM

The obvious option is to abandon interrupts and just go with the TristatePort for everything but an interrupt seems tailor-made for this type of operation...


I was looking over the firmware source briefly and I didn't see any obvious reasons why it couldn't be modified to work the way you want. (famous last words.. to be clear I only looked at the firmware for about 30 seconds)

As for why the methods are there in the first place, it's a sad casualty of the inheritance hierarchy: TriStatePort inherits from OutputPort which in turn inherits from Port which in turn inherits from NativeEventDispatcher, which introduces the event.

#5 demonGeek

demonGeek

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationCanada

Posted 24 March 2011 - 06:23 AM

I was looking over the firmware source briefly and I didn't see any obvious reasons why it couldn't be modified to work the way you want. (famous last words.. to be clear I only looked at the firmware for about 30 seconds)

As for why the methods are there in the first place, it's a sad casualty of the inheritance hierarchy: TristatePort inherits from OutputPort which in turn inherits from Port which in turn inherits from NativeEventDispatcher, which introduces the event.


Well, I'm giving up on this one. I can make it work with interrupts by using two ports as you suggested but I don't think it's worth the effort. It's simpler just to use one TristatePort for everything and perhaps run it on its own thread when I want to read the sensor.

Personally I think it makes sense to have a working interrupt on a TriState port, I find events more intuitive for this kind of thing.

Thanks for your help.

- Adam

#6 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 23 July 2011 - 04:26 PM

Hi,

I'm running into the same issue now (I need to generate a pulse on a port to trigger the measurement, and then want to use interrupts on it) with the same sensor. Basically, as I see it, there are two choices: use two ports (one outputport and an iterruptport, left in the image) or use an external circuit to generate the triggering pulse and an interruptport (right). (sensor works like this: you send a pulse over the signal line, and then after a delay it sends a pulse back, and the length of the pulse translates to the distance).

Posted Image

However, as I'm an electronics newbie, I'd like to clear up some issues first:

I weakly recall that somewhere here in the forum someone said never to connect one output and one input port, because that can/will lead to frying the pin. I don't quite get this, because the input port should be high impedance, so currents between them should be low, right?

However, this also means that the output port can sink current when the sensor sends its pulse back. this i can imagine as a problem, both because that might disrupt the measurement on the input port and because there's no current-limiting factor there. I'm reluctant to add a diode there, because the voltage drop of e.g. a 1n4148 combined with the netduinos 3.3v output levels could mean that the neccessary pulse height isn't reached to trigger the measurement. Should I simply add a resistor there? What would be a good value for that?

A similar problem exists for the external circuit, a bit less because the circuit has higher output levels and so there is no problem with adding a diode, i think ...

Can someone clear my doubts for me? Thanks!
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#7 Earthed

Earthed

    Member

  • Members
  • PipPip
  • 20 posts
  • LocationAustralia

Posted 28 July 2011 - 07:04 AM

I've just had a similar problem, I was getting the exception: InvalidOperationException after trying to do the following: this._BuzzerPin[0] = new TristatePort(Pins.GPIO_PIN_D10, false, false, Port.ResistorMode.PullUp); if (this._BuzzerPin[0] != null) { this._BuzzerPin[0].Active = false; <<<<<<<< EXCEPTION to use the following: public void Set(int index, bool Active) { if (this._BuzzerPin[index].Active != Active) { this._BuzzerPin[index].Active = Active; } } Strangely enough problem occurred on D12 also!

#8 rubenhak

rubenhak

    Member

  • Members
  • PipPip
  • 10 posts

Posted 11 February 2013 - 07:26 AM

Guys, I ran into a same issue. 

I might try to burn tow ports at this point. Could you please share the code for this?

 

Thanks,

Ruben






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.