Timer interrupts.

I am working on creating a circuit that would turn off a hot plate after a period of time.

The circuit consists of Arduino Nano with Atmega 328, some circuit with a transistor and a solid state relay.
There are also input buttons and output LEDs.

After a while, I realized that I should use timers in my project.

One timer would count out the time period that I set and completely switch off the solid state relay circuit after that period of time is over.
Another timer will switch the solid state relay on and off to create very slow pulse width modulation - 30 second base frequency will work very well...

One timer will turn of a pot of soup in t hour, while another timer will be used to bring the pot to the boiling point at maximum heat and than keep it boiling at 60% duty cycle.


cli();//stop interrupts

//set timer1 interrupt at 1Hz
  TCCR1A = 0;// set entire TCCR1A register to 0
  TCCR1B = 0;// same for TCCR1B
  TCNT1  = 0;//initialize counter value to 0
  // set compare match register for 1hz increments
  OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler
  TCCR1B |= (1 << CS12) | (1 << CS10);  
  // enable timer compare interrupt
  TIMSK1 |= (1 << OCIE1A);

sei();//allow interrupts

Is there any way to set the timer prescaler that would make it trip every minute instead of every second?

As I understand that every time the timer will trip, I will have to have a variable timekeeper++ and also I will need code to check if timekeeper == the value that I set. Also I will have to reset the timer to count me out another set time interval without occupying the processor with a Delay().

This way I can keep time and not worry about having my microcontroller busy counting out a Delay() all the time.
Is there a more efficient way to solve a problem with heating a pot of soup for an hour, firstly at maximum heat, than at lower temperatures? I want to use the most memory and processor - efficient code because this microcontroller will have to do some other jobs as well...

Thank you.

Why do you need to diddle with timers? Turning the relay off and on at regular intervals might. Turning the relay off after a defined interval simply requires that you determine, on each pass through loop(), if the device has been on long enough. Look at the blink without delay example.

Is there a more efficient way to solve a problem with heating a pot of soup for an hour, firstly at maximum heat, than at lower temperatures?

Efficient and understandable are not the same thing. Go with understandable.

I want to use the most memory and processor - efficient code because this microcontroller will have to do some other jobs as well...

Then f**king with the timers hardly seems like the best approach.

Base your code on the techniques on BlinkWithoutDelay sketch unless the times are
measured in milliseconds or less.

Where do I find Blinwithoutdelay sketch?

Examples > 02. Digital > BlinkWithoutDelay

Look at lots of examples while you are at it, its informative

A more professional approach is to use timers, right?
I may have to add an LCD screen to my circuit to make it easier to understand the modes of operation so using a loop() may be unwise.

Is it possible to make Timer1 trip every minute?

My program will take an input of three buttons: (+5 minutes), (+15 minutes) and (+30 minutes).

Than it will take the sum of the values and keep the load operational for the period of time I entered, while signaling with LEDs that the program has been set. The program will heat the hot plate at 100% duty cycle for 10 minutes but than it will go to 60% duty cycle and switch off at the time I set.

Using timers is appropriate for things that must happen at specific intervals. Using a timer when +/- 5 seconds is acceptable is not reasonable. Why are you trying to make your program more complicated than it needs to be?

I will not insist on using timers. Maybe I don't need them.

I will use millis(); function.

As long as you do not need too much memory space, I would recommend the time alarms library available at: TimeAlarms Library, Run Functions At Specific Times.
It has functions to create timers that will go off after a certain number of seconds. (Remember to read the readme.txt for full details).
All you need to do is create a one time timer set to go off after a set amount of time. Simply create a method that receives the number of minutes that the pot will boil for, multiply that number by 60 to get the number of seconds, and create a timer to go off after that amount of time.
Be aware that the library is pretty big, and it needs the Time library ( a link is on the page same page), but I don't see much reason in over complicating a program (Occam's Razor is the best tool for a programer).