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

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

Problems with different preescaler Loops

Post 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?
Attachments
Teste_Loop.hex
(772 Bytes) Downloaded 221 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Problems with different preescaler Loops

Post 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

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

Re: Problems with different preescaler Loops

Post 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.

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

Re: Problems with different preescaler Loops

Post by Oderlando »

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

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

Re: Problems with different preescaler Loops

Post 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.

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

Re: Problems with different preescaler Loops

Post 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?

Post Reply