My SYS Object
eldonb46
Posts: 70
In preparation of using potentially New Spin Improvements, I have created for my use, a "SYS" Object. As a Noobe, this OBJ implements some of my desired SPIN constructs.
In hindsight, and from the beginning I should have made better use of OBJ's to make my SPIN learning effort easier.
For background see: http://forums.parallax.com/showthread.php?142822-SPIN-improvements,
and my interest at: http://forums.parallax.com/showthread.php?142822-SPIN-improvements&p=1132031#post1132031
There is nothing NEW here, almost everyone has created these methods many times, except maybe, "Pause with Sync" which delays to a future time event. For example, with "PauseSecSync" I can easily blink a LED for 1600 millisecs at precise 10 second intervals, without having to think about the system overhead math. Example:
This is my current "SYS" Object:
The one nice thing about implementing these as an Object, is that I got to play with the syntax; for example, I wrote the different Sync method names several different ways until I liked the results. Some of my experimental names for "PauseMsSync" were: "SyncPauseMs", "PauseSyncMs" and "SyncMs". I opted for a syntax and name similar to the included "PauseMs", with the "Sync" suffix - it makes it easy to remember and easy to change forms.
Please comment and suggest code improvement (there should probably be some overhead taken into consideration for the Sync methods).
I am now looking for other short, sweet, and productive, methods to include.
Regards,
Eldon - WA0UWH - It is all fun, with the Prop!
In hindsight, and from the beginning I should have made better use of OBJ's to make my SPIN learning effort easier.
For background see: http://forums.parallax.com/showthread.php?142822-SPIN-improvements,
and my interest at: http://forums.parallax.com/showthread.php?142822-SPIN-improvements&p=1132031#post1132031
There is nothing NEW here, almost everyone has created these methods many times, except maybe, "Pause with Sync" which delays to a future time event. For example, with "PauseSecSync" I can easily blink a LED for 1600 millisecs at precise 10 second intervals, without having to think about the system overhead math. Example:
PauseSyncInit(Timer) repeat outa[LED]~~ PauseMs(1600) outa{LED]~ PauseSecSync(Timer, 10)
This is my current "SYS" Object:
CON 'SYSTEM PAUSE with SYNC to a Future Time Event 'Note: These PauseSync Methods do not support Elapsed Time longer than 52 Seconds VAR Long Timers[9] 'Available Timers PUB PauseSyncInit(TimerIndex) Timers[TimerIndex] := cnt PUB PauseSecSync(TimerIndex, _sec) PauseCntSync(TimerIndex, CLKFREQ * _sec) PUB PauseMsSync(TimerIndex, _ms) PauseCntSync(TimerIndex, CLKFREQ / 1000 * _ms) PUB PauseCntSync(TimerIndex, _cnt) waitcnt(Timers[TimerIndex] += _cnt) CON 'SYSTEM PAUSE WMin = 381 PUB PauseMin(_min) repeat _min PauseSec(60) PUB PauseSec(_sec) repeat _sec PauseMS(1000) PUB PauseMS(_ms) waitcnt(((clkfreq / 1_000 * _ms - 3932) #> WMin) + cnt)
The one nice thing about implementing these as an Object, is that I got to play with the syntax; for example, I wrote the different Sync method names several different ways until I liked the results. Some of my experimental names for "PauseMsSync" were: "SyncPauseMs", "PauseSyncMs" and "SyncMs". I opted for a syntax and name similar to the included "PauseMs", with the "Sync" suffix - it makes it easy to remember and easy to change forms.
Please comment and suggest code improvement (there should probably be some overhead taken into consideration for the Sync methods).
I am now looking for other short, sweet, and productive, methods to include.
Regards,
Eldon - WA0UWH - It is all fun, with the Prop!