alejandrojginerd Posted January 18 Share Posted January 18 Good day, I am trying to understand how to read and write values to the GPIO port on my AX1515N (CK3M) however, the documentation avaiable hasnt helped much on this regard. For learning pourpuses, could you provide an code example that follows the folowing pseudocode: void user_plcc() { input = IN_00; // read the state of IN00 (LOW = 0V, HIGH = 24V) if (input == LOW) // blinck output 0 every 1000 ticks { static int i = 0; if(i > 1000) { OUT_00 = HIGH; } else { OUT_00 = LOW; } i = i %2000; } } I have tried somethin of the sorts but i dont get any measurable results. #define OutputData(x) (x << 16) void user_plcc() { volatile GateArray3 *MyGate3IO; MyGate3IO = GetGate3MemPtr(0); static int i = 0; if(i++ > 1000) { MyGate3IO->GpioData[0] = OutputData(0xAAAA); } else { MyGate3IO->GpioData[0] = OutputData(0x5555); } i = i %2000; } Quote Link to comment Share on other sites More sharing options...
leandro.martins Posted January 18 Share Posted January 18 I couldn't spot any kind of error in your code. What is the behaviour that you are obtaining? Quote Link to comment Share on other sites More sharing options...
alejandrojginerd Posted January 20 Author Share Posted January 20 I measured the voltage at the Output pins and all presented 0V. Even pins 9, 27 and 18 wich, to my undertanding are allways "HIGH". Is something wrong on my understanding of the hardware? Quote Link to comment Share on other sites More sharing options...
DaveBarnett Posted January 20 Share Posted January 20 These I/O, being optically isolated, need external bias (typically 24VDC ) for current to flow. See: But, even without the 24v connected, you should see the individual led channel status indicators respond when your code changes the OUTPUTS, no ?? Quote Link to comment Share on other sites More sharing options...
alejandrojginerd Posted January 22 Author Share Posted January 22 If you mean the LEDs on top og the GPIO port, no, they dont lit up when the bgcplc is running. I have tried both with and without the external 24V power source on two systems and always get the same behaviour. Is there something i have to configure in order to use the GPIO port? Quote Link to comment Share on other sites More sharing options...
DaveBarnett Posted January 22 Share Posted January 22 Have you enabled your plc with: UserAlgo.BgCplc[0] = 1 ? Also, by default, You should be able to type in the terminal: Gate3[0].GpioData[0] = 0 // outputs off Gate3[0].GpioData[0] = $10000 //Output 1 ON Gate3[0].GpioDir[0] = $ffff0000 // this should be the default 1 Quote Link to comment Share on other sites More sharing options...
Alex Anikstein Posted January 22 Share Posted January 22 I'd agree with Dave--I always try to split my troubleshooting for stuff like this into pieces. Rather than using a C PLC, which brings with it it's own set of questions (Did it generate an error on build and I didn't notice? Is it actually enabled? Are the pointers correct? Etc.), start basic. -If you issue the specific command to turn an output on through the terminal window, does the LED indicator turn on? -Can you turn them all on (GpioData[0] = $FFFF0000)? -After that, can you turn them off? As he noted in the previous post, 9/18/27 are inputs--you'll need to bring in the reference voltage into those pins. If you see the LEDs toggle, but aren't seeing your devices toggle, that's a likely cause. Finally, I'd check if your code was loaded properly and actually running. Quote Link to comment Share on other sites More sharing options...
alejandrojginerd Posted January 24 Author Share Posted January 24 After some further checking, I found out that I hadn't configured GPIODir. After adding the change to the start.txt file, everything works. Thanks for the support Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.