Another InterruptPort problem - Visual Basic Support - Netduino Forums
   
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

Another InterruptPort problem

InterruptPort

Best Answer CW2, 11 February 2013 - 09:56 AM

Unfortunately, .NET Micro Framework allows only single instance of InterruptPort per pin. In case you want to handle both edges, specify InterruptEdgeBoth mode, then you can distinguish the edge in the interrupt handler based on the value of state parameter: state is false -> low/falling edge, state is true -> high/rising edge.   Welcome to the community!

Go to the full post


  • Please log in to reply
9 replies to this topic

#1 clefranc

clefranc

    Member

  • Members
  • PipPip
  • 16 posts

Posted 10 February 2013 - 12:39 AM

Hi,

Sorry if this was posted in another thread, I just received my netduino plus 2 today. I'm still playing with the button and LED. I'm interrested with event programming, this code is working well:

Imports Microsoft.SPOTImports Microsoft.SPOT.HardwareImports SecretLabs.NETMF.HardwareImports SecretLabs.NETMF.Hardware.NetduinoModule Module1    Dim led As New OutputPort(Pins.ONBOARD_LED, False)    Public WithEvents boardButton As New InterruptPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth)    Public Sub Main()	    Thread.Sleep(Timeout.Infinite)    End Sub    Private Sub boardButton_OnInterrupt(ByVal port As UInteger, ByVal state As UInteger, ByVal time As DateTime) Handles boardButton.OnInterrupt	    Select Case port		    Case CUInt(Pins.ONBOARD_SW1)			    led.Write(CBool(state))	    End Select    End SubEnd Module 

Then I tried to use both the InterruptEdgeHigh and InterruptEdgeLow, but it always fails at the second attempt to declare an InterruptPort:

Imports Microsoft.SPOTImports Microsoft.SPOT.HardwareImports SecretLabs.NETMF.HardwareImports SecretLabs.NETMF.Hardware.NetduinoModule Module1    Dim led As New OutputPort(Pins.ONBOARD_LED, False)    Public WithEvents boardButtonHigh As New InterruptPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh)    Public WithEvents boardButtonLow As New InterruptPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow)    Public Sub Main()	    Thread.Sleep(Timeout.Infinite)    End Sub    Private Sub boardButton_OnInterrupt(ByVal port As UInteger, ByVal state As UInteger, ByVal time As DateTime) Handles boardButtonHigh.OnInterrupt, boardButtonLow.OnInterrupt	    Select Case port		    Case CUInt(Pins.ONBOARD_SW1)			    led.Write(CBool(state))	    End Select    End SubEnd Module 

What prevents me from declaring a second InterruptPort for the same pin? I hope the answer is very, very complicated.

 

Thank you

 



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 11 February 2013 - 09:56 AM   Best Answer

Unfortunately, .NET Micro Framework allows only single instance of InterruptPort per pin. In case you want to handle both edges, specify InterruptEdgeBoth mode, then you can distinguish the edge in the interrupt handler based on the value of state parameter: state is false -> low/falling edge, state is true -> high/rising edge.   Welcome to the community!



#3 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 11 February 2013 - 10:27 AM

When speaking of the interrupt modes that you can specify, I've noticed that there two different types of edge enumerators:

 

InterruptEdgeHigh

InterruptEdgeLow

InterruptEdgeLevelHigh

InterruptEdgeLevelLow

 

What's the difference between EdgeHigh/Low and EdgeLevelHigh/Low?



#4 clefranc

clefranc

    Member

  • Members
  • PipPip
  • 16 posts

Posted 11 February 2013 - 11:41 PM

CW2,

Thanks for the info, very useful knowledge for my futur coding.

 

What's the difference between EdgeHigh/Low and EdgeLevelHigh/Low?

 

I think the InterruptEdgeHigh refer to the "rising edge" of the pin signal, ie the beginning of the transition between the low and high state, at the bottom of the slope. The InterruptEdgeLevelHigh must be when the µC detect that the signal have reach its high state (the upper edge of the slope, just before the top). So, if this is correct, the InterruptEdgeHigh must be triggered before the InterruptEdgeLevelHigh. But...

 

Are the netduino .NET interrupt events from the "External interrupt/event controller"? If so, then the InterruptEdgeHigh and InterruptEdgeLevelHigh must be the same because there is only a rising and falling trigger selection registers available in the STM32 chip. Perhaps other µC can use both edge.

 

This is only speculation needing approval or disapproval.



#5 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 12 February 2013 - 02:08 AM

when using

InterruptEdgeLevelHigh or

InterruptEdgeLevelLow

you have to call clear interrupt afterwards.

it wount throw another interrupt till you cleared it



#6 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 12 February 2013 - 05:52 AM

I think the InterruptEdgeHigh refer to the "rising edge" of the pin signal, ie the beginning of the transition between the low and high state, at the bottom of the slope. The InterruptEdgeLevelHigh must be when the µC detect that the signal have reach its high state (the upper edge of the slope, just before the top). So, if this is correct, the InterruptEdgeHigh must be triggered before the InterruptEdgeLevelHigh. But... Are the netduino .NET interrupt events from the "External interrupt/event controller"? If so, then the InterruptEdgeHigh and InterruptEdgeLevelHigh must be the same because there is only a rising and falling trigger selection registers available in the STM32 chip. Perhaps other µC can use both edge. This is only speculation needing approval or disapproval.

That would be my guess too.

when using InterruptEdgeLevelHigh or InterruptEdgeLevelLow you have to call clear interrupt afterwards. it wount throw another interrupt till you cleared it

Isn't that always the case within an interrupt handler?

#7 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 12 February 2013 - 06:57 AM

no.

 

the ones without Level clear themselfes

 

edit: using clear on non level even throws an error according to:

http://msdn.microsof...y/cc532335.aspx



#8 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 12 February 2013 - 09:29 AM

Thanks, I wasn't aware of that.



#9 Lunddahl

Lunddahl

    Advanced Member

  • Members
  • PipPipPip
  • 152 posts
  • LocationEurope, Denmark

Posted 13 February 2013 - 02:18 PM

- Level interupts has nothing to do with the signal level, the "Level" means not to throw any more interupts before signaled to with Clear.

 

- Level interupts is not suported on the Netduino platforms.



#10 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 13 February 2013 - 02:27 PM

sure it is, at least my mini supports it. so i guess all v1 boards do so.







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.