View Single Post
  #4   Spotlight this post!  
Unread 09-04-2006, 21:19
kiettyyyy's Avatar
kiettyyyy kiettyyyy is offline
Registered User
FRC #1538 (The Holy Cows)
Team Role: Engineer
 
Join Date: Mar 2006
Rookie Year: 2005
Location: San Diego, CA
Posts: 181
kiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond reputekiettyyyy has a reputation beyond repute
Send a message via AIM to kiettyyyy
Re: Phase A and Phase B on encoders

Ohh I see.. So if I wanted to have Encoder1 on digital i/o #1 and #2, and Encoder2 on digital i/o #3 and #4.. I would set...

Code:
	#ifdef ENABLE_ENCODER_1

	// make sure interrupt 1 is configured as an input
	TRISBbits.TRISB2 = 1;

	// interrupt 1 is low priority
	INTCON3bits.INT2IP = 0;

	// trigger on rising edge
	INTCON2bits.INTEDG2 = 1;

	// make sure the interrupt flag is reset before enabling
	INTCON3bits.INT2IF = 0;

	// enable interrupt 1
	INTCON3bits.INT2IE = 1;
	#endif

	// if enabled in encoder.h, configure encoder 2's interrupt input
	#ifdef ENABLE_ENCODER_2

	// make sure interrupt 2 is configured as an input
	TRISBbits.TRISB4 = 1;

	// interrupt 2 is low priority
	INTCON2bits.INT4IP = 0;

	// trigger on rising edge
	INTCON2bits.INTEDG4 = 1;

	// make sure the interrupt flag is reset before enabling
	INTCON3bits.INT4IF = 0;

	// enable interrupt 2
	INTCON3bits.INT4IE = 1;
	#endif
and change the Phase B inputs in encoder.h

Code:
#define ENCODER_1_PHASE_B_PIN	rc_dig_in02
#define ENCODER_2_PHASE_B_PIN	rc_dig_in04

// Encoder 3 to 6 is not defined in encoder.c
#define ENCODER_3_PHASE_B_PIN	rc_dig_in13
#define ENCODER_4_PHASE_B_PIN	rc_dig_in14
#define ENCODER_5_PHASE_B_PIN	rc_dig_in15
#define ENCODER_6_PHASE_B_PIN	rc_dig_in16

If you see any problems in this code, let me know because I am also learning

Thanks every body!
__________________
-Kiet Chau

2004-2008 - Software Developer/Driver on Team #968
2008-2011 - Software Developer/Coach/Mentor/"Engineer" on Team #968
2011-Present - Mentor & Engineer on Team #1538
www.team1538.com