Inside the Nutchip there is a very accurate programmable timer. You can set the time in a huge range, from one thousandth fo a second to one thousand hours (more than 40 days!)
When writing a truth table, we use a special kind of condition to set te timer: a timeout condition.The timeout row in a truth table sets the maximum time allowed for a praticular state. Time starts when the Nutchip enters the state. Timer is handled like a sort of input that triggers when the time is out, causing the Nutchip to change state.
In this example, the timeout is set to 1 min. Time is counted from the instant the Nutchip first enters state st01.
When the specified 1 min. interval expires, the Nutchip jumps to state st00.
Each state can have only one timeout, but if your application requires different times you can add more states to handle them: each state can have a different timeout (or no timeout at all). To add a timeout Nutstation provides a dedicated "Add timeout" button, which creates a timeout row for the state currently selected on the editor. Note that it normal for a state to have also input and remote control conditions in addition to a timeout.
This button adds a timeout line to the state currently selected on the truth table. Like all conditions, a timeout condition requires you to specify a state to jump to when the timeout expires. This is the state the Nutchip will take if no other condition on the inputs and/or remote control becoems precedently true. Timeouts are not evalued if another condition becomes true for the current state.
You can add only one timeout per state, therefore the button is disabled after you add one to a state. You can give a timeout to any state, including st00, and you can use different times for them. If you add a timeout to a blank table or to an empty row, a new state will be created together with the timeout.
You can change the timeout period clicking on it. This window will appear, allowing you to set the desired time. You can specify any time included in the following ranges:
- from 1 a 1000 mS (milliseconds, one thousandth of a second each)
- from 1 a 1000 sec (seconds)
- from 1 a 1000 min (minutes) note as 1000 minutes = 16,6 hours
- from 1 a 1000 hours: note as 1000 hurs = 41,6 days.
Normally the timer is reloaded with the duration specified in a timeout condition when the Nutchip enters a new state. If we add a timeout to the state st02, the timer is reloaded each and every time we switch from any state to state st02. "Reloading" here means that the timeout delay is restarted from the duration specified in the truth table. This is the default behavior ("Remaining time" option disabled).
If otherwise you check the remaining time option, the timer is not reloaded, and the time borrowed from the previos state is used instead. This option is useful if a timeout extends to include more than one state, a characteristic useful for applications like cyclic timers with safety inputs.
Note: the remaining time at power up is always zero.
Example: A cyclic timer must switch a pump on for 10 minutes eachand every hour. The 10 min time can be shorter if there is enough liquid, in which case a floater switch connected to an input will signal the controller to skip to the next cycle.
This application requires three states:
- st00: this state switches the pump on
condition: if the input detects a floating switch closure, skip to state st01
timeout: when a 10 min. delay expires, jump to state st02
- st01: this state waits the remaining time (if any) with the pump off.
timeout: when the remaining time expires, jump to state st02
(note: we use the remaining time to consume the residute of the 10 min set in the previous state)
- st02: this state waits 50 min (to account for a 1 hour = 60 min. total cycle time) with the pump off
timeout: when the 50 min. delay expires, jump to state st00
In this example the 10 minutes delay extends over st00 and st01. If the floater switch close before the 10 min. delay elapses, the state st01 will wait the remaining time (with the pump off) to get 10 min. as well. Whatever the current liquid level, the whole sequence st00, st01, st02 will take alway 10+50=60min, as required.
Some applications need to keep the time reloaded as long as an input pin remains set. This can be easily done on a Nutchip. As the time is reloaded on state jumps, all you need to do is to ensure that the state is continuosly re-entered. A little trick will help: it is perfectly legal for a condition in a given state - for example st03 - to jump to the same state when true. This is effectively a state jump - causing a timer reload - even if the new state is the same as the old state.
Example - Suppose you want the timer reloaded as long as the input 1 stays high. Let's call this state st00. As long as the Nutchip remains in such a state, the output 1 is high. As soon as the input 1 goes low, the timer starts ticking, and at the time it expires the Nutschip jumps to statoe st01, whreas the output goes low.
The state table requires two states:
Timer precision depends on the clock source supplied to the Nutchip. Using a ceramic resonator you can expect a precision between 0.5% and 1%, which can double if you take into account the frequency changes due to temperature variations.
If you are designing a cyclic timer (e.g. a lawn watering timer) the errors accumulate day bay day, and may find yourself seeking for a surprisingly precise clock source. The usual clock source for optimal precision is a quartz crystal clock. This kind of clock results in a precision usually better than 20 ppm (parts per million, 0.0001 %). As astonishing as it can sounds, as there are some 2.5 millions seconds per month, this 20 ppm precision turns out to yeld an error of 2.5 x 20 = 50 seconds/month. If this sounds unacceptable to you, you must calibrate your clock source against a known reference, adding a variable capacitor (a few pF will do) to the circuit.
It is usually impractical to calibrate a clock source this way. Watch makers use to compensate quartz crystal batches finding the exact capacitance required to get a very accurate time reference, using very expensive techniques. Sometimes they are facilitated by the fact that wristwatches run at an almost constant temperature - the human body temperature! now you know why your expensive computer cannot compete with a cheap wristwatch when keeping the time.
Jitter: A Nutchip switches its outputs with a jitter typically better than 2mS (worst case estimate: 6mS). States with a lower number exibit the best jitter.
The Nutchip implements a jitter compensation algorithm which subracts jitter delays on the next state change: therefore jitter will not accumulate in cyclic timers. as a rule of thumb, if your application involves timeouts greather than 10 mS you should not worry about jitter.