View Single Post
  #7   Spotlight this post!  
Unread 16-04-2006, 20:42
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: Reading interupt pin as Standard IO

Quote:
Originally Posted by Alan Anderson
As a general rule, using printf in an interrupt service routine is a Bad Idea. The serial communication library routines might handle it without causing issues...or they might not.
I was just doing that to see when the ISR was running.
My actual code is
Code:
	else if (INTCONbits.RBIF && INTCONbits.RBIE){  /* Ints 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 */
		
		if(accel_x){
			//Here it measures the Low time
			T1CONbits.TMR1ON = 0; // turn it off
			accel_xTiltC=ReadTimer1();
			WriteTimer1( 0x00 );
			T1CONbits.TMR1ON = 1; // turn it on
			Status = 2;
		}
		else if (accel_x ==0){
			//This time it measures the High time
			T1CONbits.TMR1ON = 0; // turn it off
			accel_xTilt= ReadTimer1(); //capture timer value
			WriteTimer1( 0x00 );
			T1CONbits.TMR1ON = 1; // turn it on
			Status = 1;
		}
	}
accel_xTilt is an unsigned integer, and since Timer1 is configured as a 16 bit timer, that should be suffice to hold any timer value right? But from 6ms - 4 ms I get negative values! I thought maybe for some reason it was wrapping around and doing something funny, so when I made it a long I got all zero values.
Does anyone have code that does frequency/duty cycle measurement?