Go to Post I’m not decently dressed for this picture.......I have no FIRST shirt, FIRST hat or FIRST pin anywhere on me! - Rich Wong [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 19-01-2006, 21:54
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Combining ADC, Serial, and Camera_s codes

Our team's desired code makes use of

1. The camera (stripped down version, needs the updated serial code)
2. The gyro (which needs the updated adc driver)
3. Two shaft encoders (for speed, interrupts 3 and 4).

Since all of these involve changing InterruptHandlerLow() user_routines_fast.c, this is a bit involved. I have the camera and gyro working fine with each other, but attempting to add in the encoder code gives us the red-light-o-death, even if I don't hook up the encoder or call one of the encoder reading functions.

I thought I've got all the code properly installed in InterruptHandlerLow(), but apparently that's not the case.

Here's the relevant part of my user_routines_fast.c:
Code:
#pragma code
#pragma interruptlow InterruptHandlerLow save=PROD

void InterruptHandlerLow(void)     
{                               
	unsigned char int_byte;
    unsigned char Port_B;
    unsigned char Port_B_Delta;

	if(PIR1bits.RC1IF && PIE1bits.RC1IE) // rx1 interrupt?
	{
		#ifdef ENABLE_SERIAL_PORT_ONE_RX
		Rx_1_Int_Handler(); // call the rx1 interrupt handler (in serial_ports.c)
		#endif
	}                              
	else if(PIR3bits.RC2IF && PIE3bits.RC2IE) // rx2 interrupt?
	{
		#ifdef ENABLE_SERIAL_PORT_TWO_RX
		Rx_2_Int_Handler(); // call the rx2 interrupt handler (in serial_ports.c)
		#endif
	} 
	else if(PIR1bits.TX1IF && PIE1bits.TX1IE) // tx1 interrupt?
	{
		#ifdef ENABLE_SERIAL_PORT_ONE_TX
		Tx_1_Int_Handler(); // call the tx1 interrupt handler (in serial_ports.c)
		#endif
	}                              
	else if(PIR3bits.TX2IF && PIE3bits.TX2IE) // tx2 interrupt?
	{
		#ifdef ENABLE_SERIAL_PORT_TWO_TX
		Tx_2_Int_Handler(); // call the tx2 interrupt handler (in serial_ports.c)
		#endif
	}
		else if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) // encoder 1 interrupt?
	{ 
		INTCON3bits.INT2IF = 0; // clear the interrupt flag
		#ifdef ENABLE_ENCODER_1
		Encoder_1_Int_Handler(); // call the left encoder interrupt handler (in encoder.c)
		#endif
	}
	else if (INTCON3bits.INT3IF && INTCON3bits.INT3IE) // encoder 2 interrupt?
	{
		INTCON3bits.INT3IF = 0; // clear the interrupt flag
		#ifdef ENABLE_ENCODER_2
		Encoder_2_Int_Handler(); // call right encoder interrupt handler (in encoder.c)
		#endif
	}
	else if (INTCONbits.RBIF && INTCONbits.RBIE) // encoder 3-6 interrupt?
	{
		Port_B = PORTB; // remove the "mismatch condition" by reading port b            
		INTCONbits.RBIF = 0; // clear the interrupt flag
		Port_B_Delta = Port_B ^ Old_Port_B; // determine which bits have changed
		Old_Port_B = Port_B; // save a copy of port b for next time around
	 
		if(Port_B_Delta & 0x10) // did external interrupt 3 change state?
		{
			#ifdef ENABLE_ENCODER_3
			Encoder_3_Int_Handler(Port_B & 0x10 ? 1 : 0); // call the encoder 3 interrupt handler (in encoder.c)
			#endif
		}
		if(Port_B_Delta & 0x20) // did external interrupt 4 change state?
		{
			#ifdef ENABLE_ENCODER_4
			Encoder_4_Int_Handler(Port_B & 0x20 ? 1 : 0); // call the encoder 4 interrupt handler (in encoder.c)
			#endif
		}
		if(Port_B_Delta & 0x40) // did external interrupt 5 change state?
		{
			#ifdef ENABLE_ENCODER_5
			Encoder_5_Int_Handler(Port_B & 0x40 ? 1 : 0); // call the encoder 5 interrupt handler (in encoder.c)
			#endif
		}
		if(Port_B_Delta & 0x80) // did external interrupt 6 change state?
		{
			#ifdef ENABLE_ENCODER_6
			Encoder_6_Int_Handler(Port_B & 0x80 ? 1 : 0); // call the encoder 6 interrupt handler (in encoder.c)
			#endif
		}
	}           
	else if(PIR1bits.ADIF && PIE1bits.ADIE) // ADC interrupt
	{
		PIR1bits.ADIF = 0; // clear the ADC interrupt flag
		ADC_Int_Handler(); // call the ADC interrupt handler (in adc.c)
	}       
}
This seems right to me, and compiles cleanly.

Any ideas what to try next?

Last edited by kaszeta : 19-01-2006 at 21:56. Reason: Clarification
  #2   Spotlight this post!  
