Page 1 of 1

Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Thu Feb 14, 2019 1:40 pm
by George_B
Hello all!


I am using an encoder with A and B signal outputs.

I also use an interrupt macro for INT0 (RB0) pin of a 18F4523 microcontroller with 20Mhz external crystal.

The encoder has 250 ppr.

I am wondering if there is any way of capturing the encoder's pulses faster?

At the moment i rotate the encoder quite slow by hand and i am able to capture the incoming pulses properly.

When i start rotating the encoder faster the interrupt seems to be unable to capture the pulses.

Any idea about that?


Best Regards
George

Re: Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Thu Feb 14, 2019 2:45 pm
by Benj
Hi George,

Can you post your project so we can see what's going on inside your interrupt macro.

Re: Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Thu Feb 14, 2019 5:37 pm
by QMESAR
also use an interrupt macro for INT0 (RB0) pin of a 18F4523 microcontroller with 20Mhz external crystal.
I am wondering if there is any way of capturing the encoder's pulses faster?
I always find these type of questions interresting
You want speed (faster) but to start with you run the micro at 50% of its rated speed WHY !!

Re: Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Thu Feb 14, 2019 6:57 pm
by medelec35
QMESAR wrote:I always find these type of questions interresting
You want speed (faster) but to start with you run the micro at 50% of its rated speed WHY !!
It could be an issue with flowchart and may find 20MHz is adequate?

Re: Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Thu Feb 14, 2019 7:18 pm
by QMESAR
HI Martin

Yes I agree it can be flowchart related however most of the time people are looking to speed up code but run at 20Mhz clock
which is x time for interupt exectution which is 0,5 of what it can be running at a proper clock speed .
It is all about knowing the numer off pulses ,the numer of cycles you need to execute the ISR and what is the actual time you have with x clock speed
it is not just I need more speed or faster this is the point I am trying to make not saying 20MHZ is in correct :D

Re: Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Fri Feb 15, 2019 1:20 pm
by George_B
Hello all, thank you for your replies.

here is the flowchart so you can see the actual code.

Just note that the crystal speed is 19.6608 Mhz and not 20Mhz as i said in my previous post.


Waiting your comments.


Best Regards
George

Re: Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Fri Feb 15, 2019 1:47 pm
by QMESAR
Hi

It seems you are runing an motor with an encoder attched.
What is the max speed of the motor ? and at what speed do you start to loose to detect encoder pulses?

Re: Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Fri Feb 15, 2019 1:55 pm
by medelec35
Hi George,
I was a bit confused by your flowchart.
The INT0 interrupt for encoder detection is RB0.
So if you look at the input within RB0 call macro you will see there is an input for E0.
The input should be for RB0 instead.
I'm therefore surprised the encoder works at all?

Re: Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Fri Feb 15, 2019 2:47 pm
by George_B
QMESAR wrote:Hi

It seems you are runing an motor with an encoder attched.
What is the max speed of the motor ? and at what speed do you start to loose to detect encoder pulses?

The encoder at the moment is not attached on the motor. The encoder movement is done by hand and the rotation speed is approximately less than 30 rpm. Note that the encoder has 250ppr

Re: Interrupt on INT0 pin - How fast an interrupt can capture external pulses

Posted: Fri Feb 15, 2019 2:52 pm
by George_B
medelec35 wrote:Hi George,
I was a bit confused by your flowchart.
The INT0 interrupt for encoder detection is RB0.
So if you look at the input within RB0 call macro you will see there is an input for E0.
The input should be for RB0 instead.
I'm therefore surprised the encoder works at all?

Hi Martin ,

The encoder i am using has two outputs A(first) and B(second). Therefore the first signal(A) triggers the ISR (INT0) and the second signal (B) is connected on RE0 of the microcontroller. The Read of RE0 status is needed in order to know the direction of the rotation of the encoder shaft.

I hope you understand what i am saying.


Regards
George