ATtiny85 Template Code
Code snippets for the ATtiny85
|
#include <avr/io.h>
#include <avr/interrupt.h>
#include "../hardware.h"
#include "systicks.h"
#include "iohelp.h"
Go to the source code of this file.
Macros | |
#define | SPWM_MAX 4 |
#define | TICKLETS 64 |
#define | SYSTICK_ENABLED |
Functions | |
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) | |
#define SPWM_MAX 4 |
Definition at line 15 of file systicks.c.
#define SYSTICK_ENABLED |
Definition at line 22 of file systicks.c.
#define TICKLETS 64 |
Definition at line 18 of file systicks.c.
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.
void spwmOut | ( | SPWM | pwm, |
uint8_t | value | ||
) |
Set the value of a software PWM pin
Set the output for a software PWM pin.
pwm | the software PWM output to change |
value | the 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.
pwm | the software PWM output to query |
Definition at line 153 of file systicks.c.
uint16_t ticks | ( | ) |
Get the current tick count
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).
reference | the reference tick count to calculate against. |
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.