CN / EN
文档反馈
感谢关注汇顶文档,期待您的宝贵建议!
感谢您的反馈,祝您愉快!
无匹配项 共计114个匹配页面

PWM

Introduction

GR5526 SoC has two instances of Pulse Width Modulation (PWM) module. The PWM generates successive pulses with variable duty cycles that can be converted to analog levels by external discrete components, such as controlling LED brightness via a PWM signal.

Main Features

  • Configurable output frequency and dynamic frequency configuration
  • The three PWM channel outputs (pwma, pwmb, and pwmc) can only be configured independently in the flicker mode.
  • Two operation modes: flicker mode and breath mode
  • Two alignment modes: edge alignment mode and center alignment mode
  • Configurable duty cycles in flicker mode
  • Three configuration modes: synchronize-all, synchronize-separate, and asynchronous
  • Polarity switching to support positive-drive and negative-drive mode
  • Optional stop I/O voltage level in active/idle mode: low level or high level

Block Diagram

The PWM block diagram is illustrated in 图 23.

图 23 PWM block diagram

Functional Description

The PWM is capable of configuring output frequency dynamically.

The PWM block can provide three independent channel outputs: pwma, pwmb and pwmc in flicker mode.

The PWM block has two operation modes: flicker mode and breath mode.

In flicker mode, the PWM module outputs successive pulses with a certain frequency and duty as configured. In breath mode, the duty of PWM output periodically changes from 0% to 100%, and then 100% to 0% uniformly. The change period is configurable.

In flicker mode, the duty of PWM can be configured in the range of 0% to 100%. The three outputs can be configured independently, and they share one output frequency.

In flicker mode, both edge alignment and center alignment are supported.

Choose edge alignment mode, as shown in the 图 24. All open channels are aligned at the beginning of each duty cycle.

图 24 PWM edge alignment

Choose center alignment mode, as shown in the 图 25. All open channels are aligned in the middle of each duty cycle.

图 25 PWM center alignment

The configured data can be updated into active registers in three modes: synchronize-all mode (enabled by UPDATE_SYNC_AE), synchronize-separate mode (enabled by UPDATE_SYNC_Sxx) and asynchronous update mode (enabled by UPDATE_SYNC_AE and UPDATE_SYNC_Sxx).

In breath mode, the breathing cycle can be set by BR_PRD, which represents the number of PWM cycles required for the duty cycle 0%→100% and then 100%→0%

In breath mode, a configurable duration of breath hold state (HOLD) is supported. The breath hold state is set between two adjacent breath processes, which are duty change (0%→100%→0%), breath hold, and duty change (0%→100%→0%). In the hold state, the PWM output is driven by inactive state.

Both positive-drive mode and negative-drive mode are supported and can be configured in PD_x_EN. In positive-drive mode, a valid output is configured by setting the PWM output logic level to 1, and an invalid output is set when the PWM output logic level is 0. In negative-drive mode, a valid output is configured by setting the PWM output logic level to 0, and an invalid output is set when PWM output logic level is 1.

In flicker mode, if the stop level is configured (the default value of FLICKER_PAUSE_LEVEL_x is 0 when not set), when PWM stops, the I/O level of the corresponding channel will be pulled to the set value. In breath mode, the I/O levels of all channels are the same and set by BREATH_PAUSE_LEVEL when PWM stops. When the MCU enters sleep state, the stop level remains high in both flicker mode and breath mode.

Operation

There are several shadow registers in the PWM module. The write operation will first change the shadow registers, and then will update the value of active registers from the shadow registers under certain conditions.

Active registers update conditions:

  1. In synchronize-all update mode (UPDATE_SYNC_AE = 0x1), all effective registers of flicker mode or breath mode will be updated simultaneously. In flicker mode (BREATH_EN = 0), after writing to PRD, CMPxx and AQ_CTRL will update from shadow registers simultaneously when the Time Base counter counts to a value of PRD minus 1.

    图 26 Flicker mode waveform

    In breath mode (BREATH_EN = 1), after writing to PRD, BR_PRD, and HOLD will update from shadow registers simultaneously when the current breath process ends (the moment PWM duty reduces to 0%). When using the app_pwm_update_freq interface, the PWM frequency will be updated immediately.

    图 27 Breath mode waveform
  2. In synchronize-separate update mode (UPDATE_SYNC_AE = 0x0), PRD, CMPxx, and AQ_CTRL will update when the Time Base counter counts to value of the PRD register minus 1 if the corresponding UPDATE_SYNC_Sxx bit is set. BR_PRD and HOLD will update when the current breath process ends and the corresponding UPDATE_SYNC_Sxx bit is set.

  3. In asynchronous update mode (UPDATE_SYNC_AE = 0x0 && UPDATE_SYNC_Sxx = 0x0), all registers will update instantly.

In initial state, set the update mode first, then PRD, CMPxx, AQ_CTRL, BR_PRD, and HOLD registers are configured, and then, drive mode is configured to choose the positive-drive mode or negative-drive mode, finally, choose breath mode or flicker mode and enable PWM.

