- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

EP4CE6E22C8. 66MHz input clock --> Clk. Expecting roughly 115KHz on outClk. I get roughly 57Khz and some spare change. I swear I have been through this multiple times & I cannot figure out what's up. Yes, I'm a noob.

First foray into this space since I retired.

```
library ieee;
use ieee.std_logic_1164.all;
entity BaudClockGenerator is
port
(
Clk : in std_logic;
OutClk : out std_logic
);
end entity;
architecture rtl of BaudClockGenerator is
CONSTANT g_CLKS_PER_BIT:integer:= 66_000_000/115200;
signal r_Clk_Count : integer range 0 to g_CLKS_PER_BIT-1 := 0;
signal tmp : std_logic := '0';
begin
BitPeriodProcess:process(Clk)
begin
if rising_edge(clk) then
r_Clk_Count <= r_Clk_Count +1;
if r_Clk_Count > g_CLKS_PER_BIT -1 then
r_Clk_Count <= 0;
tmp <= NOT tmp;
end if;
end if;
outClk <= tmp;
end process;
end rtl;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hello Pete,

From the code snippet I see that there is a mistake in the g_CLKS_PER_BIT calculation, which is supposed to represent the number of input clock cycles required to generate one bit of the output signal.

The value of g_CLKS_PER_BIT is calculated as 66_000_000/115200 = 572, which is incorrect. The correct value of g_CLKS_PER_BIT should be calculated as 66_000_000/115_200/2 = 284.72, which represents the number of input clock cycles required to generate half of one bit of the output signal. This is because the process generates a square wave with a 50% duty cycle, which means that it takes two clock cycles to generate one full bit period.

Since the r_Clk_Count signal is incremented by 1 on each clock cycle and the output signal is generated on every second cycle, the actual output frequency will be half of the expected frequency, which is 57.6 kHz instead of 115.2 MHz.

To fix this issue, you should update the g_CLKS_PER_BIT constant to the correct value of 284.72, which represents the number of input clock cycles required to generate half of one bit of the output signal.

The updated code should look like:

library ieee;

use ieee.std_logic_1164.all;

entity BaudClockGenerator is

port

(

Clk : in std_logic;

OutClk : out std_logic

);

end entity;

architecture rtl of BaudClockGenerator is

CONSTANT g_CLKS_PER_BIT:integer:= 66_000_000/115_200/2;

signal r_Clk_Count : integer range 0 to g_CLKS_PER_BIT-1 := 0;

signal tmp : std_logic := '0';

begin

BitPeriodProcess:process(Clk)

begin

if rising_edge(clk) then

r_Clk_Count <= r_Clk_Count +1;

if r_Clk_Count > g_CLKS_PER_BIT -1 then

r_Clk_Count <= 0;

tmp <= NOT tmp;

end if;

end if;

outClk <= tmp;

end process;

end rtl;

p/s: If any answer from the community or Intel Support are helpful, please feel free mark and solution, give kudos and rate 5/5 survey.

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

A full clock period requires 2 clock flips, not just one. g_CLKS_PER_BIT should be further divided by 2 so tmp gets flipped twice as often.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hello Pete,

From the code snippet I see that there is a mistake in the g_CLKS_PER_BIT calculation, which is supposed to represent the number of input clock cycles required to generate one bit of the output signal.

The value of g_CLKS_PER_BIT is calculated as 66_000_000/115200 = 572, which is incorrect. The correct value of g_CLKS_PER_BIT should be calculated as 66_000_000/115_200/2 = 284.72, which represents the number of input clock cycles required to generate half of one bit of the output signal. This is because the process generates a square wave with a 50% duty cycle, which means that it takes two clock cycles to generate one full bit period.

Since the r_Clk_Count signal is incremented by 1 on each clock cycle and the output signal is generated on every second cycle, the actual output frequency will be half of the expected frequency, which is 57.6 kHz instead of 115.2 MHz.

To fix this issue, you should update the g_CLKS_PER_BIT constant to the correct value of 284.72, which represents the number of input clock cycles required to generate half of one bit of the output signal.

The updated code should look like:

library ieee;

use ieee.std_logic_1164.all;

entity BaudClockGenerator is

port

(

Clk : in std_logic;

OutClk : out std_logic

);

end entity;

architecture rtl of BaudClockGenerator is

CONSTANT g_CLKS_PER_BIT:integer:= 66_000_000/115_200/2;

signal r_Clk_Count : integer range 0 to g_CLKS_PER_BIT-1 := 0;

signal tmp : std_logic := '0';

begin

BitPeriodProcess:process(Clk)

begin

if rising_edge(clk) then

r_Clk_Count <= r_Clk_Count +1;

if r_Clk_Count > g_CLKS_PER_BIT -1 then

r_Clk_Count <= 0;

tmp <= NOT tmp;

end if;

end if;

outClk <= tmp;

end process;

end rtl;

p/s: If any answer from the community or Intel Support are helpful, please feel free mark and solution, give kudos and rate 5/5 survey.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi Pete,

Did you manage to work on the issue?

Let me know if there is any update at your end.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

* As we do not receive any response from you on the previous question/reply/answer that we have provided. Please login to ‘https://supporttickets.intel.com’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.*

*p/s: If any answer from community or Intel support are helpful, please feel free to mark as solution, give Kudos and rate 5/5 survey*

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page