Quick measures & watchdog timers

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Quick measures & watchdog timers

Post by jsclownfish »

What is the best way to quickly toggle an input or output? I've run into this a couple times when I want to send a quick pulse signal to my autofeeder or record a timepoint value. I've been using something like this

Code: Select all

{
    if (minute()==0 && second()<5)
{
    if (now()%3600) set_average(0, hour());
because I don't want it to set_average but once an hour so I don't constantly keep rewriting over the memory location for an hour. When I set it to second()==0, it doesn't work. Maybe it is too fast and it misses it? I also did this for my autofeeder, but it seems to work.

Code: Select all

//Autofeeder Mode
  if ( InternalMemory.read(VacationEnable) == 1 ) // check for vacation mode
	{
         // Check if the current time is equal to the start time.
            if (NumMins(hour(), minute()) == (NumMins(InternalMemory.read(VacationStartHr), InternalMemory.read(VacationStartMin))))
            {
              if (second() == 0) 
              		{
			Feed = 1;   // Turn on feeder and feedmode
			ReefAngel.FeedingModeStart();
		        }   
            }
            else if ( InternalMemory.read(VacationEnable) == 2 ) // check for 2x feeder vacation mode
            {
            if (NumMins(hour(), minute()) == (NumMins(InternalMemory.read(VacationStart2ndHr), InternalMemory.read(VacationStart2ndMin))))
            {
              if (second() == 0) 
              		{
			Feed = 1;   // Turn on feeder and feedmode
			ReefAngel.FeedingModeStart();
		        }   
            }
            else
            {
              Feed = 0;
            }
        }
I 'm trying to avoid the delay function. As I seem to have issues with the watchdog timer resetting the controller when a delay is used. Also, I have this problem with my custom menu screens. Is there a function to turn off the WDT under certain contexts, like a custom menu screen where nothing is happening, but you need time to read it before going back to normal operation and WDT?

Thanks,
JOn
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Quick measures & watchdog timers

Post by rimai »

Code: Select all

if (now()%3600) set_average(0, hour());
This is wrong.
It is doing the opposite of what you want.
now()%3600 will result in false only when you are at the top of the hour and true for anything else.
now()%3600==0 is the same thing as second()==0 should and they both should work.
if you want to reset the WDT when doing a while() loop inside a custom menu, you need to ping the WDT so it knows you are still alive with the function wdt_reset()
Roberto.
Post Reply