Browse Source

Merge pull request #422 from KurtE/T4_IntervalTimer_magic_number

T4 IntervalTimer - change limit magic number
teensy4-core
Paul Stoffregen 4 years ago
parent
commit
edee8862e2
No account linked to committer's email address
1 changed files with 4 additions and 4 deletions
  1. +4
    -4
      teensy4/IntervalTimer.h

+ 4
- 4
teensy4/IntervalTimer.h View File

bool begin(void (*funct)(), unsigned int microseconds) { bool begin(void (*funct)(), unsigned int microseconds) {
if (microseconds == 0 || microseconds > MAX_PERIOD) return false; if (microseconds == 0 || microseconds > MAX_PERIOD) return false;
uint32_t cycles = (24000000 / 1000000) * microseconds - 1; uint32_t cycles = (24000000 / 1000000) * microseconds - 1;
if (cycles < 36) return false;
if (cycles < 17) return false;
return beginCycles(funct, cycles); return beginCycles(funct, cycles);
} }
bool begin(void (*funct)(), int microseconds) { bool begin(void (*funct)(), int microseconds) {
bool begin(void (*funct)(), float microseconds) { bool begin(void (*funct)(), float microseconds) {
if (microseconds <= 0 || microseconds > MAX_PERIOD) return false; if (microseconds <= 0 || microseconds > MAX_PERIOD) return false;
uint32_t cycles = (float)(24000000 / 1000000) * microseconds - 0.5; uint32_t cycles = (float)(24000000 / 1000000) * microseconds - 0.5;
if (cycles < 36) return false;
if (cycles < 17) return false;
return beginCycles(funct, cycles); return beginCycles(funct, cycles);
} }
bool begin(void (*funct)(), double microseconds) { bool begin(void (*funct)(), double microseconds) {
void update(unsigned int microseconds) { void update(unsigned int microseconds) {
if (microseconds == 0 || microseconds > MAX_PERIOD) return; if (microseconds == 0 || microseconds > MAX_PERIOD) return;
uint32_t cycles = (24000000 / 1000000) * microseconds - 1; uint32_t cycles = (24000000 / 1000000) * microseconds - 1;
if (cycles < 36) return;
if (cycles < 17) return;
if (channel) channel->LDVAL = cycles; if (channel) channel->LDVAL = cycles;
} }
void update(int microseconds) { void update(int microseconds) {
void update(float microseconds) { void update(float microseconds) {
if (microseconds <= 0 || microseconds > MAX_PERIOD) return; if (microseconds <= 0 || microseconds > MAX_PERIOD) return;
uint32_t cycles = (float)(24000000 / 1000000) * microseconds - 0.5; uint32_t cycles = (float)(24000000 / 1000000) * microseconds - 0.5;
if (cycles < 36) return;
if (cycles < 17) return;
if (channel) channel->LDVAL = cycles; if (channel) channel->LDVAL = cycles;
} }
void update(double microseconds) { void update(double microseconds) {

Loading…
Cancel
Save