abhinaykdn1
How do we declare the pwm output in the editor, what is it's datatype ?
Please if I could get any sample program.
Reply 0 0
thiagoralves
Check this: https://openplc.discussion.community/post/analog-input-and-output-samples-8279198?highlight=pwm
Reply 0 0
abhinaykdn1
I need to feed PWM input into to the PID program using softPWM library  of wiringPi and obtain the analog output at the pwm pin %QW0. I am facing problem in feeding the pwm input(which I guess is of boolean type) to the setpoint of PID which I guess receives only Real value. Please help
Reply 0 0
thiagoralves
abhinaykdn1 wrote:
I need to feed PWM input into to the PID program using softPWM library

The softPWM library is used to generate a PWM output on a regular GPIO pin on the Raspberry Pi. You can't use it to read a PWM signal. Furthermore, to be able to use this library with OpenPLC, you would have to modify the OpenPLC hardware driver for the Raspberry Pi platform. 

To be able to read a PWM signal you will need a board with an analog input (which the Raspberry Pi lacks) and the proper analog filters to convert the pulse modulation into an analog voltage. (See http://www.allegromicro.com/en/Design-Center/Technical-Documents/Hall-Effect-Sensor-IC-Publications/Method-for-Converting-a-PWM-Output-to-an-Analog-Output-When-Using-Hall-Effect-Sensor-ICs.aspx). For a very crude conversion, just a resistor in series and a capacitor in parallel would do. But then you would need to feed this analog voltage to an analog input to be able to read it. If you wanna play cheap, Arduino boards have plenty of analog inputs, and it works fine with OpenPLC when paired with a Raspberry Pi (instructions: http://www.openplcproject.com/getting-started-arduino)

abhinaykdn1 wrote:
I am facing problem in feeding the pwm input(which I guess is of boolean type) to the setpoint of PID which I guess receives only Real value.

Once you have your analog input ready, OpenPLC reads analog inputs in %IW0, %IW1, %IW2,... and those are 16-bit unsigned integer variables. What engineers usually do is to convert this integer number into a real world quantity before feeding it into the PID block based on what you are reading. For example, if you're reading temperature, it is wise to convert the integer number read into temperature in Celsius or Fahrenheit, and that will be a REAL value. In any case, you can use one of the provided conversion blocks to directly convert between the 16-bit integer into a real value.
Reply 0 0
Reply