View Full Version : Global Constant
07-15-2009, 11:45 PM
Is it possible to create a master constant that will trickle down through all objects under the "top object"? Specifically, I'd like to set the project frequency (_clkfreq) in the top object and have it apply to everything underneath that has a timing requirement (without editing the child objects).
07-16-2009, 12:07 AM
I don't think so, at least not with the Prop Tool...
But, I suppose you could have an object with all your constants in it and just include that object in all your files...
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
07-16-2009, 12:48 AM
I've done what Rayman suggests. In BoeBotBasic, there's a "BB_definitions.spin" file that's included as an object in everything. It contains basic constant definitions for I/O pins, work areas. It also includes a couple of very small routines used in most I/O drivers. Only one copy of the compiled code is included in the program because of how the Propeller Tool combines identical code. This definitions file also includes the master definitions for _xinfreq and _clkmode.
07-16-2009, 06:54 AM
I also use the method Rayman mentions. But there is one more thing you have to do, and that's redeclare the constant in the program that uses it. This is because there are some places in SPIN (I forget exactly where at the moment - maybe in PASM code in a DAT block) that won't accept the object#value syntax.
The once-off overhead of the few bytes required to import the constants file is usually worth it.
Catalina - a FREE C compiler for the Propeller - see Catalina (http://forums.parallax.com/showthread.php?p=795326)
07-16-2009, 07:15 AM
Thanks, Ross, that was it. I wasn't quite following Mike's suggestion but now it makes perfect sense.
Phil Pilgrim (PhiPi)
07-16-2009, 07:25 AM
Is there some reason you need specific access to a user-defined _clkfreq instead of using the already-global clkfreq contained in long?