News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Timer interrupt is stopped

Started by Amateurtje, Jan 20, 2024, 09:26 PM

Previous topic - Next topic

Amateurtje

Hello all,

I have a script running a timer interrupt (and several others).. It is running a clock....

In some parts of the program my time seems to be delayed: the timer interrupt is stopped (not executed). As far as I can find, it is not deliberatly stopped..

I seem to remember something that the Delayms command does postpone the interrupt, but I can not find that anywhere.
If so, I could solve that with a kind of wait prcedure with a counter and a very short delay..


Anybody an idea or a good solution?

tumbleweed

Delayms doesn't use any hardware timers or disable interrupts, so your problem is elsewhere.

I'd look at your interrupt handler.

Stephen Moss

#2
As tumbleweed stated the delay command will not interfere with an interrupt as it is essentially a loop the executes a specified number of NOP commands, so the interrupts will slightly lengthen the delay of the DelaycS/mS/uS commands.

By
Quote from: Amateurtje on Jan 20, 2024, 09:26 PMthe timer interrupt is stopped (not executed)
do you mean the program hangs completely and stops operating or just that it appears that it is not entering the interrupt handler?
Have you tried turning an LED on at the start of the interrupt handler and off at the end, ideally both followed by a 0.5 second delay so you can see the LED switching. That way you can confirm whether or not the interrupt handler is being called and executed or not.
 
Posting your code (or at least a snippet of it for a very long program) would allow people a better chance of identifying what the problem may be. If the interrupt is being skipped then perhaps you are disabling the interrupt somewhere.

ADDEMDUM 23/01/2024:
Sorry I forgot to mention this when posting initially, but are you clearing the relevant interrupt flag within your ISR? If not then it may only register the first interrupt of that type as there can be no subsequent changes in state to the interrupt flag as it is being left permanently in its set state (I think that's how it works).

Amateurtje

Hello guys,

Thanks a lot for the info.. It seems that the interrupt part all works fine and my problem is completely somewhere else.. I am sorry. On different forums, diffrent rules are valid.. I think, while the problem is soo different I should start a new thread but that is liek reading a book without the end...

I my script, I try to have a good running clock. that runs on an interrupt, between two cycles that it synchronises with a RTC chip, DS3231SN. The problem is that I now have to make a clock with it that runs a accuratly within a couple of hundreths. the chip gives has a high accuracy but gives with I2c only a second.

My idea was:
- reading the chip
- Add 1 second (I tired  even 2, but no help)
- Keep reading the chip untill it has the same second.
-assume the second just started and start my own interrupt clock....

The chip does not have a pps pulse or anything. It has a wave but it is unclear when it starts. I know all can be solved with a GPS receiver but that is no option.

Therefore my clock deviates. Always wihtin the correct second but thats too much...

Anybody a good alternative idea? :)  :)

trastikata

Quote from: Amateurtje on Jan 26, 2024, 03:24 PMI my script, I try to have a good running clock. that runs on an interrupt, between two cycles that it synchronises with a RTC chip, DS3231SN. The problem is that I now have to make a clock with it that runs a accuratly within a couple of hundreths. the chip gives has a high accuracy but gives with I2c only a second.

Hello Amateurtje,

the DS3231SN INT can be set to activate on different alarms. As I see it:

- connect the DS3231SN INT pin to any of the MCU external Interrupt pins
- read the the current second
- set alarm for timestamp say 3 seconds from now
- monitor the external interrupt and sync on change

Amateurtje

Mm, that could be an good idea.. Would be a nice experiment. but if during the receiving or setting of the alarm, the second is changed in the rtc chip, it could result in an extra second deviation.. Due to the time it takes receiving and sending back, I suspect this can happen...

You think?


trastikata

Quote from: Amateurtje on Jan 26, 2024, 05:30 PMMm, that could be an good idea.. Would be a nice experiment. but if during the receiving or setting of the alarm, the second is changed in the rtc chip, it could result in an extra second deviation.. Due to the time it takes receiving and sending back, I suspect this can happen...

No, it can't go wrong because the alarm is time-of-day/date.

Thus for example you read Jan-26th,2024 / 10:25:45 and set the alarm for 3 seconds later i.e. Jan-26th,2024 / 10:25:48

So you'll always know in advance what time exactly it is when the INT pin changes.

tumbleweed

#7
QuoteThe chip does not have a pps pulse or anything. It has a wave but it is unclear when it starts.
The DS3231 has multiple outputs... an INT/SQW output and a 32KHZ output, both of which are open-drain outputs and require a pullup.
Both of those are active once you program the control registers to enable the outputs.

The INT/SQW output can be set for 1HZ or a number of other freqs.
You could use either of them to sync your timer.