TIMER produces the interrupt with no counting

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

TIMER produces the interrupt with no counting

Post by r_romeo »

Hi, I am working in a code were inside a custom interuption (produced by a
external source) I have a timer interrupt that works fine the first time.
the problem is that from the second time the timer is activated, the timer
interrupt is activated but the interruption is activated inmediatly, without
counting.
Anyone knows why this can be happening ? , I am checking with a logic analyzer
and also with custom code to check the interruption is beeing generated.
In the graph I can see the interrupt is being generated rigth after the timer
is activated and before the time programed.
Somehow after the first activation the timer lost the parameters.
It does not matter wich timer I use
I also changed the delay , just in case the interrupt was been generated
outside boundaries , but that is not the problem.

I also get the warning:

------------------------------------------------------------------
D_01_03.c: In function '_T2Interrupt':
ID_01_03.c:3615: warning: PSV model not specified for '_T2Interrupt';
assuming 'auto_psv' this may affect latency
ID_01_03.c: In function '_T1Interrupt':
ID_01_03.c:3623: warning: PSV model not specified for '_T1Interrupt';
assuming 'auto_psv' this may affect latency
------------------------------------------------------------------


but the warning is in both timers, and one actually works fine, I dont know it's meaning
this is in a code were I can use use other timer interrupt that is working
fine, but the alternative is working as described.


Here are my flowcharts, one for transmission and other for reception and generation of signal (CAN) after certain time that shold be managed by TIMER 2
can-test-1-RX.fcf_pic16
(15.5 KiB) Downloaded 291 times
can-test-1-tx.fcf_pic16
(9.5 KiB) Downloaded 280 times
Also I have a screenshot that show what is happening
(RX and tx are swapt in the image)
Signal.jpg
(184.53 KiB) Downloaded 1207 times
As you can see the delay works the first time and then there is no count

Any ideas?

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: TIMER produces the interrupt with no counting

Post by r_romeo »

Something tells me the issue does not relate to the CAN bus communication
I did other example not using custom C code and I get the same behavior I couldn't make it work in simulation, but in hardware the Rx led turns on and off in half second the first time and then turns on in almost unnoticeable period, so looks off (the interruption is happening but without counting)

here is the code
can-test-1-RX.fcf_pic16
(15.3 KiB) Downloaded 313 times
can-test-1-tx.fcf_pic16
(9.5 KiB) Downloaded 308 times
I may be mistaking some concepts for timers , any idea?

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: TIMER produces the interrupt with no counting

Post by dazz »

Hi
Whilst i cant help with the code (only free version of dspic), if you open both your flowcharts then run vnet server (in the tools folder, theres a post somewhere on how to use it) you can link the flowcharts together to simulate ie send a message and watch what happens at the recieving end, this may then give you a clue as to whats happening

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: TIMER produces the interrupt with no counting

Post by r_romeo »

Thanks Dazz, As I post before the code works as explained in hardware, is a weird behavior , Does this happen just with CAN bus?
It should restart the timer each time detects an incoming CAN package and gives the answer with a certain delay after reception, I don't want to put a Delay block because I need to do other calculations .
works fine in the first detection, but in the second the interruption is produced like the settings for the timer were = 0 , and is not!!!

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: TIMER produces the interrupt with no counting

Post by LeighM »

In your Main macro, try adding the following C code, just before the call to “Enable TMR2”

IFS0bits.T2IF = 0;

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: TIMER produces the interrupt with no counting

Post by LeighM »

in can-test-1-RX.fcf_pic16

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: TIMER produces the interrupt with no counting

Post by r_romeo »

It's working !!, so was the flag I didn't turn off
Thank you !!
I wonder why this is not included in the Timer disable part of the code.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: TIMER produces the interrupt with no counting

Post by LeighM »

Currently, this timer flag is only cleared in the interrupt service routine.
This issue arises in your case as you are using the timer as a “one-shot” and as the timer actually remains running the timer interrupt flag is still being set every timeout period, even though no interrupt occurs due to it being disabled. Hence an interrupt occurs immediately that the interrupt is re-enabled. (We will look at clearing this flag in the Timer Interrupt Enable macro)
Regards,
Leigh

Post Reply