Constant (CON) Declaration question
RobertW
Posts: 66
Can anyone explain why I get an error message with the following code:
CON
· ScanTime = (clkfreq / 100) + cnt··············· '10 millisecs scan time
I am looking to set a constant for a delay that I can use in different parts of my program.· This way I would not have to retype 'clkfreq / 100 + cnt' everytime.· Is this possible?· Thanks.
-Rob W.
CON
· ScanTime = (clkfreq / 100) + cnt··············· '10 millisecs scan time
I am looking to set a constant for a delay that I can use in different parts of my program.· This way I would not have to retype 'clkfreq / 100 + cnt' everytime.· Is this possible?· Thanks.
-Rob W.
Comments
cnt is a register in the chip, not a constant (in that context anyway). clkfreq is a value stored by the compiler in location $0 of the hub ram. The interpreter inserts this value when you use the "clkfreq" command. Although in theory it should be available at compile time, none of the current compilers are geared to make that happen.
Every call you use that value you will need the current cnt value. To speed things up you could define a long in VAR and assign that the value of clkfreq / 100 when your program starts up. Every time you want to use that you'd use WAITCNT(cnt + ScanTime).
Despite almost every example people post to the forum where it's "some calculation" + cnt, you should really put "cnt" as the first value inside the brackets. This just makes your time calculation that little bit more accurate as the cnt value gets pushed onto the stack prior to any of the other calculations taking place.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life may be "too short", but it's the longest thing we ever do.
But you still have to do your delays with something like this:
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 1/20/2010 3:49:18 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
In actual fact I tend to create delay constants as Phil suggested above, based on my XIN and PLL settings.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
-Rob