瀏覽代碼

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

main
PaulStoffregen 5 年之前
父節點
當前提交
1be006032e
共有 1 個檔案被更改,包括 2 行新增2 行删除
  1. +2
    -2
      teensy4/pwm.c

+ 2
- 2
teensy4/pwm.c 查看文件

@@ -120,11 +120,11 @@ void quadtimerWrite(IMXRT_TMR_t *p, unsigned int submodule, uint16_t val)
{
uint32_t modulo = 65537 - p->CH[submodule].LOAD + p->CH[submodule].CMPLD1;
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(" 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);

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

Loading…
取消
儲存