Functions | Variables

# time.h File Reference

Contains definitions of the number of timers used and their names. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions
__interrupt void | TICK_ISR (void)
| Interrupt service routine for timer 0 overflow.
unsigned char | Time_Left (unsigned char timer)
| Checks if a specified timer has expired.
void | Time_Set (unsigned char timer, unsigned int min, unsigned char sec, unsigned char ms)
| Sets the specified timer.
void | Time_Stop (void)
| Stops timers.
void | Time_Start (void)
| Starts timers.
void | Time_Init (void)
| Initializes timers.
## Variables
unsigned long | timeval []
| Contains the values for each timer.

## Detailed Description

Contains definitions of the number of timers used and their names.

- Compiler: IAR EWAVR and GNU GCC for AVR
- Supported devices: ATmega32U4

Author:
  Atmel Corporation: http://www.atmel.com
  Support and FAQ: http://support.atmel.no/

Definition in file time.h.

## Function Documentation

__interrupt void TICK_ISR | ( | void | ) |

Interrupt service routine for timer 0 overflow.

Timer 0 runs at 125 kHz and compare match will occur every millisecond (125 / 125 kHz = 1.0 ms), which will result in a call to this function. When called, this function will decrement the time left for each timer, unless they are already at zero.

Definition at line 71 of file time.c.

References timeval.

    {
       unsigned char i;

       // 1 ms has passed, decrement all non-zero timers.
       for (i = 0; i < TIMERS; i++) {
          if(timeval[i] > 0) {
             timeval[i]--;
          }
       }
    }

unsigned char Time_Left | ( | unsigned char | timer ) |

Checks if a specified timer has expired.

Parameters:

  timer | Specifies timer

Return values:

  TRUE | Timer still going.
  FALSE | Timer has expired.

Definition at line 92 of file time.c.

References FALSE, timeval, and TRUE.

Referenced by PWM_Start().

    {
       if(timeval[timer] > 0) {
          return(TRUE);
       } else {
          return(FALSE);
       }
    }

Here is the caller graph for this function:

void Time_Set | ( | unsigned char | timer,
|  | unsigned int | min,
|  | unsigned char | sec,
|  | unsigned char | ms
| ) |  |

Sets the specified timer.

Parameters:

  timer | Specifies timer
  min | Minutes for timer to count down
  sec | Seconds for timer to count down
  ms | Milliseconds for timer to count down

Definition at line 109 of file time.c.

References timeval.

Referenced by PWM_Start().

    {
       timeval[timer] = 60000 * (unsigned long)min;
       timeval[timer] += 1000 * (unsigned long)sec;
       timeval[timer] += 1 * (unsigned long)ms;
    }

Here is the caller graph for this function:

void Time_Stop | ( | void | ) |

Stops timers.

Sets timer0's clock source to none.

Definition at line 122 of file time.c.

    {
       TCCR0B = 0;
    }

void Time_Start | ( | void | ) |

Starts timers.

Sets timer0's clock source to system clock divided by 64.

Definition at line 132 of file time.c.

Referenced by PWM_Start().

    {
       TCNT0 = 0x00;//cgs added
       TCCR0B = (0<<CS02)|(1<<CS01)|(1<<CS00);   // CLKT0 = CLK/64 = 125 kHz.
    }

Here is the caller graph for this function:

void Time_Init | ( | void | ) |

Initializes timers.

Resets all the timer values to 0, then sets up timer 0 for a compare match every millisecond.

Definition at line 144 of file time.c.

References timeval.

    {
       unsigned char i;

       for (i = 0; i<<TIMERS; i++)   {
          timeval[i] = 0;
       }

       OCR0A = 125;  // Will give a compare match every ms.

       OCR0B = 0;  // Doesn't matter, will run in normal mode.

       TCCR0A = (1<<WGM00);  // 8-bit CTC mode.

       TCCR0B = (0<<CS02)|(1<<CS01)|(1<<CS00);   // CLKT0 = CLK/64 = 125 kHz.

       TIMSK0 |= (1<<OCIE0A);  // Timer 0, Compare match A interrupt enabled.

       // Enable interrupts, just in case they weren't already.
    #ifdef __GNUC__
       Enable_interrupt();
    #else
       __enable_interrupt();
    #endif
    }

## Variable Documentation

unsigned long timeval[]

Contains the values for each timer.

Definition at line 51 of file time.c.

Referenced by TICK_ISR(), Time_Init(), Time_Left(), and Time_Set().