Go to Post We are in the business of teaching our students. One of those things should be respect for the rules... - Tuba4 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 25-01-2007, 09:37
Joohoo's Avatar
Joohoo Joohoo is offline
Registered User
FRC #0340 (G.R.R.)
Team Role: Mentor
 
Join Date: Jun 2005
Rookie Year: 2005
Location: Rochester
Posts: 241
Joohoo is just really niceJoohoo is just really niceJoohoo is just really niceJoohoo is just really niceJoohoo is just really nice
Send a message via AIM to Joohoo Send a message via Yahoo to Joohoo
interupts 3-6??

I am currently trying to develope some code for multiple encoders and I need to use interupts 3-6

I have some code from kevin watson's site and it works, but I don't know why

How do you differentite between the interupt 3-6 even though it is the same register?

thanx
  #2   Spotlight this post!  
Unread 25-01-2007, 09:44
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: interupts 3-6??

3-6 are interrupt-on-change, so they interrupt when anything on there changes. Kevin's code determines which pin changed by saving the old state of the port. You XOR the old port state with the current port state to see which bits have flipped and act accordingly. Then you save the current port state as the old port state (that you'll use the next time it interrupts).
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #3   Spotlight this post!  
Unread 25-01-2007, 09:53
Joohoo's Avatar
Joohoo Joohoo is offline
Registered User
FRC #0340 (G.R.R.)
Team Role: Mentor
 
Join Date: Jun 2005
Rookie Year: 2005
Location: Rochester
Posts: 241
Joohoo is just really niceJoohoo is just really niceJoohoo is just really niceJoohoo is just really niceJoohoo is just really nice
Send a message via AIM to Joohoo Send a message via Yahoo to Joohoo
Re: interupts 3-6??

so what you are saying is that INTCONbits.RBIF (RB Port Change Interrupt Flag bit) is actually a set of bits instead of just a single one?

or are you checking secondary bits to detrmine which pin is flagged after the RBIF is a 1?
  #4   Spotlight this post!  
Unread 25-01-2007, 10:11
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: interupts 3-6??

RBIF is a single bit that tells you that some bit in PORTB (the state of all the interrupt 3-6 pins) has flipped. You actually have to read PORTB before RBIF can be cleared. So now that you have the current value of PORTB, you compare it to the value of PORTB the last time something changed, and that tells you what's changed to cause this interrupt.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #5   Spotlight this post!  
Unread 26-01-2007, 14:41
Joohoo's Avatar
Joohoo Joohoo is offline
Registered User
FRC #0340 (G.R.R.)
Team Role: Mentor
 
Join Date: Jun 2005
Rookie Year: 2005
Location: Rochester
Posts: 241
Joohoo is just really niceJoohoo is just really niceJoohoo is just really niceJoohoo is just really niceJoohoo is just really nice
Send a message via AIM to Joohoo Send a message via Yahoo to Joohoo
Re: interupts 3-6??

couldn't you just look at the specific pin to see if it is the pin that is activated?

such as

Quote:
if(INCONbits.RBIF)
{
if(PORTBbits.RB7)
{
yadda yaddaa
}
if(PORTBbits.RB6)
{
yadda yadda
}
etc. etc.
}
I've been muddling through the pic18f8722 data sheet and I think that PORTB is just another set of bits that refer to the pins RB0 thru RB7. Is that a valid way to isolate the interrupts in INTCONbits.RBIF?
  #6   Spotlight this post!  
Unread 26-01-2007, 14:55
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: interupts 3-6??

I think you have to read the entire port to be able to clear the flag, but reading a single pin might work. What happens is if you don't clear the mismatch by reading the entire port, or maybe reading one pin, is the flag continues to be set over and over, and you'll keep jumping back into your ISR. So if you try your way and get a red light of death, you'll know why.

Second point. Your method works if you only care about 0 to 1 transitions on the pin. 1 to 0 transitions will still cause interrupts and you'll still have to service them, however. So using interrupts 3-6 when you only care about 0 to 1 transitions is pretty wasteful of your resources and you'll only be able to service half as many interrupts as you'd other wise be able to.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #7   Spotlight this post!  
Unread 28-01-2007, 19:00
intellec7's Avatar
intellec7 intellec7 is offline
108 programmer
AKA: Gustavo
FRC #0108 (SigmaC@ts)
Team Role: Programmer
 
