ATtiny85 Template Code
Code snippets for the ATtiny85
 All Files Functions Variables Typedefs Enumerations Enumerator Macros
systicks.c File Reference
#include <avr/io.h>
#include <avr/interrupt.h>
#include "../hardware.h"
#include "systicks.h"
#include "iohelp.h"
Include dependency graph for systicks.c:

Go to the source code of this file.


#define SPWM_MAX   4
#define TICKLETS   64


void ticksInit ()
uint16_t ticks ()
uint16_t ticksElapsed (uint16_t reference)
void spwmInit ()
void spwmOut (SPWM pwm, uint8_t value)
uint8_t spwmValue (SPWM pwm)
 ISR (TIMER1_OVF_vect)

Macro Definition Documentation

#define SPWM_MAX   4

Definition at line 15 of file systicks.c.


Definition at line 22 of file systicks.c.

#define TICKLETS   64

Definition at line 18 of file systicks.c.

Function Documentation

ISR ( TIMER1_OVF_vect  )

Interrupt handler

Definition at line 170 of file systicks.c.

void spwmInit ( )

Initialise the software PWM system

Sets up software PWM support. Using the software PWM implementation also enables the system ticks module (they share the same interrupt).

Definition at line 107 of file systicks.c.

Here is the call graph for this function:

void spwmOut ( SPWM  pwm,
uint8_t  value 

Set the value of a software PWM pin

Set the output for a software PWM pin.

pwmthe software PWM output to change
valuethe value for the duty cycle ranging from 0 (fully off) to 255 (fully on).

Definition at line 140 of file systicks.c.

uint8_t spwmValue ( SPWM  pwm)

Get the current value of a software PWM pin

Returns the current value of a software PWM pin.

pwmthe software PWM output to query
the current value of the software PWM pin

Definition at line 153 of file systicks.c.

uint16_t ticks ( )

Get the current tick count

the current tick count. The count wraps around once it reaches 65535.

Definition at line 70 of file systicks.c.

uint16_t ticksElapsed ( uint16_t  reference)

Calculate the ticks elapsed since the given sample.

This function calculates the number of ticks that have elapsed since the reference sample was taken. The function takes into account the wrap around of the counter (but it cannot detect multiple wrap arounds).

referencethe reference tick count to calculate against.
the number of ticks elapsed since the reference count.

Definition at line 84 of file systicks.c.

void ticksInit ( )

Initialise the 'ticks' subsystem.

This function sets up the required interrupts and initialises the tick counter. There are approximately TICKS_PER_SECOND ticks every second that elapses (depending on interrupt activity and clock accuracy) and they are tracked by a 16 bit counter. A program can use the difference between samples of the counter to measure longer periods of time.

The ticks system uses TIMER1 to provide the interrupt used to update the time count (this interrupt is shared with the software PWM implementation as well).

Definition at line 54 of file systicks.c.

Here is the caller graph for this function: