PicGIM 0.5 documentation    
Copyright (C) 2002, 2013 - [AsYntote-SkyMatrix] gKript.org    
Generated on Sun Apr 26 2015 11:03:34 with DoxyGen 1.8.8    
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Timer
timer.png

The TIMER module provides a set of functions to easily configure and manage timers in different units of time (seconds or milliseconds).
The module can be configured in order to obtain a continuous timer or a timer that spins just once.

In the public configuration file pgim_timer_setup_public.h are specified clearly the possible values for the various parameters.
For software reference please read the documentation in pgim_timer.h

Attention
The device managed by this module has interrupt signals.
If you want to use please read carefully the chapter Events ( Interrupts ) .




Module configuration


In order to use this module, it must be enabled and configured in:

  • pgim_module_setup_public.h : the main management file for the modules that must be included in the project.
    In this file there are these configurations :

         Module enabling



  • pgim_timer_setup_public.h : where are collected all the features of the module.
    Here are specified the possible values for the various parameters and when they have to be set depending on the chosen mode of operation of the module.
    In this file there are these configurations :

         Channels enabling
         The delay Trim



        
Attention
For software reference, please read the documentation about pgim_timer.h .
This is not a file defined as public and therefore it would not be edited.
We suggest that you edit this file only if necessary and only if you know what you are doing.




Module enabling


#define PGIM_TIMER PG_ENABLE

This define enables or disables the module.
It must be:

  • PG_ENABLE : Timer module enabled.
  • PG_DISABLE : Timer module disabled.

References

Channels enabling


#define PGIM_TIMER_0 PG_ENABLE_LOOP
#define PGIM_TIMER_1 PG_DISABLE

These defines enable or disable independently pwm channels.
They must be:

  • PG_DISABLE : Timer is disabled. Only set the necessary parameters.
  • PG_ENABLE_1_SHOT : When the timer starts, runs a loop and then stops.
  • PG_ENABLE_LOOP : When the timer starts, it continues to run until it is stopped.

References

The delay Trim


#define PG_TIMER_0_DELAY_TRIM 320
#define PG_TIMER_1_DELAY_TRIM 299

These definitions are the result of an empirical test on the execution time of an interruption on its timer.
The time is expressed in uSec and refers to the delta between the first instruction in the function pg_event_occurred() callback to the first instruction in the related Timer.

References

Functions


After it has been enabled and configured the module you can refer to this set of functions to use it.

Attention
This module can use the Error Handling Module : Error manager
In the TEST section of each function is specified which values ​​are set and in which cases.
Please refer to the specific documentation of the file header: pgim_timer.h


Private functions

Note
With "private" we mean a function that should not be used by the user in its code.
In this documentation the private functions are marked as Deprecate.
PicGIM internally uses these functions to properly manage the module.
Of course you are always free to use them if you think they are useful.
  • pg_timer_init() : This is the initialization function of the Timer handler module.



Public functions

  • pg_timer_set_period() : Allows to configure, through period, the timer selected by timer_id parameter and calculates the limit values.
  • pg_timer_set_freq() : Allows to configure, through frequency, the timer selected by timer_id parameter and calculates the limit values.
  • pg_timer_start() : Allows to start the timer selected by timer_id parameter.
  • pg_timer_stop() : Allows to stop the timer selected by timer_id parameter.
  • pg_timer_reg_current_value() : Converts the value of the timer contained in the two 8-bit registers (TMRxH and TMRxL) in a 16-bit value.



A code example


Here is a simple example of how to use the module in the user code.

Warning
In order to compile this example, the module must be enabled and properly configured.
...
pg_timer_set_period( PG_TIMER_0 , 1 , PG_SEC );
pg_timer_set_period( PG_TIMER_1 , 50 , PG_MSEC );
pg_timer_start( PG_TIMER_0 );
pg_timer_start( PG_TIMER_1 );
...



Using this module with interrupts

If the interrupt handling is enable is possible, through the interrupt signal PG_EVENT_SET_TMR0 or PG_EVENT_SET_TMR1, have an interrupt at every end of counting.
If using the Automatic Interrupts Handler pg_event_auto_handler() will call the associated callback: pg_interrupts_event_tmr0() or pg_interrupts_event_tmr1()
So once entered the code inside the callback it will be executed at every end of counting.
References : Interrups configuration :Module configuration
Internal interrupts configuration : Internal Interrupts
Callback configuration : How to use the interrupts callback routines

Warning
To use the User Interrupt Handler is necessary to read carefully the entire documentation related : pg_event_user_handler()