View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 22, 2009 3:44 pm |
|
|
Also, in your #INT_RB function, you need to read Pin B1 to clear the
"mismatch" condition. The "mismatch" condition is what generates
the INT_RB interrupt. You need to clear it so the PIC will be ready
to detect the next "change" (edge) tha occurs on pin B1. It's cleared
by reading the pin. Add the lines shown in bold below.
Quote: |
#INT_RB
void ext_isr()
{
int8 temp;
if(irdone) return;
for(ircount=0;ircount<=13;ircount++)
{
irframes[ircount]=get_timer1();
}
//irframes[ircount++]=get_timer1();
if(ircount>=13) //if 13 triggers(ie 12 bits+start) found
irdone=true; //set "done" flag
set_timer1(0); //restart timer for new bit
enable_interrupts(int_timer1);
temp = input(PIN_B1);
} |
I didn't look at your code and try to figure out what you're doing.
I just wanted to mention this one thing. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Feb 23, 2009 3:23 am |
|
|
Yes, a very important hint by PCM Programmer. I wrongly assumed, you would be using an external edge sensitive interrupt. Cause you are actually using RB interrupt, do you intend to detect both edges? If not, the code has to be corrected to ignore the other edge for timing measurement. |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Mon Feb 23, 2009 4:07 am |
|
|
Thanks for reply FvM and PCM programmer
Quote: | You need to clear it so the PIC will be ready
to detect the next "change" (edge) tha occurs on pin B1. It's cleared
by reading the pin. |
I had made some corrections in my code.
Code: |
#INT_RB //IR bits detected by edge triggering
void ext_isr()
{
int8 temp;
if(irdone) return;
irframes[ircount++]=get_timer1();
if(ircount>=13) //if 13 triggers(ie 12 bits+start) found
irdone=true; //set "done" flag
set_timer1(0); //restart timer for new bit
enable_interrupts(int_timer1); //(is this necessary? I dont really know)
temp = input(PIN_B1);
}
|
The result is better than the first time.
Quote: | Cause you are actually using RB interrupt, do you intend to detect both edges? If not, the code has to be corrected to ignore the other edge for timing measurement. |
Yes, I want to detect both edges, from tsop1740 ir sensor.
Now, I have some timing problems. irframes[2], irframes[3] are bigger than expected, and irframes[8], irframes[9], irframes[10] and irframes[11] are smaller. I don't know why this is happening, I will do some research.
|
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Wed Feb 25, 2009 1:32 am |
|
|
Doesn't anybody know why I get this timers?
Because I use TSOP1740 and the source code was for 1738? My timer is not set correct? |
|
|
pyu
Joined: 04 Feb 2009 Posts: 51
|
|
Posted: Sun Mar 08, 2009 9:20 am |
|
|
Anyone? |
|
|
|