steveneads Posted December 19, 2019 Share Posted December 19, 2019 What is the best way to do the equivalent of "trunc" in code that runs in the kernel? Link to comment Share on other sites More sharing options...
Omron Forums Support Posted December 19, 2019 Share Posted December 19, 2019 Do you mean C code or PMAC Script? Link to comment Share on other sites More sharing options...
Omron Forums Support Posted December 20, 2019 Share Posted December 20, 2019 In the script environment, you can use "ceil" to round up and "floor" to round down. Link to comment Share on other sites More sharing options...
steveneads Posted December 20, 2019 Author Share Posted December 20, 2019 I am trying to use it in C code that is included with usrcode.c Link to comment Share on other sites More sharing options...
Omron Forums Support Posted January 3, 2020 Share Posted January 3, 2020 In C we also have the functions "floor" and "ceil". Below is a bgcplc 0 I used to test this. void user_plcc() { pshm->P[0]=floor(9.3); pshm->P[1]=floor(9.7); pshm->P[2]=ceil(9.3); pshm->P[3]=ceil(9.7); pshm->UserAlgo.BgCplc[0]=0; } Link to comment Share on other sites More sharing options...
steve.milici Posted January 3, 2020 Share Posted January 3, 2020 In C we also have the functions "floor" and "ceil". Below is a bgcplc 0 I used to test this. void user_plcc() { pshm->P[0]=floor(9.3); pshm->P[1]=floor(9.7); pshm->P[2]=ceil(9.3); pshm->P[3]=ceil(9.7); pshm->UserAlgo.BgCplc[0]=0; } Just don't use it in CaptCompISR(). Link to comment Share on other sites More sharing options...
steveneads Posted January 7, 2020 Author Share Posted January 7, 2020 Thank you - I've made it work using "floor" with some logic to adjust the result for negative inputs (as I wanted to round towards zero). Is there an easy way to find a list of C functions that are and are not supported in the Kernel C code? Link to comment Share on other sites More sharing options...
Recommended Posts