@user123random
You must vastly simplify your code to make it readable ... to yourself and others. There is much repetition and the number of unnecessary casts just add to the complexity.
Introduce some intermediate variables; e.g.
1 2 3
|
double t0 = time_ps - number_of_baud_clocks_passed * BAUD_OUT_PERIOD;
double t1 = 0.5 * BAUD_OUT_PERIOD - HALF_48MHz_PERIOD;
double t2 = 0.5 * BAUD_OUT_PERIOD + HALF_48MHz_PERIOD;
|
Your if statement then reduces to
if ( number_of_baud_clocks_passed == 974979 && t0 >= t1 && t0 <= t2 )
and your cout statements could be considerably shortened.
As you have originally posted,
- each call to update_clk() increases time_ps by 2*HALF_48MHz_PERIOD; so you will need 5000 of these (give or take floating point rounding) to reach one BAUD_OUT_PERIOD
- for
number_of_baud_clocks_passed == 974979 |
you would need about 5000 * 974979 passes through that loop.
- if there was perfect precision then
t0 = time_ps - number_of_baud_clocks_passed * BAUD_OUT_PERIOD |
would be zero ... so the latter two conditions in the if statement would never be met.
I should go back and greatly simplify your code. Don't write massive long statements repeatedly and don't make it complicated by unnecessary casts.
You might like to actually state what your code is intending to do in words.