Shop OBEX P1 Docs P2 Docs Learn Events
Global Constant — Parallax Forums

Global Constant

JonnyMacJonnyMac Posts: 9,197
edited 2009-07-15 23:25 in Propeller 1
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).

Comments

  • RaymanRayman Posts: 14,844
    edited 2009-07-15 16:07
    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
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-15 16:48
    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.
  • RossHRossH Posts: 5,512
    edited 2009-07-15 22:54
    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.

    For example:
    Constants_File.spin said...

    CON
    My_Constant=1
    Program_File.spin said...

    OBJ
    Constants: "Constants_File.spin"

    CON
    My_Constant= Constants#My_Constant

    ...

    The once-off overhead of the few bytes required to import the constants file is usually worth it.

    Ross.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Catalina - a FREE C compiler for the Propeller - see Catalina
  • JonnyMacJonnyMac Posts: 9,197
    edited 2009-07-15 23:15
    Thanks, Ross, that was it. I wasn't quite following Mike's suggestion but now it makes perfect sense.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-07-15 23:25
    Jon,

    Is there some reason you need specific access to a user-defined _clkfreq instead of using the already-global clkfreq contained in long[noparse][[/noparse]0]?

    -Phil
Sign In or Register to comment.