Telecnatron

radio, electronics, computing, telecnology.

rss icon

Support This Site.

Please consider helping to support this site by making a contribution.

avr_lib  2.0
A C library for AVR microcontrollers
sysclk.h File Reference

Timer that counts ticks and 'seconds'. Default setting is to use T2: FCPU 16MHz, prescaller 64, terminal count 250, for timer period of 1ms. More...

#include "./timer.h"
#include "config.h"
#include <stdint.h>

Go to the source code of this file.

Macros

#define SYSCLK_INIT()   T2_OC2A_NONPWM_NORMAL(); T2_WGM_CTC()
 Change these to use a different timer: normal mode, output pin disabled, set CTC mode - clear timer on compare match. More...
 
#define SYSCLK_INT_ENABLE()   T2_CMA_E();
 
#define SYSCLK_INT_DISABLE()   T2_CMA_D();
 
#define SYSCLK_START()   T2_START();
 
#define SYSCLK_STOP()   T2_STOP();
 
#define SYSCLK_ISR_NAME   TIMER2_COMPA_vect
 
#define SYSCLK_DEFS
 
#define SYSCLK_INIT_PRE()   T2_CS_PRE_64()
 With FCPU = 16MHz, prescaler 64 and terminal count 250 gives tick (compare match interrupt) period of 1ms. More...
 
#define SYSCLK_SET_TC()   T2_OCR2A(250)
 
#define SYSCLK_TICK_FREQ   1000
 This many ticks per 'second'. More...
 

Functions

void sysclk_init ()
 Initialise and start the clock. More...
 
void sysclk_stop ()
 Stop the clock. Disable interrupt. More...
 
void sysclk_start ()
 Start the clock. Enable interrupt. More...
 
void sysclk_reset ()
 Resets tick and seconds counter to 0, clears tick flags. More...
 
uint16_t sysclk_get_ticks ()
 Return the current tick count. More...
 
uint8_t sysclk_has_ticked ()
 Return true if a tick has occured since prior call, false otherwise. More...
 
uint16_t sysclk_get_seconds ()
 Return current seconds count. More...
 
uint8_t sysclk_have_seconds_ticked ()
 Return true if a seconds-tick has occured since prior call, false otherwise. More...
 
void sysclk_reset_seconds ()
 Reset the seconds count to 0. More...
 

Detailed Description

Timer that counts ticks and 'seconds'. Default setting is to use T2: FCPU 16MHz, prescaller 64, terminal count 250, for timer period of 1ms.

Author
steves
Date
2016/05/16 06:32:46

Uses TIMER2_COMPA_vect, ISR is defined in sysclk.c

To use different timing paramters, change the SYSCLK_INIT_PRE(), SYSCLK_SET_TC() macros, and set SYSCLK_TICK_FREQ define accordingly.

To use a different timer, change all the SYSCLK_XXX macros/defines accordingly, eg replace T2_ with T0_, TIMER2 with TIMER0.

Definition in file sysclk.h.

Macro Definition Documentation

◆ SYSCLK_DEFS

#define SYSCLK_DEFS

Definition at line 41 of file sysclk.h.

◆ SYSCLK_INIT

#define SYSCLK_INIT ( )    T2_OC2A_NONPWM_NORMAL(); T2_WGM_CTC()

Change these to use a different timer: normal mode, output pin disabled, set CTC mode - clear timer on compare match.

Definition at line 33 of file sysclk.h.

◆ SYSCLK_INIT_PRE

#define SYSCLK_INIT_PRE ( )    T2_CS_PRE_64()

With FCPU = 16MHz, prescaler 64 and terminal count 250 gives tick (compare match interrupt) period of 1ms.

eg tick_period = 64/16M*250 = 0.001

Definition at line 47 of file sysclk.h.

◆ SYSCLK_INT_DISABLE

#define SYSCLK_INT_DISABLE ( )    T2_CMA_D();

Definition at line 35 of file sysclk.h.

◆ SYSCLK_INT_ENABLE

#define SYSCLK_INT_ENABLE ( )    T2_CMA_E();

Definition at line 34 of file sysclk.h.

◆ SYSCLK_ISR_NAME

#define SYSCLK_ISR_NAME   TIMER2_COMPA_vect

Definition at line 38 of file sysclk.h.

◆ SYSCLK_SET_TC

#define SYSCLK_SET_TC ( )    T2_OCR2A(250)

Definition at line 48 of file sysclk.h.

◆ SYSCLK_START

#define SYSCLK_START ( )    T2_START();

Definition at line 36 of file sysclk.h.

◆ SYSCLK_STOP

#define SYSCLK_STOP ( )    T2_STOP();

Definition at line 37 of file sysclk.h.

◆ SYSCLK_TICK_FREQ

#define SYSCLK_TICK_FREQ   1000

This many ticks per 'second'.

Definition at line 50 of file sysclk.h.

Function Documentation

◆ sysclk_get_seconds()

uint16_t sysclk_get_seconds ( )
inline

Return current seconds count.

Definition at line 77 of file sysclk.c.

◆ sysclk_get_ticks()

uint16_t sysclk_get_ticks ( )
inline

Return the current tick count.

Definition at line 54 of file sysclk.c.

◆ sysclk_has_ticked()

uint8_t sysclk_has_ticked ( )
inline

Return true if a tick has occured since prior call, false otherwise.

Definition at line 59 of file sysclk.c.

◆ sysclk_have_seconds_ticked()

uint8_t sysclk_have_seconds_ticked ( )
inline

Return true if a seconds-tick has occured since prior call, false otherwise.

Definition at line 68 of file sysclk.c.

◆ sysclk_init()

void sysclk_init ( )

Initialise and start the clock.

Definition at line 22 of file sysclk.c.

◆ sysclk_reset()

void sysclk_reset ( )

Resets tick and seconds counter to 0, clears tick flags.

Definition at line 46 of file sysclk.c.

◆ sysclk_reset_seconds()

void sysclk_reset_seconds ( )
inline

Reset the seconds count to 0.

Definition at line 82 of file sysclk.c.

◆ sysclk_start()

void sysclk_start ( )
inline

Start the clock. Enable interrupt.

Definition at line 38 of file sysclk.c.

◆ sysclk_stop()

void sysclk_stop ( )
inline

Stop the clock. Disable interrupt.

Definition at line 30 of file sysclk.c.

Copyright 2012 - 2023 Telecnatron CSS | Login | Privacy | Sitemap Web software by Stephen Stebbing.