cypher
Joined: 05 Oct 2007 Posts: 31
|
#int_ext not working |
Posted: Tue Feb 26, 2008 6:23 pm |
|
|
Hi,
This is really weird because the code below was working a while back, but when I tried incorporating it with some other code, it kept on generating interrupts even without any pin connected to RB0. So I hard reset the whole system and the next time I ran the code, it would not generate any interrupts at all on int_ext. I tried the same code with int_ext1 and it worked.
I measured the voltage on RB0, and it measures around 300mV, thus explaining why it would not interrupt. I don't think the PIC is seeing a rising edge because RB0 is never high even though I make it high. There is a voltage drop somewhere. I did the same thing with int_ext1 and it measures 5 V as expected going from Low to High. I'm just using a switch with a pull-up 10K resistor to simulate an interrupt on the rising edge/falling edges.
Does anyone know
1. Why the PIC would interrupt at random even without any trigger on the pin?
2. Why RB0 is not going to 5V when I switch on the switch. Why is there a voltage drop?
Code: |
#include <18F8722.h>
#device ADC=10
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)
#use standard_io(B)
#use standard_io(D)
#use standard_io(E)
#define ENABLE PIN_B0
long time;
float time2;
int count = 0;
void main()
{
output_d(0);
output_e(0);
set_tris_d(0x20);
set_tris_e(0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
ext_int_edge(H_TO_L);
enable_interrupts(int_ext);
enable_interrupts(global);
while(1)
{
} //while
} //main
#int_ext
void pulse_width(void)
{
int state = 0;
state = input(ENABLE);
if(state == 0)
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
set_timer0(0);
clear_interrupt(int_rtcc);
enable_interrupts(int_rtcc);
printf("H TO L\r");
clear_interrupt(int_ext);
ext_int_edge(L_TO_H);
}
if(state == 1)
{
time = get_timer0();
disable_interrupts(int_rtcc);
setup_timer_0(RTCC_OFF);
time2 = ((float)(count * 3.36) + (float)(0.0000512 * time));
printf("L TO H\r");
printf("Count = %d\r",count);
printf("Time = %lu\r",time);
printf("Time taken = %f\r",time2);
clear_interrupt(int_ext);
count = 0;
time = 0;
ext_int_edge(H_TO_L);
}
}
#int_rtcc
void timer_int(void)
{
count = count + 1;
clear_interrupt(int_rtcc);
printf("Count = %d\r",count);
}
|
|
|