Jump to content
OMRON Forums

Accessing IO Locations with ACC-11E


Recommended Posts

I tried to access the inputs to ACC-11E in a CPLC with this simple code: #include #include #include void user_plcc() { int *Input1, *Output1; Input1 = (int *)(((int *)piom) + 0xA00000 + 8); //Input Pin 1 Output1 = (int *)(((int *)piom) + 0xA0000C + 8); //Output Pin 1 if (*Input1) // If input 1 is high { *Output1 = 1; // Light output 1 LED } else { *Output1 = 0; // Deactivate output 1 LED } return; } However, when I read the Input1 location using the Send() command, its value is always 0, even when I activate the switch, and the LED does not activate ever. Am I getting the address of the ACC-11E IO memory locations incorrect? I am basing them off of the M variables suggested for these locations: M6001->u.io:$A00000.8.1 // Input 1 M8001->u.io:$A0000C.8.1 // Output 1 Is there an additional offset I need to add to the Input1 pointer in order to get the right address for the IO location? Thank you!
Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

There are many problems with the above code. First of all, the memory address to which one points needs to be divided by 4 because of how Power PMAC reads memory addresses; i.e., it reads them as whole 32-bit words, so one must divide by 4 to get the correct offset from the base I/O memory pointer (piom). Furthermore, one cannot add individual bits to the address, but rather one must look at the base address and then mask and shift bits in the whole word in order to access the correct bits desired. Lastly, the pointer to the I/O locations must be a volatile unsigned int, not just a normal int, to correctly read the addresses. Corrected code would appear as such: #include #include #include void user_plcc() { volatile unsigned int *Input1, *Output1; unsigned int Input1Val; Input1 = (piom + 0xA00000/4 ); //Input Pin 1 Output1 = (piom + 0xA0000C/4); //Output Pin 1 Input1Val = (*Input1 & 256) >> 8; // Read Input 1 Pin's memory location, mask out all bits other than the 8th bit we want to be high, then shift right 8 if (Input1Val) // If input 1 is high { *Output1 = (1 << 8) & 256; // Light output 1 LED by shifting the value of 1 left 8 bits, masking out all bits other than the 8th bit, then writing to Output 1 Pin's memory location } else { *Output1 = 0; // Deactivate output 1 LED } return; }
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share


×
×
  • Create New...