- Notifications
You must be signed in to change notification settings - Fork 10
Description
This probably doesn't cause problems at 31.25kBaud off a 16MHz clock, but the Baud rate calculation is wrong. I was trying to reuse the module and testing with 1MBaud off 12MHz (divider of 12) and found that the bits were 14 clocks long.
The local parameter "cfg_divider" is set at line 47 to the simple ratio of clock to Baud.
At line 142 (also 130, 158, 203) the bit timing counter is tested for being strictly greater than this and, if so, cleared to zero onthenextclock*. Thus with a divider of 12, the counter cycles through from 0 to 13, giving a total of 14 counts.
The fix is in two parts. First, change all of those ">" tests to ">=". Second, calculated the cfg_divider as (clk/Baud)-1 (which is very common in hardware UART Baud generator registers).