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:
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.
Note that random is not available on the Scamp2e.
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:
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.
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.
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.
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:
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 |
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:
The following word disables REFO on pin 9, and restores normal functionality to pin 9:
: REFOoff
$8100 $168 !
;