Unread 19-01-2006, 22:22
6600gt's Avatar
6600gt 6600gt is offline
Registered User
AKA: Lohit
FRC #0226 (Hammerhead)
Team Role: Alumni
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Troy, MI
Posts: 221
6600gt is a jewel in the rough6600gt is a jewel in the rough6600gt is a jewel in the rough
Re: Combining ADC, Serial, and Camera_s codes

Why are you using interrupts 3 and 4 instead of 1 and 2? They are already set up for you in Kevin Watson's encoder code.

You might be missing somthing:
Quote:
#pragma code
#pragma interruptlow InterruptHandlerLow save=PROD,section(".tmpdata")
  #3   Spotlight this post!  
Unread 19-01-2006, 22:29
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: Combining ADC, Serial, and Camera_s codes

Quote:
Originally Posted by kaszeta
Our team's desired code makes use of

1. The camera (stripped down version, needs the updated serial code)
2. The gyro (which needs the updated adc driver)
3. Two shaft encoders (for speed, interrupts 3 and 4).

Since all of these involve changing InterruptHandlerLow() user_routines_fast.c, this is a bit involved. I have the camera and gyro working fine with each other, but attempting to add in the encoder code gives us the red-light-o-death, even if I don't hook up the encoder or call one of the encoder reading functions.

I thought I've got all the code properly installed in InterruptHandlerLow(), but apparently that's not the case.

Here's the relevant part of my user_routines_fast.c:
Code:
#pragma code
#pragma interruptlow InterruptHandlerLow save=PROD
 
void InterruptHandlerLow(void) 
{ 
	unsigned char int_byte;
unsigned char Port_B;
unsigned char Port_B_Delta;
 
	if(PIR1bits.RC1IF && PIE1bits.RC1IE) // rx1 interrupt?
	{
		#ifdef ENABLE_SERIAL_PORT_ONE_RX
		Rx_1_Int_Handler(); // call the rx1 interrupt handler (in serial_ports.c)
		#endif
	} 
	else if(PIR3bits.RC2IF && PIE3bits.RC2IE) // rx2 interrupt?
	{
		#ifdef ENABLE_SERIAL_PORT_TWO_RX
		Rx_2_Int_Handler(); // call the rx2 interrupt handler (in serial_ports.c)
		#endif
	} 
	else if(PIR1bits.TX1IF && PIE1bits.TX1IE) // tx1 interrupt?
	{
		#ifdef ENABLE_SERIAL_PORT_ONE_TX
		Tx_1_Int_Handler(); // call the tx1 interrupt handler (in serial_ports.c)
		#endif
	} 
	else if(PIR3bits.TX2IF && PIE3bits.TX2IE) // tx2 interrupt?
	{
		#ifdef ENABLE_SERIAL_PORT_TWO_TX
		Tx_2_Int_Handler(); // call the tx2 interrupt handler (in serial_ports.c)
		#endif
	}
		else if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) // encoder 1 interrupt?
	{ 
		INTCON3bits.INT2IF = 0; // clear the interrupt flag
		#ifdef ENABLE_ENCODER_1
		Encoder_1_Int_Handler(); // call the left encoder interrupt handler (in encoder.c)
		#endif
	}
	else if (INTCON3bits.INT3IF && INTCON3bits.INT3IE) // encoder 2 interrupt?
	{
		INTCON3bits.INT3IF = 0; // clear the interrupt flag
		#ifdef ENABLE_ENCODER_2
		Encoder_2_Int_Handler(); // call right encoder interrupt handler (in encoder.c)
		#endif
	}
	else if (INTCONbits.RBIF && INTCONbits.RBIE) // encoder 3-6 interrupt?
	{
		Port_B = PORTB; // remove the "mismatch condition" by reading port b 
		INTCONbits.RBIF = 0; // clear the interrupt flag
		Port_B_Delta = Port_B ^ Old_Port_B; // determine which bits have changed
		Old_Port_B = Port_B; // save a copy of port b for next time around
 
		if(Port_B_Delta & 0x10) // did external interrupt 3 change state?
		{
			#ifdef ENABLE_ENCODER_3
			Encoder_3_Int_Handler(Port_B & 0x10 ? 1 : 0); // call the encoder 3 interrupt handler (in encoder.c)
			#endif
		}
		if(Port_B_Delta & 0x20) // did external interrupt 4 change state?
		{
			#ifdef ENABLE_ENCODER_4
			Encoder_4_Int_Handler(Port_B & 0x20 ? 1 : 0); // call the encoder 4 interrupt handler (in encoder.c)
			#endif
		}
		if(Port_B_Delta & 0x40) // did external interrupt 5 change state?
		{
			#ifdef ENABLE_ENCODER_5
			Encoder_5_Int_Handler(Port_B & 0x40 ? 1 : 0); // call the encoder 5 interrupt handler (in encoder.c)
			#endif
		}
		if(Port_B_Delta & 0x80) // did external interrupt 6 change state?
		{
			#ifdef ENABLE_ENCODER_6
			Encoder_6_Int_Handler(Port_B & 0x80 ? 1 : 0); // call the encoder 6 interrupt handler (in encoder.c)
			#endif
		}
	} 
	else if(PIR1bits.ADIF && PIE1bits.ADIE) // ADC interrupt
	{
		PIR1bits.ADIF = 0; // clear the ADC interrupt flag
		ADC_Int_Handler(); // call the ADC interrupt handler (in adc.c)
	} 
}
This seems right to me, and compiles cleanly.

