module uart_out_baudrate_gen #( parameter ClockFrequency = 12000000, parameter BaudRate = 9600,  parameter Oversampling = 1 )(
        input clock, enable,
        output tick  // generate a tick at the specified baud rate * oversampling
    );

    // A quicky for an int log2
    function integer log2(input integer v); begin
        log2=0;
        while(v>>log2)
            log2=log2+1;
        end
    endfunction

    localparam Count = (ClockFrequency/BaudRate); // for the oversampling = 1.  Um... I don't know for what.
    localparam CountWidth = log2(Count) + 2; // don't want to accidentally fill it with a load!

    reg [CountWidth-1:0] Counter = 0;

    always @(posedge clock)
        if( !enable )
            Counter <= Count - Oversampling - Oversampling - 1;
        else if ( Counter[CountWidth-1] )
            Counter <= Counter + Count - Oversampling;
        else
            Counter <= Counter - Oversampling;

    assign tick = Counter[CountWidth-1];
endmodule