A programmable PWM generator. The desired frequency and duty cycle is programmed by setting pwm_top
and pwm_threshold
. A counter counts from 0 to pwm_top
(over and over), the pwm signal is high as when the counter is <= pwm_threshold
.
pwm_top
is wired to uio (all of them are used as inputs)
pwm_threshold
is wired to ui
They are encoded as follows
pwm_top <= uio(7 downto 5) << uio(4 downto 0)
pwm_threshold <= ui(7 downto 5) << ui(4 downto 0)
Resulting frequency of PWM signal is: $f_{out} = \frac{f_{in}}{pwm_{top} + 1}$
Resulting duty cycle is: $f = \frac{pwm_{threshold}+1}{pwm_{top}+1}$
The goal is to have wide as possible frequency range while still being able to go from 0% to 100% in duty cycle.
Use above formulas to determine value of pwm_threshold
and pwm_top
, hard ware them to this value or connect through switches. Probe output on oscilloscope
Switches and oscilloscope
# | Input | Output | Bidirectional |
---|---|---|---|
0 | pwm_threshold shift_amount[0] | pwm output | input: pwm_top shift_amount[0] |
1 | pwm_threshold shift_amount[1] | design is enabled (active high) | input: pwm_top shift_amount[1] |
2 | pwm_threshold shift_amount[2] | wired 0 | input: pwm_top shift_amount[2] |
3 | pwm_threshold shift_amount[3] | wired 0 | input: pwm_top shift_amount[3] |
4 | pwm_threshold shift_amount[4] | wired 0 | input: pwm_top shift_amount[4] |
5 | pwm_threshold base[0] | wired 0 | input: pwm_top base[0] |
6 | pwm_threshold base[1] | wired 0 | input: pwm_top base[1] |
7 | pwm_threshold base[3] | wired 0 | input: pwm_top base[2] |