Any ideas what to try next?
A few things are wrong. The ADC code for the 2006 controller also uses timer 2, but I don't see its ISR. If timer 2 fires off and there isn't any way to clear the interrupt flag, you'll get the red-light-of-death. The attached file should work.

-Kevin
Attached Files
File Type: c user_routines_fast.c (7.1 KB, 50 views)
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #4   Spotlight this post!  
Unread 20-01-2006, 08:38
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: Combining ADC, Serial, and Camera_s codes

Quote:
Originally Posted by Kevin Watson
A few things are wrong. The ADC code for the 2006 controller also uses timer 2, but I don't see its ISR. If timer 2 fires off and there isn't any way to clear the interrupt flag, you'll get the red-light-of-death. The attached file should work.
Thanks, I'll have them try this tonight. I just noticed the lack of the timer2 ISR when I got this.
  #5   Spotlight this post!  
Unread 21-01-2006, 13:57
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: Combining ADC, Serial, and Camera_s codes

Quote:
Originally Posted by Kevin Watson
A few things are wrong. The ADC code for the 2006 controller also uses timer 2, but I don't see its ISR. If timer 2 fires off and there isn't any way to clear the interrupt flag, you'll get the red-light-of-death. The attached file should work.
This file mostly worked for us. We had to add in an include for encoder.h and the Port_B and Port_B_Delta variables.

Now, encoders 3 through 6 work fine (indeed, I can run all four of them, each generating 1600 pulses/sec, and it keeps up) in tandem with the gyro and camera. But if try to use encoder 1, I get the red-light-o-death as soon as something triggers it. And if I try to enable encoder 2, it doesn't build:

C:\FIRST 2006\FRC 21 Jan 2006\encoder.c:131:Error [1205] unknown member 'INT3IP' in '__tag_223'
C:\FIRST 2006\FRC 21 Jan 2006\encoder.c:131:Error [1131] type mismatch in assignment

I noticed this thread, but I've confirmed that my p18f8722.h (in c:\mcc18\h) file is the exact one from the installation CD, and there are no others on the system. Are there two versions of this .h floating around?

In any case, I've put the code online (with team-strategy specific stuff removed, but this version shows the problem) at this link. I can probably run with just encoders 3-6, but wanted to run speed control on 1 and 2.

Any ideas?
  #6   Spotlight this post!  
Unread 21-01-2006, 14:46
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: Combining ADC, Serial, and Camera_s codes

Quote:
Originally Posted by kaszeta
This file mostly worked for us. We had to add in an include for encoder.h and the Port_B and Port_B_Delta variables.

Now, encoders 3 through 6 work fine (indeed, I can run all four of them, each generating 1600 pulses/sec, and it keeps up) in tandem with the gyro and camera. But if try to use encoder 1, I get the red-light-o-death as soon as something triggers it. And if I try to enable encoder 2, it doesn't build:

C:\FIRST 2006\FRC 21 Jan 2006\encoder.c:131:Error [1205] unknown member 'INT3IP' in '__tag_223'
C:\FIRST 2006\FRC 21 Jan 2006\encoder.c:131:Error [1131] type mismatch in assignment

I noticed this thread, but I've confirmed that my p18f8722.h (in c:\mcc18\h) file is the exact one from the installation CD, and there are no others on the system. Are there two versions of this .h floating around?

In any case, I've put the code online (with team-strategy specific stuff removed, but this version shows the problem) at this link. I can probably run with just encoders 3-6, but wanted to run speed control on 1 and 2.

Any ideas?
Thinking you only wanted support for encoders on int 3 and int 4, that's what I included in the user_routines_fast.c I attached to my posting above. Use the file attached to this posting. Also, the p18f8722.h file included with the compiler is messed up. Use the one that's attached to this posting.

-Kevin
Attached Files
File Type: h p18f8722.h (44.1 KB, 80 views)
File Type: c user_routines_fast.c (7.7 KB, 78 views)
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org

Last edited by Kevin Watson : 21-01-2006 at 15:03.
  #7   Spotlight this post!  
Unread 22-01-2006, 20:23
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: Combining ADC, Serial, and Camera_s codes

Quote:
Originally Posted by Kevin Watson
Thinking you only wanted support for encoders on int 3 and int 4, that's what I included in the user_routines_fast.c I attached to my posting above. Use the file attached to this posting. Also, the p18f8722.h file included with the compiler is messed up. Use the one that's attached to this posting.
Thanks. It is working perfectly now. Now on to actually get the robot to do things.
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


All times are GMT -5. The time now is 01:03.

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