• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

code for timer interrupts with different on off times

Q&A Forum › code for timer interrupts with different on off times
0 Vote Up Vote Down
Henk La Dru asked 2 years ago

cannot seem to find any code that uses interrupts  for different on/off settings. Using delay is not recommended for this type of application require interrupts within operating loop so how do you set variable on of times of outputs

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
I’m not sure that I understood your question.
Can you try to provide more details or explain in a different way?
Regards,
Sara

0 Vote Up Vote Down
LoetLuemmel answered 2 years ago

I think I have the same problem. – We would encourage a sample of 2 or more interrupt timers in parallel.
So a sample project like:

Unit 6 – ESP32 with PIR Motion Sensor: Interrupts and Timers

I am struggling with two timers in parallel:
 

// Timer Interrupt

hw_timer_t *timer1M = NULL;
void IRAM_ATTR onTimer1M()
{
// ISR
timer1M_trigger = TRUE;
}
hw_timer_t *timer5M = NULL;
void IRAM_ATTR onTimer5M()
{
// ISR
timer5M_trigger = TRUE;
}

// Timer 1 min
timer1M = timerBegin(0, 80, true);
timerAttachInterrupt(timer1M, &onTimer1M, true);
timerAlarmWrite(timer1M, 60000000, true);
digitalWrite(LED, !digitalRead(LED));
timerAlarmEnable(timer1M);

// Timer 5 min
timer5M = timerBegin(0, 80, true);
timerAttachInterrupt(timer5M, &onTimer5M, true);
timerAlarmWrite(timer5M, 60000005, true);
timerAlarmEnable(timer5M);

(Please note: Timer values and prescaler values are not 1 and 5 minutes, as I am still experimenting.)

 
What is happening? – Timer1 fires correctly, but the implementation for the 2nd timer seems to be wrong.
A sound sample might help us all here.
 
Happy hacking’!

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
At the moment, we don’t have any examples about that.
Have you taken a look at this library? https://github.com/philbowles/H4
It seems to provide functions for multiple timers. Take a look at its most simple example: https://github.com/philbowles/H4/blob/master/examples/multiblink/multiblink.ino
 
Does this help?
 
I’ll add that subject to my list of future tutorials.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.