BitFlow

Configurable PWM Block

advanced · interface · 270 XP

Sign in to write your solution, run it in the simulator and submit it for grading.

Sign in or create a free account →

Problem

Configurable PWM Block A **Pulse-Width Modulation** generator with programmable period and duty cycle. Internal counter counts 0 to `period`; output is high while counter < `duty`. New period/duty values are captured at the **start of a new period** (shadow register technique) to prevent glitches. **Registers** (written via write-enable interface) | Register | Width | Description | |---------------|-------|----------------------------------------| | `period` | 8 | Counter max value (period−1) | | `duty` | 8 | Duty cycle threshold (0 = always low) | **Interface** | Port | Direction | Width | Description | |------------|-----------|-------|---------------------------------| | `clk` | input | 1 | System clock | | `rst` | input | 1 | Sync reset | | `wr_period`| input | 1 | Write enable for period | | `wr_duty` | input | 1 | Write enable for duty | | `wr_data` | input | 8 | Data for writes | | `pwm_out` | output | 1 | PWM output signal | **Timing & Glitch Prevention** 1. **Shadow registers:** Store new values in temporary registers when written 2. **Period transition:** At counter = `period_current`, load shadow values into active registers 3. **No mid-period glitches:** Changes take effect only at period boundaries **Behavior** - Counter counts 0 to `period` continuously - `pwm_out = (counter < duty)` - When `counter == period`, reset to 0 and load any pending shadow updates - If `duty > period`, PWM is always high (saturated) - If `duty = 0`, PWM is always low **Duty cycle examples** - Period=100 (0–100, 101 values), Duty=50 → 50% duty cycle (high for 0–49) - Period=100, Duty=0 → 0% (always low) - Period=100, Duty=100+ → 100% (always high) **Glitch-free updates:** A write to period or duty while PWM is running takes effect at the next period start, not immediately.

Constraints

  • Shadow register technique: new values latched but not applied until counter reaches period.
  • Counter counts from 0 to period (inclusive); total period = period + 1 clocks.
  • pwm_out = (counter < duty), computed combinationally from active registers.
  • Updates are synchronous and glitch-free (no mid-period changes).
  • If duty = 0, pwm_out is always 0. If duty > period, pwm_out is always 1.

Examples

Input: period=9 (10 counts), duty=3

Output: pwm_out high for counts 0–2, low for 3–9 (30% duty)

Normal PWM

Input: period=99, duty=0

Output: pwm_out always low

0% duty cycle

Input: period=99, duty=100

Output: pwm_out always high

Oversaturation (100% duty)

Input: Change period during operation

Output: New period takes effect at next counter wrap

Glitch-free

Input: Rapid duty changes: 25%, 50%, 75%

Output: Duty changes smoothly at period boundaries

No glitches

Common questions

What does the Configurable PWM Block problem ask you to build?
Configurable PWM Block A **Pulse-Width Modulation** generator with programmable period and duty cycle. Internal counter counts 0 to `period`; output is high while counter < `duty`. New period/duty values are captured at the **start of a new period** (shadow register technique) to prevent glitches.
What constraints does Configurable PWM Block have?
Shadow register technique: new values latched but not applied until counter reaches period.; Counter counts from 0 to period (inclusive); total period = period + 1 clocks.; pwm_out = (counter < duty), computed combinationally from active registers.; Updates are synchronous and glitch-free (no mid-period changes).; If duty = 0, pwm_out is always 0. If duty > period, pwm_out is always 1.
What is an example input and output for Configurable PWM Block?
Input period=9 (10 counts), duty=3 gives output pwm_out high for counts 0–2, low for 3–9 (30% duty). Normal PWM
Which Verilog concepts does Configurable PWM Block practise?
interface, PWM, configurable, interview, control.