Duty Cycle Calculation

The PWM duty cycle can be configured as an integer from 0 to 100, depending on the following calculation formulas of the duty cycle accuracy "n".

  • In PWM_ALIGNED_EDGE mode:
    n = f PWM ÷ f SYSCLK × 100
  • In PWM_CENTER_EDGE mode:
    n = f PWM ÷ f SYSCLK × 200

For example, when the clock frequency is 64 MHz, and the duty cycle is in the range of 0 to 100, the maximum PWM frequency can only be set to 640 kHz in the PWM_ALIGNED_EDGE mode and 320 kHz in the PWM_ALIGNED_CENTER mode.

Recommended Setting in Breath Mode

In breath mode, in order to satisfy that the duty cycle of the waveform changes from 0 to 100 and then from 100 to 0, it is allowed to set the values of PRD and BR_PRD to an integer that is multiple(s) of 128. The freq, bperiod and hperiod in the structure pwm_init_t need to meet the following formula during initialization:

f r e q × b p e r i o d = 1000 × k k 2 & & k i n t e r g e r

SYS CLK 1000 × hperiod 16777215

where, k represents the number of PWM cycles required for the duty cycle from 0% to 100%; SYSCLK represents the system clock frequency.

Registers

MODE

  • Name: Mode Register
  • Description: This register sets the PWM operation mode.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x0
  • Reset Value: 0x00000000
Note:

*x is used to identify the PWM Module instance. The “x” can be 0 or 1.

表 186 Mode Register
Bits Field Name RW Reset Description

31:10

RSVD

R

Reserved bits

9

BREATH_PAUSE_LEVEL

RW

0x0

PWMA/B/C output IO level when suspending in Breath Mode

8

FLICKER_PAUSE_LEVEL_C

RW

0x0

PWMC output IO level when suspending in Flicker Mode

7

FLICKER_PAUSE_LEVEL_B

RW

0x0

PWMB output IO level when suspending in Flicker Mode

6

FLICKER_PAUSE_LEVEL_A

RW

0x0

PWMA output IO level when suspending in Flicker Mode

5

PD_C_EN

RW

0x0

PWMC positive-drive mode enable.

Value:

  • 0x0: negative-drive mode
  • 0x1: positive-drive mode

4

PD_B_EN

RW

0x0

PWMB positive-drive mode enable.

Value:

  • 0x0: negative-drive mode
  • 0x1: positive-drive mode

3

PD_A_EN

RW

0x0

PWMA positive-drive mode enable.

Value:

  • 0x0: negative-drive mode
  • 0x1: positive-drive mode

2

BREATH_EN

RW

0x0

Breath mode enable.

Value:

  • 0x0: flicker mode
  • 0x1: breath mode

1

PAUSE

RW

0x0

PWM pause signal.

Value:

  • 0x0: Ongoing
  • 0x1: Pause

0

ENABLE

RW

0x0

Enable PWM.

Value:

  • 0x0: Disable
  • 0x1: Enable

UPDATE

  • Name: Update Register
  • Description: This register is used to set the synchronous update mode.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x4
  • Reset Value: 0x00000000
表 187 Update Register
Bits Field Name RW Reset Description

31:18

RSVD

R

Reserved bits

17

UPDATE_SYNC_SAQCTRL

RW

0x0

Separate update enable of AQ_CTRL

Value:

  • 0x0: Disable
  • 0x1: Enable

16

UPDATE_SYNC_SHOLD

RW

0x0

Separate update enable of HOLD

Value:

  • 0x0: Disable
  • 0x1: Enable

15

UPDATE_SYNC_SBRPRD

RW

0x0

Separate update enable of BR_PRD

Value:

  • 0x0: Disable
  • 0x1: Enable

14

UPDATE_SYNC_SCMPC1

RW

0x0

Separate update enable of CMPC1

Value:

  • 0x0: Disable
  • 0x1: Enable

13

UPDATE_SYNC_SCMPC0

RW

0x0

Separate update enable of CMPC0

Value:

  • 0x0: Disable
  • 0x1: Enable

12

UPDATE_SYNC_SCMPB1

RW

0x0

Separate update enable of CMPB1

Value:

  • 0x0: Disable
  • 0x1: Enable

11

UPDATE_SYNC_SCMPB0

RW

0x0

Separate update enable of CMPB0

Value:

  • 0x0: Disable
  • 0x1: Enable

10

UPDATE_SYNC_SCMPA1

RW

0x0

Separate update enable of CMPA1

Value:

  • 0x0: Disable
  • 0x1: Enable

9

UPDATE_SYNC_SCMPA0

RW

0x0

Separate update enable of CMPA0

Value:

  • 0x0: Disable
  • 0x1: Enable

8

UPDATE_SYNC_SPRD

RW

0x0

Separate update enable of PRD

Value:

  • 0x0: Disable
  • 0x1: Enable

7:2

