udamonic.com
  • Start
    • What is a Scamp?
    • Getting Started
    • Getting Started (Windows)
  • Learn
    • What is Forth?
    • Arithmetic
    • The Stack
    • Creating Words
    • Compilation Tricks
    • Decompilation
    • Comments
    • Characters and Strings
    • Accessing Memory
    • Constants, Variables and Values
    • Flow Control
    • Loops
    • Data Structures
    • Doubles, Triples and Quads
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Extras
    • Interrupts
    • Timers
    • Multitasking
    • Delays and Tick Count
    • Processor Words
    • Starting up with turnkey
    • Changing the Prompt
    • Formatting Text on Screen
  • Interfacing
    • Using the LED Array
    • Temperature Sensor
    • Input/Output
    • Analog Input
    • Serial >
      • Serial Communication
      • Scamp Serial Comms
      • Scamp2 UART Pins
    • I2C >
      • I2C Overview
      • I2C Commands
    • SPI
    • PWM
    • Peripheral Pin Select
    • Input Capture
    • Digital Signal Modulator
    • DataFlash
    • RS485
  • Create
    • Scamp Projects on Youtube
    • Prototyping >
      • Protoboards
      • Fabricating PCBs
      • Soldering
    • GPIO >
      • Adding Extra GPIO
      • 32-bit GPIO Module
      • Adding a Low Side Switch
    • Sensing >
      • Measuring Temperature
    • LEDs >
      • Adding LEDs
      • LED arc-welder effect
    • Memory >
      • Adding MRAM
      • AT24C256 EPROM Driver
    • Displays >
      • Adding a 7 Segment Display
      • Adding a Touch LCD
      • Touch LCD GUI
      • Game of Pong
    • FizzBuzz
    • Model Train Control
    • Adding a Real Time Clock
    • 1-D Pacman
  • Resources
  • Buy
  • Consulting
  • About

Random Number Generator
​

Picture
The PIC24 processor used in Scamp3/3e has a hardware Random Number Generator (RNG). This generates a true random number, not a software-generated pseudo-random number.
​
The word random and places a 16-bit random number onto the stack. For example:
random
For a 32-bit random number, call random twice.

Note that random is not available on the Scamp2e.

Device ID
​

Picture
The Microchip processor used in your Scamp has a Device ID register. This can be used by your software to determine the particular type of processor your code is running on, and also the silicon revision of that part.

The word devID and places onto the stack the processor's family/device code, and the revision number. For example:
hex
​​devID .s
gives the (hex) result 4c58 4. The 4c indicates that the device family is the PIC24FJ128GB204 family. 58 is a PIC24FJ64GB202 processor within that family. The silicon revision is 4. 

Processor Oscillator Frequency
​

Picture
The word Fcy will place the frequency (in kiloHertz) of the processor's primary oscillator onto the stack. This is an unsigned 16-bit value. 

On the Scamp3 (only), the 16 MHz system clock is available on the main connector (label <CLK) as a reference, or for use as a clock source to external peripherals. ​

Reference Oscillator
​

Picture
There is a 32 MHz reference oscillator that is available internally as an input to onboard peripheral modules (such as the DSM Module). The Scamp3 word oscdiv takes a 16-bit value from stack, disables the oscillator momentarily, writes the divisor value to the appropriate register, and then re-enables the oscillator. A value of 0 gives a 32 MHz reference, 1 gives a 16 MHz reference, 2 gives an 8 MHz reference and so on, up to $ffff which gives a 490 Hz reference. 

For example, to set the frequency to 160 kHz:
#100 oscdiv
The reference oscillator output (REFO) can be output on pin 9 (only) on the Scamp3 and Scamp3e with the following word:
​: REFOon
  $9100 $168 !
;
Note that the reference oscillator output on pin 9 will override all other functionality for pin 9. 
The output on pin 9 by REFO is a sine wave, not digital.
The following word disables REFO on pin 9, and restores normal functionality to pin 9:
​: REFOoff
  $8100 $168 !
;

Learn : Extras : Processor Words
Site powered by Weebly. Managed by Hostwinds
  • Start
    • What is a Scamp?
    • Getting Started
    • Getting Started (Windows)
  • Learn
    • What is Forth?
    • Arithmetic
    • The Stack
    • Creating Words
    • Compilation Tricks
    • Decompilation
    • Comments
    • Characters and Strings
    • Accessing Memory
    • Constants, Variables and Values
    • Flow Control
    • Loops
    • Data Structures
    • Doubles, Triples and Quads
    • FlashForth Dictionary Reference
    • Scamp Dictionary Reference
  • Extras
    • Interrupts
    • Timers
    • Multitasking
    • Delays and Tick Count
    • Processor Words
    • Starting up with turnkey
    • Changing the Prompt
    • Formatting Text on Screen
  • Interfacing
    • Using the LED Array
    • Temperature Sensor
    • Input/Output
    • Analog Input
    • Serial >
      • Serial Communication
      • Scamp Serial Comms
      • Scamp2 UART Pins
    • I2C >
      • I2C Overview
      • I2C Commands
    • SPI
    • PWM
    • Peripheral Pin Select
    • Input Capture
    • Digital Signal Modulator
    • DataFlash
    • RS485
  • Create
    • Scamp Projects on Youtube
    • Prototyping >
      • Protoboards
      • Fabricating PCBs
      • Soldering
    • GPIO >
      • Adding Extra GPIO
      • 32-bit GPIO Module
      • Adding a Low Side Switch
    • Sensing >
      • Measuring Temperature
    • LEDs >
      • Adding LEDs
      • LED arc-welder effect
    • Memory >
      • Adding MRAM
      • AT24C256 EPROM Driver
    • Displays >
      • Adding a 7 Segment Display
      • Adding a Touch LCD
      • Touch LCD GUI
      • Game of Pong
    • FizzBuzz
    • Model Train Control
    • Adding a Real Time Clock
    • 1-D Pacman
  • Resources
  • Buy
  • Consulting
  • About