hw: support duty cycles other than 50%
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
6d8875850c
commit
8b2241a9e6
@ -336,21 +336,24 @@ class SBLED(Module, AutoCSR):
|
|||||||
self.ctrl = CSRStorage(4)
|
self.ctrl = CSRStorage(4)
|
||||||
|
|
||||||
self.bypass = CSRStorage(3)
|
self.bypass = CSRStorage(3)
|
||||||
self.pwm_count = CSRStorage(24)
|
self.pulse = CSRStorage(24)
|
||||||
|
self.duty = CSRStorage(24)
|
||||||
self.sent_pulses = CSRStatus(32)
|
self.sent_pulses = CSRStatus(32)
|
||||||
self.detected_pulses = CSRStatus(32)
|
self.detected_pulses = CSRStatus(32)
|
||||||
|
|
||||||
count = Signal(24)
|
count = Signal(24)
|
||||||
led_value = Signal()
|
led_value = Signal()
|
||||||
|
last_led_value = Signal()
|
||||||
rgb = Signal(3)
|
rgb = Signal(3)
|
||||||
sent_pulses = Signal(32)
|
sent_pulses = Signal(32)
|
||||||
detected_pulses = Signal(32)
|
detected_pulses = Signal(32)
|
||||||
rgba_drv = Signal(3)
|
rgba_drv = Signal(3)
|
||||||
|
|
||||||
self.sync += [
|
self.sync += [
|
||||||
|
last_led_value.eq(led_value),
|
||||||
# When the PWM count is updated, reset everything and
|
# When the PWM count is updated, reset everything and
|
||||||
# copy the results out.
|
# copy the results out.
|
||||||
If(self.pwm_count.re,
|
If(self.pulse.re,
|
||||||
count.eq(0),
|
count.eq(0),
|
||||||
|
|
||||||
self.sent_pulses.status.eq(sent_pulses),
|
self.sent_pulses.status.eq(sent_pulses),
|
||||||
@ -359,19 +362,30 @@ class SBLED(Module, AutoCSR):
|
|||||||
self.detected_pulses.status.eq(detected_pulses),
|
self.detected_pulses.status.eq(detected_pulses),
|
||||||
detected_pulses.eq(0),
|
detected_pulses.eq(0),
|
||||||
|
|
||||||
).Elif(count < self.pwm_count.storage,
|
led_value.eq(0),
|
||||||
count.eq(count + 1),
|
|
||||||
|
|
||||||
|
).Elif(count < self.pulse.storage,
|
||||||
|
count.eq(count + 1),
|
||||||
|
If(count < self.duty.storage,
|
||||||
|
led_value.eq(0),
|
||||||
).Else(
|
).Else(
|
||||||
count.eq(0),
|
led_value.eq(1),
|
||||||
led_value.eq(~led_value),
|
|
||||||
If(led_value,
|
# On the transition from 0 > 1, increment the counter
|
||||||
|
# and see if the LED has changed. If so, increment
|
||||||
|
# the number of detected pulses.
|
||||||
|
If(~last_led_value,
|
||||||
sent_pulses.eq(sent_pulses + 1),
|
sent_pulses.eq(sent_pulses + 1),
|
||||||
If(detected_pulse,
|
If(detected_pulse,
|
||||||
detected_pulses.eq(detected_pulses + 1),
|
detected_pulses.eq(detected_pulses + 1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
).Else(
|
||||||
|
# Reset the count once it gets greater than "Pulse"
|
||||||
|
count.eq(0),
|
||||||
|
led_value.eq(0),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Wire up the bypasses
|
# Wire up the bypasses
|
||||||
@ -404,7 +418,7 @@ class SBLED(Module, AutoCSR):
|
|||||||
o_RGB2 = pads.rgb2,
|
o_RGB2 = pads.rgb2,
|
||||||
p_CURRENT_MODE = "0b1", # Half current
|
p_CURRENT_MODE = "0b1", # Half current
|
||||||
p_RGB0_CURRENT = "0b000011", # 4 mA
|
p_RGB0_CURRENT = "0b000011", # 4 mA
|
||||||
p_RGB1_CURRENT = "0b000001", # 2 mA
|
p_RGB1_CURRENT = "0b000011", # 4 mA
|
||||||
p_RGB2_CURRENT = "0b000011", # 4 mA
|
p_RGB2_CURRENT = "0b000011", # 4 mA
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user