Page 1 of 1

Problems with different preescaler Loops

Posted: Tue Feb 12, 2019 12:48 pm
by Oderlando
Hello. I'm having some problems regarding timing through interrupts. I need to understand a concept that is giving me problems in my project. I'm posting a reduced flowchart just so I can understand the idea. In the original flowchart I need someone who at a given time has a wide interval between interruptions and at a later time I need a shorter interval between interrupts. So I decided to use two loops: the first one has a 1: 256 prescaler and the second loop has a 1: 1 prescaler. Theoretically, in the first loop I would get a delay of 49.80ms and in the second loop I would get a delay of 50.00ms. To test, I used a led that should turn off and on at equal intervals of time, but it looks like the second loop takes more time than the first one. Can anyone explain me why this occurs?

Re: Problems with different preescaler Loops

Posted: Tue Feb 12, 2019 5:45 pm
by QMESAR
Hi

Please help me understand how you think we should help you with a hex file you posted?
(1) we do not know your config settings from the hex file
(2) we do not know what controler you are using
(3) we can not see how you setup and change your intterupt routines

I would expect no body is going to analyse a hex file :D

Re: Problems with different preescaler Loops

Posted: Tue Feb 12, 2019 5:55 pm
by Oderlando
Excuse me. Only now I noticed that I posted the wrong file. I'll send the correct one as soon as I get home.

Re: Problems with different preescaler Loops

Posted: Wed Feb 13, 2019 12:23 pm
by Oderlando
I am sending the correct file.

Re: Problems with different preescaler Loops

Posted: Thu Feb 14, 2019 2:50 pm
by Benj
Hello,

An interrupt cannot be assigned to two different macros. This is down to the way the generated code works.

We provide this warning in the compiler messages.

#warning "This interrupt has previously been enabled, so the macro <Interrupt2> may never get called."


You can see the problem in the interrupt function inside the C code.

Code: Select all

void MX_INTERRUPT_MACRO(void)
{

    //Handler code for [TMR0]
    #ifndef MX_INTHANDLER_INTCON_TMR0IF
    #define MX_INTHANDLER_INTCON_TMR0IF
    if (ts_bit(INTCON, TMR0IF) && ts_bit(INTCON, TMR0IE))
    {
        FCM_inerrupt1();
        cr_bit(INTCON, TMR0IF);
    }
    #else
    #warning "This interrupt has previously been enabled, so the macro <inerrupt1> may never get called."
    #endif


    //Handler code for [TMR0]
    #ifndef MX_INTHANDLER_INTCON_TMR0IF
    #define MX_INTHANDLER_INTCON_TMR0IF
    if (ts_bit(INTCON, TMR0IF) && ts_bit(INTCON, TMR0IE))
    {
        FCM_Interrupt2();
        cr_bit(INTCON, TMR0IF);
    }
    #else
    #warning "This interrupt has previously been enabled, so the macro <Interrupt2> may never get called."
    #endif


}


Maybe use a different timer peripheral for the second enable icon or have both interrupt enable icons point to the same macro.

Re: Problems with different preescaler Loops

Posted: Thu Feb 14, 2019 9:16 pm
by Oderlando
Would it be possible for me to read the Timer0 record in the first loop (in order to get a higher resolution) using FCV_Variable = TIMER0?