23.3.4.7 Amplitude, Offset and Fractional Compare Value
Instead of writing an absolute value to the compare registers (TCEn.CMPn, TCEn.CMPnBUF and TCEn.AMP), it is possible to write these as a fractional value between 0 and 2. The fractional value is in UQ1.15 format, ranging from 0 to 2 - 2-15. The actual compare value is calculated based on the Period (TCEn.PER), Amplitude (TCEn.AMP), and Offset (TCEn.OFFSET) registers.
The UQ1.15 format will cause up to one-bit loss in precision for high
period or amplitude values (> 0x8000
) but allows multiplication
>1, needed for Single slope where 100% duty cycle is achieved when CMPn > PER.
The Amplitude and Offset registers are used to set the range for the compare registers. The amplitude is calculated automatically from the TCEn.PER register if scaling (SCALE in TCEn.CTRLD) is enabled. The calculation occurs when the AMP register is written.
When the AMP register is written, the value is multiplied by the existing PER value and then stored in the AMP register. The multiplication is triggered when the high byte is written (TCEn.AMPH).
The data read from the AMP register are the value after the multiplication. The offset is automatically calculated based on the selected SCALEMODE for the following clock cycle.
Rewrite the TCEn.AMP register to ensure the identical relationship between the two registers if changing the period.
SCALEMODE | Amplitude(1,2) | Offset(3) |
---|---|---|
CENTER | AMPfrac * PER | (PER - AMP)/2 |
BOTTOM | AMPfrac * PER | 0 |
TOP | AMPfrac * PER | (PER - AMP) |
TOPBOTTOM | AMPfrac * PER | (PER - AMP) |
Note:
|
When writing a fractional value to the TCEn.CMPn or TCEn.CMPnBUF registers, they are multiplied first with the amplitude (TCEn.AMP) register, and then the offset (TCEn.OFFSET) is added. The multiplication is triggered when the high byte is written (TCEn.CMPnH or TCEn.CMPnBUFH) and completes as the data are written. The figure below shows the functionality for the CMPn registers, which works identically for the CMPnBUF registers.
The data read from the compare and compare buffer register are the value after the multiplication.
When changing the Period or Amplitude registers, the TCEn.CMPn or TCEn.CMPnBUF registers must be rewritten to ensure the same relationship to the period and amplitude.
SCALEMODE | Scaled CMPn
Value (AMPEN = 0 ) | Scaled CMPn
Value (AMPEN = |
---|---|---|
CENTER | CMPfrac * PER | CMPfrac * AMP + OFFSET |
BOTTOM | CMPfrac * PER | CMPfrac * AMP |
TOP | CMPfrac * PER | CMPfrac * AMP + OFFSET |
TOPBOTTOM | CMPfrac * PER | CMPf rac = 0x0000 : BOTTOMCMPfrac ≥
CMPfrac ≥ CMPfrac < |
Note:
|
Waveform Range with SCALE Enabled
When the scaled write is enabled, the values written to the TCEn.CMPn and TCEn.CMPnBUF are between 0 and 1, giving a duty cycle range between 0% and 100% of the PWM period. When using amplitude reduction, the compare registers are multiplied with the amplitude (TCEn.AMP) register as the range for the fractional value, and the generated compare values are adjusted with the offset (TCEn.OFFSET) register.
Examples below show the effective compare value in percentage of the period for the different scale modes where the amplitude is set to 90% of the period. The offsets are calculated according to Table 23-6. The black lines show the written compare value, identical for all cases, and the red line shows the effective compare value as a percentage of the period (PER).