Vlak
Hi all, I have a question about controlling a stepper motor via a PWM control output. I've tried it with a digital output and can't get it to run smoothly with a pulse train.
 
Just the basics I use: An Arduino Mega with a stepper driver CL57Y with which a closed loop motor is controlled, a Nema 23.
 
I'm using OpenPLC in Ladder for the program. I've found the PWM block, but that's about it for now. Can someone send me an example of how to control and use it?
I've connected the driver's pulse input to port 2 of the Arduino, and I'm also using a port for direction and enable.
What should I connect to the legs of the block and where should the PWM output, and therefore the driver, be located?
 
 
[203128%2F9670260%2Fmceclip0]
Reply 0 0
thiagoralves
PWM_CONTROLLER generates a PWM wave. It is not appropriate for stepper motor control. Your best bet will be to use an Arduino library for stepper motor on an Arduino Extension in your OpenPLC v3 project.
Reply 0 0
Vlak
I don't control the motor directly, but through a driver. Is that still not possible?
 
Or should I better control the driver differently?
 
Just a quick question. I was installing my new laptop tonight, including the new 4.1 editor. Can I convert the programs written in the old editor?
Reply 0 0
thiagoralves
Using a driver you might be able to use a PWM CONTROLLER block. Just keep in mind that all this block does is generate pulses of a giving frequency and duty cycle. Once you set the channel, frequency and duty, it starts generating pulses on the channel you specified and will only stop if you set duty or frequency to zero. Number of channels vary depending on the platform and are tied to PWM-capable pins, where channel 0 is the first PWM-capable pin.
Reply 0 0
Gloworm72
PWM_CONTROLLER generates a PWM wave. It is not appropriate for stepper motor control. Your best bet will be to use an Arduino library for stepper motor on an Arduino Extension in your OpenPLC v3 project.
Is there an Arduino Extension file equivalent on OpenPLC V4? Or if we need that then we should stick with V3?
Reply 0 0
thiagoralves
Yes. Click on blue + button -> Function Block -> Language C/C++
Reply 0 0
Gloworm72
Yes. Click on blue + button -> Function Block -> Language C/C++
Ok thank you! I'm still learning what the difference between functions and function blocks are but does that mean the Arduino extension file on openPLC v3 is technically acting as a function block since it maintains variable values over each cycle?
Reply 0 0
thiagoralves
Arduino Extension on the previous v3 editor was a hack. It injected code on the runtime with the user code an had no notion of Function or Function Block. C/C++ Function Blocks are true Function Blocks just like any other in the PLC project
Reply 0 0
Reply