Problems with different preescaler Loops

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Oderlando
Posts: 25
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Problems with different preescaler Loops

Postby Oderlando » Tue Feb 12, 2019 12:48 pm

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?
Attachments
Teste_Loop.hex
(792 Bytes) Downloaded 25 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1087
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 334 times
Been thanked: 544 times
Contact:

Re: Problems with different preescaler Loops

Postby QMESAR » Tue Feb 12, 2019 5:45 pm

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

Oderlando
Posts: 25
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Problems with different preescaler Loops

Postby Oderlando » Tue Feb 12, 2019 5:55 pm

Excuse me. Only now I noticed that I posted the wrong file. I'll send the correct one as soon as I get home.

Oderlando
Posts: 25
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Problems with different preescaler Loops

Postby Oderlando » Wed Feb 13, 2019 12:23 pm

I am sending the correct file.
Attachments
Teste_Loop.fcfx
(10.83 KiB) Downloaded 25 times

User avatar
Benj
Matrix Staff
Posts: 14130
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4325 times
Been thanked: 4070 times
Contact:

Re: Problems with different preescaler Loops

Postby Benj » Thu Feb 14, 2019 2:50 pm

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.

Oderlando
Posts: 25
Joined: Tue Jul 17, 2018 11:30 am
Has thanked: 7 times
Been thanked: 3 times
Contact:

Re: Problems with different preescaler Loops

Postby Oderlando » Thu Feb 14, 2019 9:16 pm

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?