Positron Compiler Documentation

Creating variables in DMA RAM

Source: Positron16 Compiler User Manual, PDF page 443

Some PIC24® and dsPIC33® devices have an extra area of RAM dedicated to DMA (Direct Memory Access) operations. It resides at the top of the X RAM area, above any Y RAM, and is named DMA RAM. All DMA operations must use DMA RAM, otherwise the microcontroller will create an exception.

Adding the text DMA at the end of a variable's declaration will cause it to be created in the DMA RAM section:

Dim MyArray[10] As Word DMA = 1, 2, 3, 4, 5, 6, 7

Each device has differing amounts of DMA RAM, if any, so the compiler will produce an error message if the limit is exceeded.

Notes.

The final RAM usage will also encompass the microcontroller’s stack size, therefore, even if the BASIC program only declares 4 byte variables, the final RAM count will be 84. 80 bytes for the default stack size and 4 bytes for variable usage. If handled interrupts are used, the stack size will increase due to context saving and restoring requirements.

RAM locations for variables is allocated automatically within the microcontroller because the PIC24® and dsPIC33® range of devices have specific requirements concerning RAM addressing. Which are:

16-bit variables must be located on a 16-bit RAM address boundary. 32-bit and 64-bit variables must be placed on a 16-bit address boundary, but should be placed on a 32-bit address, if possible, for more efficiency with some mnemonics. 8-bit variables can be located on an 8-bit,16-bit or 32-bit RAM address boundary.

Therefore, the order of variable placements is:

The microcontroller's 16-bit stack is located before all variables are placed. The compiler's 16-bit system variables are placed. Word variables are placed. Dword variables are placed. Float variables are placed. Double variables are placed. Byte and Pin variables are placed. Word Arrays are placed. Dword Arrays are placed. Float Arrays are placed. Byte Arrays are placed. String variables are placed.

The logic behind the variable placements is because of the microcontroller’s near and far RAM.

The first 8192 bytes of RAM are considered "near" RAM, while space above that is considered "far" RAM. By default, the compiler sets all user variables to near RAM. However, when near RAM space is full, the compiler will place variables in far RAM (above 8192).

The special significance of near versus far to the compiler is that near RAM accesses are encoded in only one mnemonic using direct addressing, while accesses to variables in far RAM require two to three mnemonics using indirect addressing. Standard variables are used more commonly within a BASIC program, therefore should reside in near RAM for efficiency. Arrays and Strings are generally accessed indirectly anyway, therefore, it is of little consequence if they reside in near or far RAM.

See Also : Aliases, Declaring Arrays, FloatIng Point Math, Symbol,

Creating and using Strings .