Slacken
I am trying to figure out how to control a servo motor withs pwm range of 1ms-2ms. Is there a way to generate pulses that fast, i cannot seem to make an arduino uno with open plc consider frequencies so high with ton and tof blocks. Or some other way to control servo motors. thx
Reply 0 0
Slacken
Just found out Pwm block exsists now wondering how to intergrate it into the program correctly, such as doing i just use variables, for duty do i use % somewhere in the text what to do with channel and success?
Reply 0 0
thiagoralves
You don’t have to use any % variable. Just configure the block with numbers according to your needs. The first input is the channel number. Each platform has different amount of channels, but they all start from zero. On a Uno, the channels are the PWM capable pins. Then you fill your the frequency and duty cycle according to your needs as well with variables or constants (plain numbers)
Reply 0 0
Slacken
so it references a pwm pin i noticed some have different frequencies will they differ in their effect? As for output which i assume is from success is that to any output coil?
Reply 0 0
Slacken
image.jpgthis is my understanding of plain numbers but it saids the data type is incompatible?
Reply 0 0
thiagoralves
You gotta put something in the channel input. Freq and duty are REAL values, so you should use 50.0 and 10.0. Success is a Boolean value that tells you that the block worked.
Reply 1 0
Slacken
Can you specify what needs to go in the channel input because it doesn't like having a variable which i was thinking would be tied one of the input analog pins that emits pwm. Also should there be an output coil attached to success that is related to an analog output pin that will connect directly then to the motor itself?
 
[203128%2F9420449%2Fmceclip0]
Reply 0 0
thiagoralves
Can you specify what needs to go in the channel input because it doesn't like having a variable which i was thinking would be tied one of the input analog pins that emits pwm.
As I said on my earlier post: You don’t have to use any % variable. The first input is the channel number. The Arduino Uno for example has 2 channels: 0 and 1, tied to pins 9 and 10 on the Arduino Uno. If you put 0 on the channel input, the PWM block will activate PWM on channel 0, which is tied to pin 9 on the Arduino Uno board.
Also should there be an output coil attached to success that is related to an analog output pin that will connect directly then to the motor itself
No. As I mentioned in my earlier post:
Success is a Boolean value that tells you that the block worked. If you put a channel number that does not exist, or a frequency that is too high or too low for the board, or a duty cycle different than 0-100, then success will be FALSE. Otherwise, if the instruction worked, it will activate PWM on the channel you specified, and success will be TRUE. You need to connect the motor to the channel you specified at the block input. If you put channel 0 on the PWM block programming an Arduino Uno, then you connect the motor to pin 9 on the Arduino Uno, which is the PWM channel 0 of this board.
Reply 0 0
Slacken
I have made the changes to the program and it now runs with no issues indicated within the editor debug. I notice success is not lit but i assume this is not activated but i assume this just because its just in the editor.
[203128%2F9423739%2Fmceclip0]
But when i try to burn the program to the arduino board it fails. I have copied it onto a completely new file yet this problem persists, i can still upload other plc programs i have made with no changes to before.
[203128%2F9423738%2Fmceclip0]
Reply 0 0
thiagoralves
This whole discussion was based on the Uno, not Uno R4. This code will not work on the Uno R4 because it uses a completely different chip than the regular Uno. The PWM_CONTROLLER block was not implemented for the Uno R4 platform.
Reply 0 0
Slacken
Is there any possibility of an update to the software in future for open plc to make this capable or is it purely a hardware limitation? In other words get another board?
Reply 0 0
thiagoralves
Your best bet is to use an Arduino Extension (grey plus icon on the left panel) to write your motor control code directly. You can use PWM.h library for the Uno R4 board that seems to work great. There are several Arduino Extension examples on the file->examples menu for you to check out.
Reply 0 0
Slacken
I think this coding option is quite beyond what I am willing to understand right now, would the UNO R3 be a useable for a totally ladder logic programmed controller that i wrote earlier?
Reply 0 0
thiagoralves
Mega is a better option as the Uno R3 is very short on RAM (it only has 2KB)
Reply 0 0
thiagoralves
OpenPLC installs the boards when you use them. There is no block for encoder reading. Reading that with just ladder logic will most likely make you miss pulses, as ladder is not interrupt driven. For things like that (reading encoders, controlling servos) you need dedicated hardware. Arduino boards can work if you know how to program in C, as a low level language allows you to make good use of the hardware. Any layer of abstraction (like a PLC runtime) takes you too far away from the hardware, which makes it much more difficult to do tasks like these. The PWM_CONTROLLER block works because it was written in C. But as you saw yourself, a low level language is too dependent on the hardware. The block works on the Uno R3 but does not work on the Uno R4. In other words, building a project like this using only ladder, you’d be better off using a brand PLC that has dedicated hardware modules to read encoders and control servos. P1AM is a great platform that works with OpenPLC and might be able to do what you want.
Reply 1 0
Reply