Browse Source

Fix analogWrite for values 2^res or higher with quad timer PWM pins

teensy4-core
PaulStoffregen 5 years ago
parent
commit
1be006032e
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      teensy4/pwm.c

+ 2
- 2
teensy4/pwm.c View File

{ {
uint32_t modulo = 65537 - p->CH[submodule].LOAD + p->CH[submodule].CMPLD1; uint32_t modulo = 65537 - p->CH[submodule].LOAD + p->CH[submodule].CMPLD1;
uint32_t high = ((uint32_t)val * (modulo - 1)) >> analog_write_res; uint32_t high = ((uint32_t)val * (modulo - 1)) >> analog_write_res;
if (high >= modulo) high = modulo - 1; // TODO: is this check correct?
if (high >= modulo - 1) high = modulo - 2;


//printf(" modulo=%lu\n", modulo); //printf(" modulo=%lu\n", modulo);
//printf(" high=%lu\n", high); //printf(" high=%lu\n", high);
uint32_t low = modulo - high; // TODO: low must never be 0 or 1 - can it be??
uint32_t low = modulo - high; // low must 2 or higher
//printf(" low=%lu\n", low); //printf(" low=%lu\n", low);


p->CH[submodule].LOAD = 65537 - low; p->CH[submodule].LOAD = 65537 - low;

Loading…
Cancel
Save