_CLKFREQ vs CLKFREQ vs CLK_FREQ
dbpage
Posts: 217
in Propeller 1
The Propeller Manual is very clear, _CLKFREQ is the original system clock frequency at startup and CLKFREQ is the current system clock frequency. They both may be the same value, but they can be different if the application changes the clock speed.
Of what use is the following CLK_FREQ constant?
Is it solely to establish other constants, such as:
Are there run-time uses for the constant CLK_FREQ?
Of what use is the following CLK_FREQ constant?
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq ' system freq as a constant
Is it solely to establish other constants, such as:
CON TIME1 = CLK_FREQ / 2 TIME = CLK_FREQ - SEC_LED_HI_TIME
Are there run-time uses for the constant CLK_FREQ?
Comments
Edit: note also that the above CLK_FREQ is only useful if you intend to change the values of _xinfreq or which PLL multiplier you are using with XTAL1. If you aren't going to do either, then you may as well just set CLK_FREQ = 80_000_000, which would more directly convey your meaning.
That is indeed quite a handy snippet. After learning that trick from Jon's coding examples, I also begin all of my programs that way.
In your next iteration of the spin compiler, would you consider changing the behavior of _xinfreq and _clkfreq a bit? In particular, have them be predefined with default values and implicitly in scope. User code can override them as they do now, except that both constants will be "in scope" even though only one was explicitly set. For instance, if code sets _xinfreq, then _clkfreq is implicitly updated. Both _xinfreq and _clkfreq would be accessible to the user code (even though _clkfreq was not explicitly set). After all, this is exactly what the above code is meant to achieve, but adds unnecessary confusion since there is already a predefined constant (_clkfreq) that means the same thing.