Page 1 of 1

TIMER produces the interrupt with no counting

Posted: Mon Nov 19, 2012 4:11 pm
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 378 times
can-test-1-tx.fcf_pic16
(9.5 KiB) Downloaded 372 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?

Re: TIMER produces the interrupt with no counting

Posted: Tue Nov 20, 2012 8:31 pm
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 417 times
can-test-1-tx.fcf_pic16
(9.5 KiB) Downloaded 408 times
I may be mistaking some concepts for timers , any idea?

Re: TIMER produces the interrupt with no counting

Posted: Tue Nov 20, 2012 8:55 pm
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

Re: TIMER produces the interrupt with no counting

Posted: Wed Nov 21, 2012 10:33 am
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!!!

Re: TIMER produces the interrupt with no counting

Posted: Wed Nov 21, 2012 12:06 pm
by LeighM
In your Main macro, try adding the following C code, just before the call to “Enable TMR2”

IFS0bits.T2IF = 0;

Re: TIMER produces the interrupt with no counting

Posted: Wed Nov 21, 2012 12:10 pm
by LeighM
in can-test-1-RX.fcf_pic16

Re: TIMER produces the interrupt with no counting

Posted: Wed Nov 21, 2012 1:27 pm
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.

Re: TIMER produces the interrupt with no counting

Posted: Wed Nov 21, 2012 2:09 pm
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