User's Manual
PMAC Dual-Ported RAM User Manual
Dual-Ported RAM Communications 9
M130->D:$28 ;motor #1 actual position
M131->DP:$D000 ;point to a location in DPRAM
OPEN PLC 1 CLEAR
M131=M130/(I108*32) ;update motor position (in counts) in DPRAM
CLOSE
I5=2 ; allow PLC 1 to be enabled
ENABLE PLC 1 ; “turn on” PLC 1
Now, read the location corresponding to M131 ($D000 in PMAC's memory) in PC memory and extract
this position information so that the C program can use it. The corresponding address in PC memory can
easily be determined by talking the address location in PMAC’s memory minus the starting address
(always $D000), multiply by 4 (because the X and Y words for each location in PMAC’s DPRAM space
is equivalent to four bytes or locations of PC memory) and add it to the PC memory starting address
selected for the DPRAM.
PC Location = ((PMAC Mem. Location (hex)- $D000)
×
4) + (PC Mem Starting Address selected for DPRAM)
Assume we configured DPRAM to start at PC address $D4000. We want the equivalent PC address
location for PMAC location $D200. This would be:
Hex: ($D200 -$D000)
× 4 + $D4000 = $D4800
Decimal: (53760 - 53248)
× 4 + 868352 = 870400
Our C code now only has to PEEK location $D4800 and $D4802 (since we need to get four bytes to get a
32 bit word) to obtain motor #1’s current position. The C code subroutine may look like this.
long get_motor_position (){
int hi_word;
unsigned lo_word;
lo_word = peek (0xD400, 0x0800);
hi_word = peek (0xD400, 0x0802);
return (hi_word *65536 +lo_word);
Example #2: To calculate positions for three axes in a custom C program and have PMAC move to these
positions. Assign three M-variables to point to three DPRAM locations, write position values to these
locations with the C program, and have a PMAC motion program use these variables in its move
statements. In the sample code below, a flag bit has been used to signal the C program when the data has
been taken by PMAC so the next move locations can be loaded.
M101->DP:$D201 ; used for motor x’s commanded position
M102->DP:$D202 ; used for motor x’s commanded position
M103->DP:$D100 ; used for motor x’s commanded position
M100->DP:$D200,0 ; go flag to stop motion program
M104->DP:$D200,1 ; flag to stop C program when positions have
; been received
OPEN PROG 1 CLEAR
TA10
WHILE(M100=1) ;keep looking while go flag is 1
X(M101) Y(M102) Z(M103) ;move x,y,z to new positions
ENDWHILE
CLOSE
The C program calculates the positions, and would send them to PMAC via a subroutine like this:
void update_positions (longx, long y, long z, int stop_program)
{
static long far *x, *y, *z;
x = MK_FP (0xD400, 0x0804);
y = MK_FP (0xD400, 0x0808);
z = MK_FP (0xD400, 0x080C);