Join Date: Sep 2005
Rookie Year: 2006
Location: Hollywood, Florida
Posts: 65
intellec7 is on a distinguished road
Send a message via AIM to intellec7 Send a message via MSN to intellec7
Re: interupts 3-6??

What if some other pin changed on the port and that pin was already high (it was high before and is continued to be high) that would give a false impression of that pin changing, right?
  #8   Spotlight this post!  
Unread 28-01-2007, 19:31
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: interupts 3-6??

ummmm.. true. a good point. missed that one.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #9   Spotlight this post!  
Unread 28-01-2007, 20:45
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: interupts 3-6??

John, Kevin, Gustavo, et al,

Look at Kevin Watson's example here. Look at the way he uses the static variable "Old_Port_B" in user_rourtines_fast.c and you will begin to understand...

Regards,

Mike
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...

Last edited by Mike Betts : 28-01-2007 at 20:48.
  #10   Spotlight this post!  
Unread 28-01-2007, 21:41
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: interupts 3-6??

Quote:
Originally Posted by Joohoo View Post
I am currently trying to develope some code for multiple encoders and I need to use interupts 3-6

I have some code from kevin watson's site and it works, but I don't know why

How do you differentite between the interupt 3-6 even though it is the same register?

thanx
This is the code Mike is referring to:

-Kevin

Code:
 
if (INTCONbits.RBIF && INTCONbits.RBIE) // external interrupts 3 through 6?
 {
 
// This does two things. First we grab a copy of PORTB, which 
// contains the states of the four interrupts. Secondly, reading
// this register resets an internal flag that would otherwise cause 
// another interrupt to fire-off when you cleared the interrupt 
// flag in the next instruction...
  Port_B = PORTB;          
 
// This clears the interrupt flag, informing the processor that you've
// handled the interrupt
  INTCONbits.RBIF = 0;
 
// This line of code updates a variable using the exclusive-or operation.
// If the state of one of the interrupts has changed between the last
// time this function was called and now, a bit in Port_B_Delta will be
// set to one, signaling that that interrupt service routine needs to be
// called
  Port_B_Delta = Port_B ^ Old_Port_B;
 
// Now that we know which inputs have changed, save a copy of the
// current state so we'll know which one(s) changed next time.
  Old_Port_B = Port_B;
 
// This checks to see if the bit associated with interrupt 3 has changed
// and if it has, call the interrupt service routine
  if(Port_B_Delta & 0x10)
  {
// Call the interrupt 3 handler and include the current state of the
// interrupt pin. The wacky bit of code "Port_B & 0x10 ? 1 : 0" is the
// same thing as:
//
// if(Port_B & 0x10)
// {
// return(1)
// }
// else
// {
// return(0)
// }
// This is done to ensure the value sent into the interrupt
// handler is either 0 or 1.
   Int_3_Handler(Port_B & 0x10 ? 1 : 0);
  }
 
// Each one must be checked individually because more than one may
// have changed
  if(Port_B_Delta & 0x20)
  {
   Int_4_Handler(Port_B & 0x20 ? 1 : 0);
  }
  if(Port_B_Delta & 0x40)
  {
   Int_5_Handler(Port_B & 0x40 ? 1 : 0);
  }
  if(Port_B_Delta & 0x80)
  {
   Int_6_Handler(Port_B & 0x80 ? 1 : 0);
  }
 }
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org

Last edited by Kevin Watson : 28-01-2007 at 21:44.
Closed Thread


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
Interupts/sec cprogrammer Programming 9 12-10-2006 12:46
Interupts on Vex in MPLab Andrew Schreiber FIRST Tech Challenge 1 24-05-2006 08:32
Interupts on the Pic18 Andrew Schreiber Programming 10 21-01-2006 22:54
Interupts? Validius Programming 6 11-01-2006 18:29
Need interupts help, and another question... Kevin Karan Programming 7 22-02-2004 11:20


All times are GMT -5. The time now is 23:54.

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