Go to Post Gravity is not always pointing the same direction relative to the robot! - ChrisH [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 01-02-2004, 18:02
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Post Easy interrupt setup

I made this code to ease using interrupts - I spent most of a day reading documentation and testing things, so I figured that I'd share the code.

RobotUtils.h
Code:
/*				RobotUtils.h			*\
|*		Interface with the more			*|
|*		advanced controller features	*|
|*		Created 2004 by					*|
\*			Steven Schlansker			*/

#include "ifi_picdefs.h"
#include "printf_lib.h"

typedef void (*int_func)(void);


typedef enum { falling, rising } edge;

void interrupt_pin1(int_func,edge which);
void interrupt_pin2(int_func,edge which);
void interrupt1();
void interrupt2();
RobotUtils.c
Code:
#include "RobotUtils.h"
#define bitbyte(c) (1 << c)

int_func pin1,pin2;

void interrupt_pin1(int_func func,edge which){
	pin1 = func;
	if(func){
		INTCON	|= bitbyte(7);
		if(which == rising)
			INTCON2	|= bitbyte(4);
		else
			INTCON2	&= ~bitbyte(4);
		INTCON3	&= ~bitbyte(7);
		INTCON3 |= bitbyte(4);
	}else{
		INTCON3 &= ~bitbyte(4);
	}
}

void interrupt_pin2(int_func func,edge which){
	pin2 = func;
	if(func){
		INTCON	|= bitbyte(7);
		if(which == rising)
			INTCON2	|= bitbyte(3);
		else
			INTCON2	&= ~bitbyte(3);
		INTCON2 &= ~bitbyte(1);
		INTCON3 |= bitbyte(5);
	}else{
		INTCON3 &= ~bitbyte(5);
	}
}

void interrupt1(){ pin1(); }
void interrupt2(){ pin2(); }
user_routines_fast.c (Only modify the lines which are shown here)
Code:
void InterruptHandlerLow ()     
{                               
  unsigned char int_byte;       
  if (INTCON3bits.INT2IF)         /* The INT2 pin is RB2/DIG I/O 1. */
  { 
	 interrupt1();
    INTCON3bits.INT2IF = 0;
  }
  else if (INTCON3bits.INT3IF)    /* The INT3 pin is RB3/DIG I/O 2. */
  {
	  interrupt2();
    INTCON3bits.INT3IF = 0;
  }
  else if (INTCONbits.RBIF)       /* DIG I/O 3-6 (RB4, RB5, RB6, or RB7) changed. */
  {
    int_byte = PORTB;           /* You must read or write to PORTB   */
    INTCONbits.RBIF = 0;        /* and clear the interrupt flag      */
  }                             /* to clear the interrupt condition. */
}
Good luck.
  #2   Spotlight this post!  
Unread 03-02-2004, 10:41
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: Easy interrupt setup

Thanks.
__________________

  #3   Spotlight this post!  
Unread 03-02-2004, 19:30
SeanCassidy's Avatar
SeanCassidy SeanCassidy is offline
Antiregistered User
#0263 (Aftershock)
Team Role: Programmer
 
Join Date: Oct 2003
Location: Holtsville, NY
Posts: 37
SeanCassidy is an unknown quantity at this point
Re: Easy interrupt setup

Glad you posted this, but could you clairify what exactly RoboUtils.c does? It has a lot of bitshiffting and other bitwise operations which are hard to follow. Maybe a few comments?
  #4   Spotlight this post!  
Unread 04-02-2004, 00:07
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: Easy interrupt setup

Yeah, it changes a few registers around, specifically the INTCON registers. For a description of the bits, refer to the Microchip documentation on the PIC. I might write comments eventually if I get a chance...
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
Competition IR Beacon - how does its physical setup compare to our beacons? DanL Electrical 2 25-01-2004 18:05
Interrupts Questions mightywombat Programming 0 03-01-2004 14:50
Looking for an easy website for your team? Jack Website Design/Showcase 2 30-12-2003 23:32
Official California Robot Games announcement! Ken Leung Off-Season Events 9 01-10-2003 03:37
MnM EASY Question of the Day Winners! Mike Bonham General Forum 22 03-05-2002 21:21


All times are GMT -5. The time now is 09:11.

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