Fun with Electronics and Code

Just another WordPress.com site

Code for Lane Interrupts

Last Night I worked on the interrupt Logic for each lane. It occurred to me when writing my post on Saturday that the interrupt logic I was using could lag the embedded computer if it were to get triggered multiple times.  Even though the code was written to only take the time from the first interrupt it would still have to process all other events. On one lane that might not be an issue but on 8 lines that could mean potentially dozen of events in a fraction of a second. That would be bad I am guessing.

So I stated looking for a different way of handling the interrupt and found it. There are basically 2 type of interrupts in the .NET Micro Framework. They are apart of the Microsoft.SPOT.Hardware.Port.InterruptMode namespace. The members InterruptEdgeBoth, InterruptEdgeHigh, and InterruptEdgeLow will all generate an event for each  time they are triggered. However  InterruptEdgeLevelHigh and InterruptEdgeLevelLow will only generate an event the first time they are triggered. Then the question becomes ‘how do we reset for the next race?’.  Well one of the method of the InterruptPort Class is called InterruptPort.ClearInterrupt();. Now in my reset function I just call that function for each lane and it is then ready to generate a single event during the next race.

I also added a Start race function. In it I am checking to see if each lane is ready (make sure each lane’s Digital I/O signal is Low) and then enable the interrupts for each lane. The only thing left to figure out for this section of code is to see if I include the start gate opening interrupt.  Once I add the servo to control the opening of the start gate then you would want to disable the start gate interrupt until the race is started via computer or the manual trigger button. before then however you may want to have the device work independent of the computer and in that case you would want the gate open to start the race and then start gate close to stop and reset the race.  Will have to think about that one some more.

One last thing: I took a bunch of pictures and will be adding them to the project page later today.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: