Jump to content

# Syncing multiple clocks

## Recommended Posts

I have roughly the following clock scheme set up

```double refclk_period = 8000;
double ck1_ratio = 10;
double ck2_ratio = 5;
double ck3_ratio = 6;

sc_clock refclk("refclk", refclk_period, SC_PS);
sc_clock ck1("ck1", refclk_period/ck1_ratio, SC_PS);
sc_clock ck2("ck2", refclk_period/ck2_ratio, SC_PS);
sc_clock ck3("ck3", refclk_period/ck3_ratio, SC_PS);

```

Then I have SC_THREADs sensitive to each clock's pos(). I've realized a problem which is that eventually ck3 will get quite out of sync since it does not divide the refclk period evenly. For example at 8000 ps, the SC_THREAD watching ck3 last hit at 7998 ps. Ideally all the clocks should be firing at 8000 ps.

This has got to be a common problem. Is there a recommended way to sync clocks with SystemC? Thanks!

#### Share this post

##### Share on other sites

Note, I've realized I can kind of solve my problem by scaling the clock periods up so the division is even. e.g. make the reference clock period 24000. For the sake of studying the concept though I am still interested in whether explicitly syncing clocks is supported or recommended in SystemC

#### Share this post

##### Share on other sites

Hi, there's no explicit support for synchronizing clocks in SystemC.

Your solution of choosing "nice numbers" makes sense.

Regarding your comment

"This has got to be a common problem."

may not be true :-) Most industry use of SystemC is for virtual prototyping, which generally doesn't use clocks. People do use SystemC for synthesis of course, but then your problem is similar in any hardware description language (and in real hardware as well, hence the use of frequency synthesis techniques for clock division and multiplication on modern FPGAs).

regards

Alan

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

×

• Leaderboard