udamonic.com
  • Learn
    • What is a Scamp?
    • Order a Scamp
    • Getting Started
    • Learning Forth ... >
      • What is Forth?
      • Arithmetic
      • The Stack
      • Creating Words
      • Compilation Tricks
      • Comments
      • Characters and Strings
      • Constants, Variables and Values
      • Flow Control
      • Loops
      • Accessing Memory
      • Data Structures
      • Doubles, Triples and Quads
    • Extras... >
      • Starting up with turnkey
      • Formatting Text on Screen
      • Changing the Prompt
      • Delays and Tick Count
      • Processor Words
      • Cryptography Engine
      • Temperature Sensor
      • Using the LED Array
    • Interfacing... >
      • Input/Output
      • Analog Input
      • Serial Communication
      • PWM
      • I2C Overview
      • I2C Commands
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Create
    • Adding LEDs
    • LED arc-welder effect
    • Measuring Temperature
    • Time Keeping
    • Model Train Control
    • FizzBuzz
    • Adding Extra GPIO
    • Adding a Low Side Switch
    • Adding an RTCC
  • Resources
  • Consult
  • About
  • Contact

Setting a Delay
​

The word ms will wait for n milliseconds before continuing, up to a maximum of 65,535 milliseconds. For example, to turn the LED on, wait for 2 seconds, then turn the LED off:
​ledon 2000 ms ledoff

Measuring Intervals
​

The word ticks will place a 16-bit count in milliseconds onto the stack. The tick count rolls over to zero every 65,535 milliseconds (65.535 seconds). ticks can be useful in determining how long your code takes to execute. For example, we can determine how long blink takes to execute by using ticks to place its count on the stack before and after blink, then subtract the second count from the first to determine the delay:
​ticks blink ticks – abs .
As it is possible for the tick counter to roll through zero between the two calls of ticks, giving a negative result from the subtraction, we use the word abs (absolute) to convert the result of the subtraction to an absolute value. 

Note that there will be an extra few milliseconds due to the overhead of word execution. For example:
​ticks 500 ms ticks – abs . 
gives an output of 504 milliseconds or so, rather than 500 milliseconds. This is the (small) overhead associated with calling the words ms and ticks.  

Site powered by Weebly. Managed by Hostwinds
  • Learn
    • What is a Scamp?
    • Order a Scamp
    • Getting Started
    • Learning Forth ... >
      • What is Forth?
      • Arithmetic
      • The Stack
      • Creating Words
      • Compilation Tricks
      • Comments
      • Characters and Strings
      • Constants, Variables and Values
      • Flow Control
      • Loops
      • Accessing Memory
      • Data Structures
      • Doubles, Triples and Quads
    • Extras... >
      • Starting up with turnkey
      • Formatting Text on Screen
      • Changing the Prompt
      • Delays and Tick Count
      • Processor Words
      • Cryptography Engine
      • Temperature Sensor
      • Using the LED Array
    • Interfacing... >
      • Input/Output
      • Analog Input
      • Serial Communication
      • PWM
      • I2C Overview
      • I2C Commands
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Create
    • Adding LEDs
    • LED arc-welder effect
    • Measuring Temperature
    • Time Keeping
    • Model Train Control
    • FizzBuzz
    • Adding Extra GPIO
    • Adding a Low Side Switch
    • Adding an RTCC
  • Resources
  • Consult
  • About
  • Contact