Skip to content

Main content

Microcontroller: PWM Compare Polarity Crosswalk Tool

Resolve edge-aligned ideal PWM active ticks under an explicit inversion convention, assuming compare counts active ticks directly and excluding device-specific endpoint quirks.

Loading tool…

Description

Use compareTicks as activeTicks for noninverting polarity or periodTicks - compareTicks for inverting.

Timer formulas depend on whether endpoints are inclusive, the count direction, prescaling, and wrap behavior. A counter reading alone cannot reveal an arbitrary number of elapsed wraps.

Use compareTicks as activeTicks for noninverting polarity or periodTicks - compareTicks for inverting.

When to use this tool

Use Microcontroller: PWM Compare Polarity Crosswalk when you need a timer period, wrap delta, or explicit count-budget term.

How to use the tool and how it works

  1. Enter periodTicks, compareTicks, polarity. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read result. Expand result to inspect the returned fields.

Use compareTicks as activeTicks for noninverting polarity or periodTicks - compareTicks for inverting. Divide active ticks by the positive period for dutyFraction.1

Input fieldMeaning and unitsAccepted input
periodTicksPeriod TicksRequired. Safe integer.
compareTicksCompare TicksRequired. Safe integer.
polarityPolarityRequired. Text; one of "noninverting", "inverting". Implementation limit: 8192 Unicode code points and 16384 UTF-16 code units.
Output fieldInterpretationReturned shape
resultResultRequired. Object.
result.activeTicksActive TicksCalculated result member: number.
result.dutyFractionDuty FractionCalculated result member: number.
json
{
  "input": {
    "periodTicks": 10,
    "compareTicks": 3,
    "polarity": "inverting"
  },
  "output": {
    "result": {
      "activeTicks": 7,
      "dutyFraction": 0.7
    }
  }
}

Limitations and assumptions

  • This ideal ratio omits endpoint special cases, dead time, and hardware-specific PWM behavior.
  • Outputs are nested inside result. Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
  • Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.

Alternative or Complementary methods

Check the timer mode and register semantics in the device documentation, including synchronization and latency.

References

  1. Calculation and input contract: microcontroller/pwm-compare-polarity-crosswalk — tool.io

Similar or alternative tools