Problems with different preescaler Loops
-
- Posts: 37
- Joined: Tue Jul 17, 2018 11:30 am
- Has thanked: 7 times
- Been thanked: 3 times
- Contact:
Problems with different preescaler Loops
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 229 times
- QMESAR
- 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
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
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
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
-
- 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
Excuse me. Only now I noticed that I posted the wrong file. I'll send the correct one as soon as I get home.
-
- 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
I am sending the correct file.
- Attachments
-
- Teste_Loop.fcfx
- (10.83 KiB) Downloaded 233 times
- 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
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.
Maybe use a different timer peripheral for the second enable icon or have both interrupt enable icons point to the same macro.
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.
You can see the problem in the interrupt function inside the C code.#warning "This interrupt has previously been enabled, so the macro <Interrupt2> may never get called."
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
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
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?