Tutorial beginner 3:


Set a Timer!




Content of the tutorial:


- What is a Timer.

- How to configure a Timer.

- Let's start with the simulator.

- Build the hardware.




Introduction


Dear User, In this tutorial we will learn how to use Timers.

As learned in the previous tutorial, you can find the Project I'm going to describe in the dropdown List of Examples in the Devise Home header area.

It is a very simple Project. However it can be one first really useful application.

Top



What is a Timer


In the previous tutorial we have seen how to connect together four elements:


- controller: the Arduino Uno,

- physical devices: the button and the led,

- service: the cross connection between the button and the led.


A service is a functionality we want the controller to apply to physical devices, or to other services. In the previous example the cross connect service is the funcnionality that gets the status of the button (pushed or not) and set this status on the let (switched on or off).

Well, also a Timer is a service.

In other words a Timer is an elemente that gets an event from an element (i.e. from a button that is pushed) and, after a defined period of time, has a defined behavior on another element (i.e. a led)

The following picture shows how a Timer can be used in our Project:



In this picture we can see that the cross connection element takes the status of the button, as it was in the previous example, and set it to the Timer. In this way any change of the button state acts as trigger to the Timer. The output of the Timer will set the led status (on or off) according to the configured behavior of the timer itself.

Actually the overall behavior of a Timer can be splitted in three phases and for each phase we can define a different behavior:


- start phase,

- running phase,

- stop phase.


In the example only the running phase is configured, so there is no action during the start and the stop phases. However in the next chapter of this tutorial we will see in details how to configure all these three phases.

If you follow the guidelines shown in the previous tutorial, you should now be able to load the project on arduino and test it. As result you should see that the led will light on for a second every time the buton is pushed, and then light off again.

Top



How to configure a Timer


In the following picture we can see the screenshot representing the properties of a Timer. The behavior of the Timer can be configured through these properties.



The first property is the name of the timer. This property, and also the names of all the other elements, is not functional, that means that we can modify it as we like without modify the behavior of the Timer. However I do not recommend to do it because the name is automatically given to the element by the tool. In case you prefer to modify it, be careful that:


- there are no spaces or strange characters in the name,

- the same name is not repeated for two different elements in the whole Project.


Then we can see the properties that configure the behavior of the three phases. Let's analyse them.


Top

1. Start phase.


The start phase is configured through the 'mode on' and 'time on' properties.

mode on defines the start phase in this way:

- bypass: nothing to do during the start phase, as in our example.

- fade: after the trigger has been received (i.e. the button has been pushed), the output will be a raising ramp, so the Led will progressively light on. (in this case the led should be connected to a PWM pin. For this reason it does't work with the embedded led on Arduino Uno. We will see this case in the next tutorial).

- delay: the Led switch on is delayed respect the time the button is pushed.

time on defines the time period of the start phase, expressed in milliseconds, seconds or minutes accordingly to the 'unit' property.



Top

2. Running phase.


In this phase the behavior of the Timer is configured through the 'mode' and 'time' properties.

mode defines the running phase in this way:

- bypass: nothing to do during the running phase.

- tempor: the Timer will lead the output off either after a defined time period or when the trigger occurs again, if not expired yet.

- pulse: the Timer will lead the output off after a defined time period. If during the running phase the trigger occurs again, the time counter restart the counting from the beginning and the running phase is stretched.

- progressive: the Timer will lead the output off after a number of defined time periods equal to the number of given triggers. For instance, if the time period is one minute and the button is pushed three times, the output will go down after three minutes.

- square: the Timer will lead the output continously on and off with a given period.

time defines the time period of the running phase, expressed in milliseconds, seconds or minutes accordingly to the 'unit' property.



Top

3. Stop phase.


The stop phase is configured through the 'mode off' and 'time off' properties.

The meaning of these properties is very similar to the start phase ones.

mode off defines the stop phase in this way:

- bypass: nothing to do during the stop phase, as in our example.

- fade: after the running phase has been completed, the output will be a falling ramp, so the Led will progressively light down. (also in this case the led should be connected to a PWM pin).

- delay: the Led switch off is delayed respect the time the running phase is completed.

time off defines the time period of the stop phase, expressed in milliseconds, seconds or minutes accordingly to the 'unit' property.




Top

Let's start with the simulator


A very powerful feature of Devise Home tool is the provided possibility to see how our project works before to really build it in hardware. At this purpose a graphic project simulator can be easily started by clicking over the Simulator button .

After clicked on, a new window will open. In this window you can see a whiteboard very similar to the project one, but with different behavior. In fact it is not editable at all.

Now try to click over the components of the project. you can see that when you click over the push button, something happens. Yes, the led switches on for a few time and then switches back again. And that is exactly what should happen in the real system. In other words you can see the behavior of your project inside the screen of your laptop. Very cool, isn't it?




Top

Build the hardware


the hardware implementation of this example is the same of the previous tutorial, so I will explain nothing more about it. If you want to try the 'Analog version of this example, using the fade in and the fade out of the Timer, you can go ahead and read the next tutorial.


<< - Index - >>