## Random Number Generator

The PIC24 processor used in your Udamonic computer has a hardware Random Number Generator (RNG). This is a true random number, not a software-generated pseudo-random number.

The word

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.## Cyclic Redundancy Check

The PIC24 processor in your Udamonic computer incorporates an inbuilt CRC engine in hardware. To understand the details of this CRC engine, please refer to the Microchip application note AN1148, and Section 30 of the PIC24F Reference Manual, Programmable Cyclic Redundancy Check.

After a reset or powerup, the CRC engine is off by default. The word

The word

The CRC engine can be configured for polynomials of up to the 32nd order, using up to 32 bits. The word

For example, a bit pattern of

The word

**crcon**enables the CRC engine, whilst the word**crcoff**disables it.**crcon**must be run before the CRC engine can used. Turning off the CRC engine is optional.The word

**crc!**takes two 16-bit numbers from the stack and preloads the CRC engine with these initial values. Refer to Section 30 of the PIC24F Reference Manual, Programmable Cyclic Redundancy Check (subsection 5.5.3) for more information about the CRC initial value.The CRC engine can be configured for polynomials of up to the 32nd order, using up to 32 bits. The word

**coeff**takes two 16-bit values from the stack, the bit patterns of which will enable or disable each coefficient. A set bit will enable a particular coefficient, whilst a cleared bit will disable that coefficient.For example, a bit pattern of

**%****0000010011000001 %000111011011011x**results in the following coefficients used in the CRC polynomial: X26 + X23 + X22 + X16 + X12 + X11 + X10 + X8 + X7 + X5 + X4 + X2 + X + 1. Bit 0 of the polynomial is always included, and therefore the LSB ignored.The word

**crc16**performs a 16-bit CRC. It takes a starting*address*and a*count*from the stack, and returns the CRC result to the stack. Note that the count is the number of 16-bit values, not the number of bytes.For example, let's say we want to calculate a 16-bit CRC with polynomial coefficients X16 + X12 + X5 + 1, giving a coefficient bit pattern of

**%0000000000000001 0001000000100000**, or**$0001 $1020**in hex. (The least significant bit of the coefficient pattern is ignored, as bit 0 is*always*included in the polynomial.) To begin, load the coefficient bit pattern, preload the CRC registers with initial values (in this case with**0 0**), then we turn on the CRC engine, perform the CRC, then turn the engine off. In this example, we perform the CRC on 30 16-bit values starting at the**pad**address:$0001 $1020 coeff \ load the coefficients

0 0 crc! \ load the initial values

crcon \ turn on CRC engine

pad 30 crc16 \ address count crc16

crcoff \ turn off CRC engine