Go to Post We have not always been a winning team but we have always tried to be a quality team. - WynS [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 Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 01-02-2009, 16:58
Analog's Avatar
Analog Analog is offline
Registered User
AKA: Bob Most
FRC #2619 (The Charge)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Midland, Michigan
Posts: 53
Analog will become famous soon enoughAnalog will become famous soon enough
Using Interrupts on Digital Inputs

Is there any example code on using interrupts on digital inputs via Windriver?

Also, are there any restrictions on which digital inputs can be used via interrupts?
Reply With Quote
  #2   Spotlight this post!  
Unread 01-02-2009, 20:27
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 Interrupts on Digital Inputs

Any digital input pin is as good as any other. So far as I know, however, none of them will be able to generate interrupts that your code can respond to.

Why do you want an interrupt? The WPI library has support via the FPGA for pretty much anything you might otherwise need interrupts to implement.
Reply With Quote
  #3   Spotlight this post!  
Unread 01-02-2009, 20:42
Analog's Avatar
Analog Analog is offline
Registered User
AKA: Bob Most
FRC #2619 (The Charge)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Midland, Michigan
Posts: 53
Analog will become famous soon enoughAnalog will become famous soon enough
Re: Using Interrupts on Digital Inputs

Quote:
Originally Posted by Alan Anderson View Post
Any digital input pin is as good as any other. So far as I know, however, none of them will be able to generate interrupts that your code can respond to.

Why do you want an interrupt? The WPI library has support via the FPGA for pretty much anything you might otherwise need interrupts to implement.
We were thinking about having an ISR service high priority tasks outside of the main loop if necessary.
Reply With Quote
  #4   Spotlight this post!  
Unread 01-02-2009, 21:42
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 Interrupts on Digital Inputs

Quote:
Originally Posted by Analog View Post
We were thinking about having an ISR service high priority tasks outside of the main loop if necessary.
Sure, but what specifically do you want to do? I can't think of any events you'd need a "high priority" routine for.
Reply With Quote
  #5   Spotlight this post!  
Unread 02-02-2009, 09:46
Analog's Avatar
Analog Analog is offline
Registered User
AKA: Bob Most
FRC #2619 (The Charge)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Midland, Michigan
Posts: 53
Analog will become famous soon enoughAnalog will become famous soon enough
Re: Using Interrupts on Digital Inputs

We have some tasks based on limit switches which have high priority. Can't tell you much more than that since its proprietary...
Reply With Quote
  #6   Spotlight this post!  
Unread 02-02-2009, 17:22
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Using Interrupts on Digital Inputs

If you look at the source for the DigitalInput class you will see virtual methods for using interrupt handlers. You can use a tInterruptHandler object to catch the interrupts.
Reply With Quote
  #7   Spotlight this post!  
Unread 03-02-2009, 23:05
7-11number1 7-11number1 is offline
ROAR.
FRC #1711 (RAPTORS)
 
Join Date: Sep 2007
Rookie Year: 2006
Location: Traverse City, Michigan
Posts: 46
7-11number1 will become famous soon enough
Re: Using Interrupts on Digital Inputs

We have implemented interrupt handling for our limit switches, reset operations, autonomous goodies using GPIO and the DigitialInput class. Points to note to save you from our madness, the DIO sig pins are pulled high, therefore you switch them low to get response (then high again to get toggle). You will get switch bounce as the contacts come together and separate. You need to program against that. You also need to set the leading or trailing edge of the pulse correctly (the default is the wrong way round by my estimation in the DigitalInput interrupt handler), since the initial setup is to transition to 0v, you should only interrupt on the trailing pulse edge. If not, you will get an interrupt for the press and another for the release of the switch - unless you are interested in that granularity of course.

Good luck. I'll paste some code here to help.

Tony
1711 Raptors

Code:
#include "WPILib.h"
#include "Reset.h"

// Victor crab drive definitions
Victor *vicCrabFront;
Victor *vicCrabRear;

#define CRABRESETTIMEOUT 20		// reset timeout in seconds for crab drive

bool frontLimit;
bool rearLimit;

// front crab limit switch interrupt handler (handles both left and right switches)
static void hdlrCrabFrontLimit(tNIRIO_u32 interruptAssertedMask, void *param)  {
	// only process if not already set (eliminates switch bounce)
	if(frontLimit==false){
		frontLimit=true;
		// hit limit switch, turn the other way 
		
		if(vicCrabFront->Get()>0) {
			cout<<"Front right limit fired"<<endl;
			vicCrabFront->Set(-1);
		} else {
			cout<<"Front left limit fired"<<endl;
			vicCrabFront->Set(1);
		}
	} else 
		frontLimit=false;
		
}	

Reset::Reset () {
	DigitalInput swCrabFrontRightLimit(4);
	DigitalInput swCrabFrontLeftLimit(5);
	Timer timer; 

	// create the crab Victor objects
	vicCrabFront=new Victor(7);
	vicCrabRear=new Victor(8);

	// adjust interrupts to fire on trailing edge (5>0v) transitions.
	swCrabFrontRightLimit.SetUpSourceEdge(false,true);
	swCrabFrontLeftLimit.SetUpSourceEdge(false,true);

	// enable limit switch interrupts (1 routine handles left and right limits)
	swCrabFrontRightLimit.RequestInterrupts(hdlrCrabFrontLimit); 
	swCrabFrontRightLimit.EnableInterrupts();
	swCrabFrontLeftLimit.RequestInterrupts(hdlrCrabFrontLimit); 
	swCrabFrontLeftLimit.EnableInterrupts();

	// ensure all limit switches are off to start
	frontLimit=false;

	// zero front crab drive if not already in position
	cout<<"Waiting "<<CRABRESETTIMEOUT<<" seconds for front reset"<<endl;
	vicCrabFront->Set(1);
	if(swCrabFrontZero.Get()==false) {
		timer.Reset();
		timer.Start();

		// move crab front drive to right looking for 0 point
		vicCrabFront->Set(1);
		
		// hold for CRABRESETTIMEOUT seconds waiting for the crab to find zero 
		while(timer.Get()<CRABRESETTIMEOUT&&swCrabFrontZero.Get()==false) ;
		vicCrabFront->Set(0);
		
		// display error if we cannot zero the crab (timed out)
		if(swCrabFrontZero.Get()==false) {
			cout<<"Cannot zero front crab drive"<<endl;
			return;
		}
	}
}

Last edited by 7-11number1 : 03-02-2009 at 23:11.
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
Digital Inputs KRibordy C/C++ 5 25-01-2009 00:35
Using driver station digital inputs Japper FRC Control System 6 19-01-2009 20:01
Using Analog Inputs as Digital (on the OI) Guy Davidson Control System 16 10-03-2008 17:17
digital inputs: some bad? Trav-O Electrical 3 18-02-2008 23:29
Analog vs Digital inputs? f22flyboy Programming 8 08-11-2002 22:18


All times are GMT -5. The time now is 15:29.

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