Skip to content

Commit

Permalink
improve millis TCA ISR
Browse files Browse the repository at this point in the history
  • Loading branch information
MX682X committed May 30, 2023
1 parent 4fbe30a commit 70032b0
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 150 deletions.
16 changes: 8 additions & 8 deletions megaavr/cores/megatinycore/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ uint8_t PWMoutputTopin(uint8_t timer, uint8_t channel);
* 3/19/23: These are supposed to be macros, not inline functions
* Users have reported problems resulting from their being functions, even inline ones
*/
#define clockCyclesPerMicrosecond() ((uint16_t)(F_CPU / 1000000L))
#define clockCyclesToMicroseconds(a) ((uint32_t)((a) / clockCyclesPerMicrosecond()))
#define microsecondsToClockCycles(a) ((uint32_t)((a) * clockCyclesPerMicrosecond()))
#define clockCyclesPerMicrosecond() ((F_CPU / 1000000UL))
#define clockCyclesToMicroseconds(__a__) (__a__ / clockCyclesPerMicrosecond())
#define microsecondsToClockCycles(__a__) (__a__ * clockCyclesPerMicrosecond())

// Currently DxCore has no cases where the millis timer isn't derived from system clock, but that will change
/* This becomes important when we support other timers for timekeeping. The Type D timer can be faster, requiring:
Expand Down Expand Up @@ -441,15 +441,15 @@ uint32_t microsecondsToMillisClockCycles(uint32_t microseconds);
*/
#ifdef MILLIS_USE_TIMERD0
#if (F_CPU == 20000000UL || F_CPU == 10000000UL ||F_CPU == 5000000UL)
#define millisClockCyclesPerMicrosecond() ((uint16_t) (20)) // this always runs off the 20MHz oscillator
#define millisClockCyclesPerMicrosecond() (20) // this always runs off the 20MHz oscillator
#else
#define millisClockCyclesPerMicrosecond() ((uint16_t) (16))
#define millisClockCyclesPerMicrosecond() (16)
#endif
#else
#define millisClockCyclesPerMicrosecond() ((uint16_t) ((F_CPU) / 1000000L))
#define millisClockCyclesPerMicrosecond() (F_CPU / 1000000UL)
#endif
#define millisClockCyclesToMicroseconds(a) ((uint32_t)((a) / millisClockCyclesPerMicrosecond()))
#define microsecondsToMillisClockCycles(a) ((uint32_t)((a) * millisClockCyclesPerMicrosecond()))
#define millisClockCyclesToMicroseconds(__a__) (__a__ / millisClockCyclesPerMicrosecond())
#define microsecondsToMillisClockCycles(__a__) (__a__ * millisClockCyclesPerMicrosecond())

/* Timers and Timer-like-things
* These are used for two things: Identifying the timer on a pin in
Expand Down
Loading

0 comments on commit 70032b0

Please sign in to comment.