enjoy-digital / colorlite

Take control of your Colorlight FPGA board with LiteX/LiteEth :)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

try to add a simple timer dosen't work

OJthe123 opened this issue · comments

Hi.
I just started with migen/LiteX and FPGA.

I want to add an UART to colorlite.py
So I copied and modified the parts from ios_stream.py. Sending four bytes over UART works fine. But it keep on sending as far as clock allows it.
So I tried to add a counter to slow it down. But I cannot get it to work.
Maybe this goal is too high for a beginner? Maybe you can give me a little help :-)

This is the part I added into colorlite.py

class IOStreamer(Module):
    """Stream bytes from memory over UART"""
    def __init__(self, pad, sys_clk_freq, baudrate):
        from litex.soc.cores.uart import RS232PHYTX

        # Timer/Counter
        self.counter = Signal(max=sys_clk_freq +1)
        
        # UART
        pads = Record([("tx", 1)])
        self.comb += pad.eq(pads.tx)
        phy = RS232PHYTX(pads, int((baudrate/sys_clk_freq)*2**32))
        self.submodules += phy

        # Memory
        mem  = Memory(8, 4, init=[0xAA, 0xBB, 0xCC, 0xDD])
        port = mem.get_port()
        
        
        self.specials += mem, port
        self.comb += phy.sink.valid.eq(1)
        self.comb += If(self.counter == int(12e6), self.counter.eq(0), phy.sink.data.eq(port.dat_r) ) 
        #self.comb += phy.sink.data.eq(port.dat_r)
        
        self.sync += self.counter.eq(self.counter+1)
        self.sync += If(phy.sink.ready, port.adr.eq(port.adr + 1))
        

and in the SoCMini section

# Servos -----------------------------------------------------------------------------------
        from litex.soc.cores.pwm import PWM
        for n in range(4):
            servo_pad = platform.request("servo", n)
            servo     = PWM(servo_pad)
            setattr(self.submodules, f"servo{n}", servo)

        # IO_Streamer ------------------------------------------------------------------------------
        self.submodules.iostreamer = IOStreamer(platform.request("gpio", 2), sys_clk_freq, baudrate=9600)

without my counter it is sending AA BB CC DD over UART. with my counter just zeros.
Where is my fault?