Speeduino
Loading...
Searching...
No Matches
timers.h
Go to the documentation of this file.
1
2
3/*
4NOTE - This file and it's associated functions need a CLEARER NAME
5
6//Purpose
7We're implementing a lower frequency interrupt loop to perform calculations that are needed less often, some of which depend on time having passed (delta/time) to be meaningful.
8
9
10//Technical
11Timer2 is only 8bit so we are setting the prescaler to 128 to get the most out of it. This means that the counter increments every 0.008ms and the overflow at 256 will be after 2.048ms
12Max Period = (Prescale)*(1/Frequency)*(2^8)
13(See arduinomega.blogspot.com.au/2011/05/timer2-and-overflow-interrupt-lets-get.html)
14
15We're after a 1ms interval so we'll need 131 intervals to reach this ( 1ms / 0.008ms per tick = 125).
16Hence we will preload the timer with 131 cycles to leave 125 until overflow (1ms).
17
18*/
19#ifndef TIMERS_H
20#define TIMERS_H
21
22#include <stdint.h>
23
24constexpr uint8_t BIT_TIMER_1HZ = 0;
25constexpr uint8_t BIT_TIMER_4HZ = 1;
26constexpr uint8_t BIT_TIMER_10HZ = 2;
27constexpr uint8_t BIT_TIMER_15HZ = 3;
28constexpr uint8_t BIT_TIMER_30HZ = 4;
29constexpr uint8_t BIT_TIMER_50HZ = 5;
31constexpr uint8_t BIT_TIMER_1KHZ = 7;
32
33void initTacho(uint8_t tachoPin);
34void tachoPulseHigh(void);
35void tachoPulseLow(void);
36
37enum TachoOutputStatus {TACHO_INACTIVE, READY, ACTIVE}; //The 3 statuses that the tacho output pulse can have. NOTE: Cannot just use 'INACTIVE' as this is already defined within the Teensy Libs
38
40extern volatile uint16_t tachoSweepIncr;
41
42#define TACHO_SWEEP_TIME_MS 1500
43#define TACHO_SWEEP_RAMP_MS (TACHO_SWEEP_TIME_MS * 2 / 3)
44#define MS_PER_SEC 1000
45
46void oneMSInterval(void);
47void initialiseTimers(void);
48
49#endif // TIMERS_H
static TIntegral readSerialIntegralTimeout(void)
Reads an integral type, timing out if necessary.
Definition comms.cpp:175
void initTacho(uint8_t tachoPin)
Definition timers.cpp:56
constexpr uint8_t BIT_TIMER_200HZ
Definition timers.h:30
volatile TachoOutputStatus tachoOutputFlag
Definition timers.cpp:36
constexpr uint8_t BIT_TIMER_1HZ
Definition timers.h:24
volatile uint16_t tachoSweepIncr
Definition timers.cpp:37
void tachoPulseLow(void)
Definition timers.cpp:67
void tachoPulseHigh(void)
Definition timers.cpp:62
constexpr uint8_t BIT_TIMER_1KHZ
Definition timers.h:31
constexpr uint8_t BIT_TIMER_10HZ
Definition timers.h:26
constexpr uint8_t BIT_TIMER_15HZ
Definition timers.h:27
void initialiseTimers(void)
Definition timers.cpp:42
TachoOutputStatus
Definition timers.h:37
@ ACTIVE
Definition timers.h:37
@ READY
Definition timers.h:37
@ TACHO_INACTIVE
Definition timers.h:37
constexpr uint8_t BIT_TIMER_50HZ
Definition timers.h:29
constexpr uint8_t BIT_TIMER_4HZ
Definition timers.h:25
constexpr uint8_t BIT_TIMER_30HZ
Definition timers.h:28
void oneMSInterval(void)
Definition timers.cpp:72