Software PWM Generation

Medium C Control
Solve this problem

Implement a software PWM generator in C using a timer tick function. The PWM must allow configurable duty cycle and period.

Constraints

  • tick() called periodically.
  • period and duty in ticks.
  • pwm_output() returns HIGH/LOW.
  • Internal counter rolls over.
  • duty <= period.
Starter codeC
1void pwm_init(int period, int duty);2int pwm_tick();