|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Reading interupt pin as Standard IO
I am trying to generate code that reads the pulswidth of a signal. I am avoiding use of Interupt pins 1 and 2 for later use. As my code is set up, I am trying to read the pulsewidth on pin 3. (BTW this is the Vex controller, I don't think it should make a difference though)
The code: Code:
#define accel_x rc_dig_int3
.......
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 */
if(accel_x){
WriteTimer1( 0x00 );
T1CONbits.TMR1ON = 1; // turn it on
}
else if (!accel_x){
T1CONbits.TMR1ON = 0; // turn it off
accel_xTilt= ReadTimer1();
WriteTimer1( 0x00 );
}
INTCONbits.RBIF = 0; /* and clear the interrupt flag */
}
Code:
void Process_Data_From_Local_IO(void){
if(accel_x){printf("ON\n");}
else if (!accel_x){printf("OFF\n");}
}
0n 0n .... I then press the switch 0n 0n 0n ....................... (Ons for about another second) Off Off It is the same for the 0ff to On transition. I thought maybe for some reason my ISR was consuming to much time, explaining the delay, and so I took all of my code out an left the default: 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 */
} /* to clear the interrupt condition. */
|
|
#2
|
|||||
|
|||||
|
Re: Reading interupt pin as Standard IO
The delay may be the USART waiting for the transmit buffer to clear of "On"s before the "Off"s are being sent. Try setting a pin high/low and reading that, it is a much faster response time.
|
|
#3
|
|||||
|
|||||
|
Re: Reading interupt pin as Standard IO
I second Mike's comment. I know the IFI loader's terminal window introduces a significant delay when there is continuous data coming in. Hyperterminal is much better.
I don't know how the Vex serial communication is implemented. It's likely that you're sending "on" and "off" messages faster than they can be transmitted, and that they're being buffered. |
|
#4
|
|||||
|
|||||
|
Re: Reading interupt pin as Standard IO
Quote:
|
|
#5
|
||||
|
||||
|
Re: Reading interupt pin as Standard IO
Quote:
Now I'm trying to do it with interrupts, and I have the code in the ISR as so: 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){
printf("High!n");
}
else if (accel_x ==0){
printf("LOW!n");
}
}
[EDIT]-Stupid mistake... I never enabled interrupts by setting bit : INTCONbits.RBIE :-p Last edited by intellec7 : 16-04-2006 at 00:29. |
|
#6
|
|||||
|
|||||
|
Re: Reading interupt pin as Standard IO
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.
ISRs should be reserved for things which take approximately no time to perform. Make a comparison, set a flag, store a value, maybe compute a delta or a sum. But try not to start something which will require waiting for something else to happen. |
|
#7
|
||||
|
||||
|
Re: Reading interupt pin as Standard IO
Quote:
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;
}
}
Does anyone have code that does frequency/duty cycle measurement? |
|
#8
|
|||||
|
|||||
|
Re: Reading interupt pin as Standard IO
Quote:
|
|
#9
|
||||
|
||||
|
Re: Reading interupt pin as Standard IO
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VEX inputs | Andrew Blair | FIRST Tech Challenge | 22 | 31-05-2006 18:17 |
| Encoders and putdata | theycallhimtom | Programming | 3 | 09-02-2006 19:24 |
| Attatching an axel to a wheel | Zoheb N | Technical Discussion | 36 | 12-12-2005 13:43 |
| Dynamic Input/Output Changing | Paolo | Control System | 6 | 23-09-2004 19:09 |
| 4 pin EDU PWM out power, red pin2 V in error | Dale(294engr] | Electrical | 4 | 13-02-2004 03:03 |