Skip to content

Commit

Permalink
Merge pull request #963 from MX682X/master
Browse files Browse the repository at this point in the history
Little improvement on TCA/TCD ISR
  • Loading branch information
SpenceKonde authored Jun 1, 2023
2 parents e23f6a8 + 28843d0 commit 672e35e
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 161 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 672e35e

Please sign in to comment.