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

InteruptPort problem


  • Please log in to reply
22 replies to this topic

#1 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 28 March 2011 - 02:36 AM

I am trying to get the HH10D humidity sensor to work. I get everything from I2C correctly but the board has an FOUT the I connect to D5 and then use an InteruptPort on the pin to get the frequency to use in the calculation. The problem is that it crashes after I create the port. Any help would be appreciated.

uint _iFreq = 0;

        void port_OnInterrupt(uint data1, uint data2, DateTime time) {
            try {
                this._iFreq++;
            }
            catch (Exception ex) {
                Debug.Print(ex.Message);
            }
        }

        public double GetHumidity() {
            double dReturn = 0.0;

            try {
                InterruptPort port = new InterruptPort(this._FrequencyPin, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
                port.OnInterrupt += new NativeEventHandler(port_OnInterrupt);

                port.DisableInterrupt();
                port.ClearInterrupt();

                this._iFreq = 0;

                port.EnableInterrupt();
                Thread.Sleep(1000);
                port.DisableInterrupt();
                
                dReturn = (this._iOffset - this._iFreq) * this._iSensativity / 4096;
            }
            catch(Exception ex){
                Debug.Print(ex.Message);
            }

            return dReturn;
        }


#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 March 2011 - 03:11 AM

Hi Ryan, First thing...make sure you dispose of your "port" variable before leaving your function...as it may not be automatically disposed before the second time it's called (and therefore you'll be trying to open an already-open port). Second, do you get the exception the _first time_ you call that line of code...or the second+ time? Chris

#3 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 28 March 2011 - 03:29 AM

It happens the first time the code is called. Thanks for reminding to dispose of the port though. The app stops running when the call to DisableInterrupt() is called.

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 March 2011 - 03:49 AM

Hello Ryan. If you try cut off all the port.*Interrupt calls, then it works? Cheers
Biggest fault of Netduino? It runs by electricity.

#5 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 28 March 2011 - 04:16 AM

Unfortunately I need them as I am trying to count the interrupts for 1 second to determine the frequency the sensor is operating at.

#6 demonGeek

demonGeek

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationCanada

Posted 28 March 2011 - 05:07 AM

Ryan,

The code you posted to create the port should work. I tried it and it works for me - at least I was able to create the port and execute the DisableInterrupt call.

So it seems likely that some of your other code might be affecting this code. I would suggest much the same thing as vernarim: Take out as much other code as possible to prove that you can create the port and then gradually add back in the other code until you discover what's causing this code to break. Then, if the answer still isn't clear, you can post all the relevant code and get some more help.

- Adam

#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 March 2011 - 05:32 AM

I have a suspect...how much approx is the frequency of the interrupt? I guess that is too high... Don't expect to manage frequencies above -let's say- 100Hz (but I'd never count on either). Cheers
Biggest fault of Netduino? It runs by electricity.

#8 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 28 March 2011 - 04:15 PM

Looking at the data sheet it says that the output frequency range is between 5 and 10 KHz with normal being about 6.5 KHz. I think what is happening is that it is the event queue is filling up faster than it can be processed and crashing the app. The funny thing is that they have it working on an Arduino without a problem. But they are using a library called FreqCounter to calculate the frequency. I am not sure if that library can be ported to the Netduino though.

#9 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 01 April 2011 - 04:05 PM

Ok, I was able to spend some time with this last night. I hooked up the meter to the FOUT and it was running at about 6.9 KHz. I placed a Debug.Print statement in the OnInterupt event to print out the frequency count. The funny thing is that when it hit it the count was already at 15 and then an out of memory error was thrown. So I still believe that the event call queue is the culprit on this one. Anyone have any alternate solutions to collecting the frequency on this one?

#10 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 01 April 2011 - 05:46 PM

I can't see all the code cause my silly iPhone won't scroll code blocks, but why do you keep re-creating the interrupt port upon each reading? Maybe I'm missing something, but Instead try creating a static variable at Program level holding the port before doing your 1st and any consecutive reading. Initially, I would also loose any and all "just in case" try-catch blocks for clarity as these just adds complexity not really needed until you got the basic principle working. If possible, loose the enable/disable statements as well.

#11 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 01 April 2011 - 05:59 PM

hanzibal, I tried that originally with the same results. The try/catch I put in during testing to see if I could catch any errors. I have even tried using an anonymous method for the oninterupt event. When I add the event binding it does not take long for the app to crash and I have managed to see an out of memory message a couple of times in the dump.

#12 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 01 April 2011 - 06:11 PM

Ok, I see about the try-catches but still have a strong feeling re-creating the port is a dead end. I would suggest reverting to a once and for all static port, then go from there.

#13 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 01 April 2011 - 06:22 PM

hanzibal, thanks for the help. But I had originally designed it that way and had the same results. Re-creating the port isn't the problem as it crashes the first time the port is created and never get's to the point of re-creating it.

#14 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 01 April 2011 - 07:09 PM

Ok, good luck and hope you solve it. Seems strange that creating an Interruptport would cause a crash though. But then again, Pin 13 of my mini recently turned out to be toast...

#15 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 01 April 2011 - 07:26 PM

It doesn't crash until the OnInterupt event is bound. That is when the I believe the event queue is filled up faster than it can be processed causing the out of memory situation. FOUT is running at about 6.9 KHz which is pretty fast.

#16 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 01 April 2011 - 08:03 PM

I see, well maybe it's like you say - event buffer filling up too fast. Dunno if regular Netduino's got programmable conters but if not, you could add an external conter chip using its overflow pin as source of your nterrupt pin, thus implementing a clock devider?

#17 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 01 April 2011 - 09:39 PM

Unfortunately the counters are not exposed on the Netduino (yet), there has been some talk about it but nothing so far. Do you happen to know of a chip off hand or an article to point me in the right direction? Still new at the whole IC stuff so any help would be appreciated, thanks.

#18 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 01 April 2011 - 10:22 PM

Unfortunately the counters are not exposed on the Netduino (yet), there has been some talk about it but nothing so far. Do you happen to know of a chip off hand or an article to point me in the right direction? Still new at the whole IC stuff so any help would be appreciated, thanks.

Not really but found this thread in an Arduino forum, probably looking to solve the same problem as you:

http://arduino.cc/fo...p?topic=50249.0

Btw, I'm a newbie too Posted Image

#19 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 02 April 2011 - 05:31 PM

It looks like I can use a 4017 decade counter to divide the frequency by 10. Now to see if I can find one locally.

#20 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 02 April 2011 - 06:48 PM

It looks like I can use a 4017 decade counter to divide the frequency by 10. Now to see if I can find one locally.

Nice and it's probably like just 20 cents :)




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.