Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

Timers

Modules

Functions


Detailed Description

There are four general-purpose programmable timer units in the processor. Three timers have an external pin that can be configured either as a pulse width modulator (PWM) or timer output, as an input to clock the timer, or as a mechanism for measuring pulse widths and periods of external events. These timers can be synchronized to an external clock input to the several other associated PF pins, to an external clock input to the PPI_CLK input pin, or to the internal SCLK. The timer units can be used in conjunction with the UART to measure the width of the pulses in the data stream to provide a software auto-baud detect function for the respective serial channels. The timers can generate interrupts to the processor core providing periodic events for synchronization, either to the system clock or to a count of external signals. In addition to the three general-purpose programmable timers, a fourth timer is also provided. This extra timer is clocked by the internal processor clock and is typically used as a system tick clock for generation of operating system periodic interrupts.

Function Documentation

unsigned long Get_TimerCounter int  timer  ) 
 

Return count of specified timer.

Parameters:
timer Timer identifier Identifier of available timers.
Returns:
Timer count, each count is 10ns length.
See also:
Set_TimerCounter
        Set_TimerCounter(TIMER_0);                                              // Set count on TIMER_0
        Set_TimerEnable(TIMER_0, true);                                 // Start count
        // With this code I want measure elapsed time of a process
        unsigned long st = Get_TimerCounter(TIMER_0);   // Start count
        // Process to be measured
        // ...
        unsigned long et = Get_TimerCounter(TIMER_0);   // End count
        // Now I will display elapsed time
        // First of all I will check if roll-over timer was happen (long time measure)
        if(st > et) et = 0xFFFFFFFF - st + et;
        else et = et - st;
        printf("Elapsed time: %.3f ms\n", (double) et / 100000.0);

void Set_CoreTimerEnable bool  ena  ) 
 

Enable/Disable generation of a periodic interrupt on core-timer.

Parameters:
ena Enable (true) / Disable (false) interrupt.
See also:
Set_CoreTimerInterruptService

void Set_CoreTimerInterruptService int  prescaler,
unsigned  countValue,
bool  autoReload,
void(*  pCallback)()
 

Enable coretimer to generate a periodic interrupt. The core timer is a programmable 32-bit interval timerwhich can generate periodic interrupts.
Unlike other peripherals, the core timer resides inside the Blackfin core and runs at the core clock (CCLK) rate.
Core timer features include:
-32-bit timer with8-bit prescaler -Operates at core clock (CCLK) rate -Dedicated high-priority interrupt channel -Single-shot or continuous operation.

Parameters:
prescaler 0= Prescaler is 1, 1= Prescale is 2, ...
countValue Value decremented every prescaler + 1 value
autoReload If true the generated interrupt is periodic
pCallback Pointer to a procedure executed every at every interrupt
See also:
Set_CoreTimerEnable
        unsigned universalCounter = 0;

        // CORE TIMER callback
        void backgroundProcess()
        {
                printf("Count = %6d\n", universalCounter++);
        }

        int main(void)
        {
                Set_PLL(16, 4);         // CORE: 25MHz * 16 = 400MHz, SCLK: 400MHz / 4 = 100MHz
                Set_Port();                     // Set the port according to project set
                Set_Uart0(115200);      // printf is redirected to UART0
                // Prescaler action 400MHz / 40 (39+1) = 10MHz (100ns)
                // Period: 5000000 * 100ns = 0.5s
                Set_CoreTimerInterruptService(39, 5000000, true, backgroundProcess);
                Set_CoreTimerEnable(true);
                while(1)                        // Main loop
                {
                }
                return 0;
        }

void Set_TimerCounter int  timer  ) 
 

Set count on specified timer.

Parameters:
timer Timer identifier Identifier of available timers.
See also:
Get_TimerCounter

void Set_TimerEnable int  timer,
bool  ena
 

Enable/Disable generation of a periodic interrupt on specified timer.

Parameters:
timer Timer identifier Identifier of available timers.
ena Enable (true) / Disable (false) interrupt.
See also:
Set_TimerInterruptService

void Set_TimerInterruptService int  timer,
void(*  pCallback)(),
unsigned  countValue
 

Enable specified timer to generate a periodic interrupt.

Parameters:
timer Timer identifier Identifier of available timers.
pCallback Procedure pointer to interrupt call back.
countValue Interrupt period in us
See also:
Set_TimerEnable
        int counter = 0;

        void callBack()
        {
                printf("Counter: %6d\n", counter++);
        }

        int main(void)
        {
                Set_PLL(16, 4); // CORE: 25MHz * 16 = 400MHz, SCLK: 400MHz / 4 = 100MHz
                Set_Port();
                Set_Uart0(115200);
        
                Set_TimerInterruptService(TIMER_0, &callBack, 500000);  // 0.5s
                Set_TimerEnable(TIMER_0, true);
                while(1)
                {
                }
        return 0;
        }

void Set_TimerSquareWave int  timer,
unsigned  width,
unsigned  period
 

Set_WatchDogTimer unsigned  count  ) 
 

Set wathcdog activity. This procedure set a 32-bit timer that can be used to implement a software watchdog function.
A software watchdog can improve system reliability by generating an event to the processor core if the watchdog expires before being updated by software. Typically, the watchdog timer is used to supervise stability of the system software.
When used in this way, software reloads the watchdog timer in a regular manner so that the downward counting timer never expires (neverbecomes 0).
An expiring timer then indicates that system software might be out of control.
At this point a special error handler may recover the system.
For safety, however, it is often better to reset and reboot the system directly by hardware control.

Parameters:
count Watchdog Count (10ns step).
See also:
Set_WatchDogTimerEnable
        unsigned universalCounter = 0;

        // CORE TIMER callback
        void backgroundProcess()
        {
                printf("Count = %6d\n", universalCounter++);
        }

        int main(void)
 {
                // Dear user this test work only in FLASH !!!
                // Why? Loaded code in RAM is always reset
                Set_PLL(16, 4);         // CORE: 25MHz * 16 = 400MHz, SCLK: 400MHz / 4 = 100MHz
                Set_Port();                     // Set the port according to project set
                Set_Uart0(115200);      // printf is redirected to UART0
                // Prescaler action 400MHz / 40 (39+1) = 10MHz (100ns)
                // Period: 5000000 * 100ns = 0.5s
                Set_CoreTimerInterruptService(39, 5000000, true, backgroundProcess);
                Set_CoreTimerEnable(true);
                // 10ns * 100 = 1us * 1000 = 1ms * 5000 = 5s
                Set_WatchDogTimer(100 * 1000 * 5000);
                Set_WatchDogTimerEnable(true);  // After 5s count restart from 0!
                printf("WatchDog test started\n");
                while(1)                        // Main loop
                {
                }
                return 0;
        }

void Set_WatchDogTimerEnable bool  enable  ) 
 

Enable/Disable watchdog activity.

Parameters:
enable Enable (true) / Disable (false) watchdog.
See also:
Set_WatchDogTimer


Generated on Tue Apr 7 20:07:44 2015 for BF592A Library by doxygen 1.3.1