Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Processing pre-set Interrupts (http://www.chiefdelphi.com/forums/showthread.php?t=34560)

Tom Bottiglieri 13-02-2005 14:44

Processing pre-set Interrupts
 
I am having troubles with my encoder. It is a 128 ppr encoder, and at close to maximum shaft RPM, I start to get bad readings from it. I figured this was from the RC trying to process too many interrupts per second, so I know I need decrease the ppr of the encoder.

The way I thought I could do this was by including a true/false check statement in the InterruptHandlerLow() function that would only call the Encoder Handler Function every other time that interrput happened. I tried doing this with if's and switch statements, but neither worked. I still got 128 ticks per revolution.

Heres a sample of the code I am using.
Code:

unsigned char loops=0;

void InterruptHandlerLow()   
{   
    if(loops==0)
    {
        if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) // left encoder interrupt?
                {
                        INTCON3bits.INT2IF = 0; // clear the interrupt flag [91]
                        Left_Encoder_Int_Handler(); // call the left encoder interrupt handler (in encoder.c)
                }
          loops=1;
    }
    else loops=0;
}

Any ideas?

Kevin Watson 13-02-2005 15:41

Re: Processing pre-set Interrupts
 
Quote:

Originally Posted by Tom Bottiglieri
I am having troubles with my encoder. It is a 128 ppr encoder, and at close to maximum shaft RPM, I start to get bad readings from it. I figured this was from the RC trying to process too many interrupts per second, so I know I need decrease the ppr of the encoder.

The way I thought I could do this was by including a true/false check statement in the InterruptHandlerLow() function that would only call the Encoder Handler Function every other time that interrput happened. I tried doing this with if's and switch statements, but neither worked. I still got 128 ticks per revolution.

Heres a sample of the code I am using.
Code:

unsigned char loops=0;
 
void InterruptHandlerLow()
{
if(loops==0)
{
if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) // left encoder interrupt?
                {
                        INTCON3bits.INT2IF = 0; // clear the interrupt flag [91]
                        Left_Encoder_Int_Handler(); // call the left encoder interrupt handler (in encoder.c)
                }
loops=1;
}
else loops=0;
}

Any ideas?

Check the magical Encoder FAQ for a possible answer.

-Kevin


All times are GMT -5. The time now is 23:56.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi