Is there a way to launch an external interrupt on INT0 (pin D2 on Arduino) from the DS1307 at a specified interval ranging from 1s to a a few minutes (most importantly 1 minute)?
I don't have any free timers or their pins are occupied.
I know I can do the 1s interval with the 1Hz SQ output, but launching an interrupt every second and counting to 60s so that some code is executed seems excessive and lots of wasted time.
I think that's the only way with the 1307 as it has no alarm function. But an interrupt that just increments and checks a counter doesn't really take much time. At 16MHz an ISR that does so little will take about 5us. Once per second means it would be using 0.0005% of your processor's bandwidth.
There are no alarms or interrupts available on the DS1307 other than the square wave output. If you don't want to count 1 Hz interrupts you will need to substitute a DS3231 or another RTC with alarms. The overhead of an interrupt and counting to 60 is not many processor cycles and I would not characterize it as "lots of wasted time".
I don't have any free timers or their pin are occupied.
Please explain more. Depending on how the timers are being used, it may be possible to do something with an overflow or compare interrupt without involving the output pins.
If I'm using timer1 (16 bit) in Fast PWM mode with output on OC1A using ICR1 as TOP, can I still use this timer to launch an interrupt? Would be useful to have a timer that counts to more than 255, so more than 255 seconds at a time.
Would be useful to have a timer that counts to more than 255, so more than 255 seconds at a time.
??
The longest period you can get out of Timer 1 with a 1024 prescaler is a little over 4 seconds.
I believe that you are headed in the wrong direction trying to use the hardware timers to get long time periods. Your best approach may be counting the 1Hz interrupts on the DS1307.
Why do you want to use some sort of hardware interrupt instead of a software timer using millis()?
What are you trying to achieve?
8 bit timer => 255 steps
1Hz from the RTC => 255 seconds
I want to make a logger that records a Voltage over a few hours.
Will use the EEPROM of the AT24C32 that comes with the RTC board to store the Voltages.
I want the measurements interval to be chosen by the user. So I was thinking something from 1s to a few hours should do.
I will probably buy the DS3231 if that can send a pulse at an interval I can program into it. Can I?
dragospuri:
8 bit timer => 255 steps
1Hz from the RTC => 255 seconds
I want to make a logger that records a Voltage over a few hours.
Will use the EEPROM of the AT24C32 that comes with the RTC board to store the Voltages.
I want the measurements interval to be chosen by the user. So I was thinking something from 1s to a few hours should do.
I will probably buy the DS3231 if that can send a pulse at an interval I can program into it. Can I?
32 bit timer (unsigned long int) => 4294967296
1Hz from the RTC => 136.1925 years
aarg:
32 bit timer (unsigned long int) => 4294967296
1Hz from the RTC => 136.1925 years
Yeah. Unfortunately I need that timer in PWM mode as I said. Which, if I got it right, means I can can't also use it to trigger an interrupt once it reaches a certain number.
dragospuri:
Yeah. Unfortunately I need that timer in PWM mode as I said. Which, if I got it right, means I can also use it to trigger an interrupt once it reaches a certain number.
Nah. You don't need any hardware timer. Just an unsigned long int variable, which you increment with every 1Hz pulse from the RTC. The software overhead is microscopic.