RSVD

R

Reserved bits

1

UPDATE_SYNC_AE

RW

0x0

Synchronous update enable

Value:

  • 0x0: Disable
  • 0x1: Enable

0

UPDATE_SYNC_AG

R

0x0

Synchronous update ongoing

Value:

  • 0x0: Not ongoing
  • 0x1: Ongoing

PRD

  • Name: Period Register
  • Description: This register is used to set the PWM cycle.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x8
  • Reset Value: 0x64
表 188 Period Register
Bits Field Name RW Reset Description

31:0

PRD

RW

0x64

The period of PWM output, PRD=fCLK/fPWM

CMPA0

  • Name: Compare A0 Register
  • Description: This register controls the PWM duty of Compare register 0 of channel A.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0xC
  • Reset Value: 0x00000000
表 189 Compare A0 Register
Bits Field Name RW Reset Description

31:0

CMPA0

RW

0x0

PWMA duty control register0

CMPA1

  • Name: Compare A1 Register
  • Description: This register controls the PWM duty of Compare register 1 of channel A.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x10
  • Reset Value: 0x00000000
表 190 Compare A1 Register
Bits Field Name RW Reset Description

31:0

CMPA1

RW

0x0

PWMA duty control register1

CMPB0

  • Name: Compare B0 Register
  • Description: This register controls the PWM duty of Compare register 0 of channel B.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x14
  • Reset Value: 0x00000000
表 191 Compare B0 Register
Bits Field Name RW Reset Description

31:0

CMPB0

RW

0x0

PWMB duty control register0

CMPB1

  • Name: Compare B1 Register
  • Description: This register controls the PWM duty of Compare register 1 of channel B.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x18
  • Reset Value: 0x00000000
表 192 Compare B1 Register
Bits Field Name RW Reset Description

31:0

CMPB1

RW

0x0

PWMB duty control register1

CMPC0

  • Name: Compare C0 Register
  • Description: This register controls the PWM duty of Compare register 0 of channel C.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x1C
  • Reset Value: 0x00000000
表 193 Compare C0 Register
Bits Field Name RW Reset Description

31:0

CMPC0

RW

0x0

PWMC duty control register0

CMPC1

  • Name: Compare C1 Register
  • Description: This register controls the PWM duty of Compare register 1 of channel C.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x20
  • Reset Value: 0x00000000
表 194 Compare C1 Register
Bits Field Name RW Reset Description

31:0

CMPC1

RW

0x0

PWMC duty control register1

AQ_CTRL

  • Name: Action Qualifier Control Register
  • Description: This register is used to set actions when counter reaches the compare value.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x24
  • Reset Value: 0x00000000
表 195 Action Qualifier Control Register
Bits Field Name RW Reset Description

31:12

RSVD

R

Reserved bits

11:10

AQ_CTRL_C1

RW

0x0

Action of event CNT_CMPC1 control register

Value:

  • 0x0: Do nothing
  • 0x1: Clear
  • 0x2: Set
  • 0x3: Toggle

9:8

AQ_CTRL_C0

RW

0x0

Action of event CNT_CMPC0 control register

Value:

  • 0x0: Do nothing
  • 0x1: Clear
  • 0x2: Set
  • 0x3: Toggle

7:6

AQ_CTRL_B1

RW

0x0

Action of event CNT_CMPB1 control register

Value:

  • 0x0: Do nothing
  • 0x1: Clear
  • 0x2: Set
  • 0x3: Toggle

5:4

AQ_CTRL_B0

RW

0x0

Action of event CNT_CMPB0 control register

Value:

  • 0x0: Do nothing
  • 0x1: Clear
  • 0x2: Set
  • 0x3: Toggle

3:2

AQ_CTRL_A1

RW

0x0

Action of event CNT_CMPA1 control register

Value:

  • 0x0: Do nothing
  • 0x1: Clear
  • 0x2: Set
  • 0x3: Toggle

1:0

AQ_CTRL_A0

RW

0x0

Action of event CNT_CMPA0 control register

Value:

  • 0x0: Do nothing
  • 0x1: Clear
  • 0x2: Set
  • 0x3: Toggle

BR_PRD

  • Name: Breath Period Register
  • Description: This register configures the period of breath mode.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x28
  • Reset Value: 0x00000000
表 196 Breath Period Register
Bits Field Name RW Reset Description

31:0

BREATH_PRD

RW

0x0

Register for breath period that is the required time (number of clock) that the duty changes from 0% to 100% in breath mode.

HOLD

  • Name: Hold Register
  • Description: This register configures the hold period in breath mode.
  • Base Address: 0x4000CB00 + x*0x100
  • Offset: 0x2C
  • Reset Value: 0x00000000
表 197 Hold Register
Bits Field Name RW Reset Description

31:24

RSVD

R

Reserved bits

23:0

HOLD

RW

0x0

Breath hold control register. The value should be the required number of clock in breath hold state.

扫描关注

打开微信,使用“扫一扫”即可关注。