Page 1 of 1

Secund counter, again.

Posted: Mon Oct 17, 2011 1:15 pm
by jgu1
Hi all!

I am again, try and use the interrupt hours2 in a study. I made this second count. Although I have copied Martin's FC in a previous project, I can not get the time to fit exactly. When I compare with the stopwatch, it looks like the counter lose time when it flip over from 59 to 00. :?: What am I doing wrong?

Is there anyone who can help.

Thank you in advance.

Best regard

jgu1

Re: Secund counter, again.

Posted: Mon Oct 17, 2011 1:44 pm
by dbasnett
You are doing a lot in the interrupt code, including updating the LCD. What if the interrupt code just added 1, and the rest of the code was in a different macro that was called from within the loop?

Re: Secund counter, again.

Posted: Mon Oct 17, 2011 1:49 pm
by jgu1
Hi DBSNETT and all!


Exactly, solved!. I moved the display update. And now it work´s.

Thank´s! :D

Best regard.

jgu1.

Re: Secund counter, again.

Posted: Mon Oct 17, 2011 1:50 pm
by dbasnett
See attached (not tested BTW)

Re: Secund counter, again.

Posted: Tue Oct 18, 2011 6:07 am
by jgu1
Hi DBASNET!

Thank you for your examble! I am testing. So it´s best when the interrupt timer expires, it must not make too much.

Now I learn some new. :D

Thank´s

Best regard

jgu1

Re: Secund counter, again.

Posted: Tue Oct 18, 2011 7:57 am
by medelec35
Hi jgu1
If you look here:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936
I covered this about About half way down the page some time ago:
medelec35 wrote:
Timer interrupts macros:

It is important that you do not place any delays or components that will have delays in like LCD displays ,RS232 etc within timer interrupts. Keep interrupt macros as short as possible.
Components like LEDs and calculation icons are OK to use.
If you do use delays which lasts for longer than the timer interrupt takes to trigger, then corruption will occur giving unexpected results.
If you want to update a LCD display after an interrupt has occurred, then set a flag to 1 within interrupt. E.g. update_lcd=1
then for your LCD have a decision branch E.g
If lcd=1 then display macros : lcd=0
Martin

Re: Secund counter, again.

Posted: Tue Oct 18, 2011 11:12 am
by jgu1
Thank you Martin. I will follow the instructions. :D

Best regard

jgu1

Re: Secund counter, again.

Posted: Tue Oct 18, 2011 3:38 pm
by dbasnett
medelec35 wrote:Hi jgu1
If you look here:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936
I covered this about About half way down the page some time ago:
medelec35 wrote:
Timer interrupts macros:

It is important that you do not place any delays or components that will have delays in like LCD displays ,RS232 etc within timer interrupts. Keep interrupt macros as short as possible.
Components like LEDs and calculation icons are OK to use.
If you do use delays which lasts for longer than the timer interrupt takes to trigger, then corruption will occur giving unexpected results.
If you want to update a LCD display after an interrupt has occurred, then set a flag to 1 within interrupt. E.g. update_lcd=1
then for your LCD have a decision branch E.g
If lcd=1 then display macros : lcd=0
Martin
In the code provided by the OP it appears that the LCD update happens once per second, and there is already code to check for that. The problem was that all of the code was in the interrupt routine, and as you pointed out, that is not a good idea.