|
|
View previous topic :: View next topic |
Author |
Message |
greeniemax
Joined: 05 Jun 2013 Posts: 15
|
External Interrupt Timing |
Posted: Fri Sep 26, 2014 11:31 pm |
|
|
Hi,
I have a circuit where everything is working fine but because my board is installed in a heavy industrial place, I get lots of noise on my external interrupt, I tried adding capacitor to remove the noise and tried almost everything, finally the point manually over time.
I added a function to check input over time, so I make sure I'm getting input for at least 5ms before I consider it correct input as noise can't be this long and 5ms delay is not a problem for me. But code I wrote requires extra timer and there is 1 in billion chance it would fail because it checks for input every ms.
Is there a way to setup EXT interrupt so it only triggers after it gets constant signal for given time?
I'm using PIC18F46K22 - Running at 16MHz.
This is my code, which is pointless to post but I'll do anyways for checking input.
Code: |
#int_TIMER4
void TIMER4_isr(void)
{
if (input(PIN_B0) && !IntChecked)
{
IntOn++;
if (IntOn > 3000)
IntOn = 3000;
}
if (!input(PIN_A2))
{
IntOn = 0;
IntChecked = false;
}
} |
Code: |
int1 IntCheck(void)
{
if (IntOn > 5)
{
IntOn = 0;
IntChecked = true;
return true;
}
return false;
}
|
Code: |
if (IntCheck())
{
//Do process
}
|
As my process is waiting for input before it does anything and there are maximum of 2 process per second, it's not a problem of delay.
Thanks, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Sat Sep 27, 2014 12:22 am |
|
|
Fundamentally no.
However consider another approach.
Have a 'tick' interrupt at (say) 10mSec intervals.
Then have this read the interrupt pin, and code like:
Code: |
int1 pin_seen=FALSE;
#INT_TIMERx //whatever timer you use.
void tick(void)
{
static int1 last=FALSE;
static int1 have_reacted=FALSE;
if (input(PIN_xx)) //whatever pin your input is on
{
if (last)
{
if (have_reacted==FALSE)
{
pin_seen=TRUE;
have_reacted=TRUE;
//or have the code you want when the pin is seen here
}
}
last=TRUE;
}
else
{
last=FALSE;
have_reacted=FALSE;
}
}
|
This way, 'pin_seen' will go 'TRUE', when the input is high for two _successive_ ticks. Clear it in the main once handled. Obviously you can reverse the test if you want to look for the signal going low. If your interrupt wants to actually 'do' something, rather than just set a flag, then put the code where shown.
This is the same approach I often recommend for key de-bounce.
You are 'half way there' with what you currently do, but it is needlessly complex. |
|
|
greeniemax
Joined: 05 Jun 2013 Posts: 15
|
|
Posted: Sat Sep 27, 2014 5:07 am |
|
|
Thanks Ttelmah,
Your code looks much refined, I'll use this one.
But it seems like there is no way to configure interrupt to have this delay?
Thanks and Regards, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19503
|
|
Posted: Sat Sep 27, 2014 8:41 am |
|
|
As I said in my first line, no.
It's not what you want from an interrupt. The whole 'point' of an interrupt is to get a prompt response. This is not what you want (you need a delay), and not normally what interrupts are used for. If you want an interrupt with a delay, you would need to build an external circuit to provide this. You could use an external retriggerable monostable multivibrator, or even a really simple 8pin PIC, to just provide the pre-processing.
Though your problem is not 'bounce', the effect, and requirements are the same. Have a look at:
<http://electrosome.com/switch-debouncing/>
For some hardware solutions. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|