Store PLCnext CommunityPLCnext on LinkedInPLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

  1. Martin PLCnext Team
  2. PLCnext Technology & PLCnext Controls
  3. Friday, 16 February 2018

I have a customer who wants to drive a servo motor using a Pulse Width Modulated (PWM) signal.

I have suggested one of our InLine PWM modules, but the discussion on this forum about real-time threads has got me thinking ... would it be possible to write a C++ program for PLCnext, which:

  • Runs under the ESM.
  • Takes a 'position' setpoint from the PLC program via a GDS port.
  • Uses a real-time thread to generate a pulse on an Axioline digital output at a frequency suitable for PWM control of the servo.

A separate real-time thread would be needed because the ESM will only execute the C++ program on a cycle time down to 1 ms (or maybe 500 μs?), but this is too slow for a PWM signal with the necessary resolution - in this case the PWM pulse tops must have a width between 900 μs and 2100 μs.

What do people think?

First question: Would the C++ program need to access the Axioline output directly, or would writing the PWM output signal via a GDS port be fast enough?

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
Vincent PLCnext Team Accepted Answer Pending Moderation

Hi Martin, 


I guess this would be possible, however as you doing a lot of comms on the GDS (writing port state), you kind-of abuse that mechanism, as every cycle (0.5ms), you latch the pin-state to the IO device, going through all the layers of synchronization.

Also keep in mind that although you run your program at 1khz (to make it easier to reason, cloud be a tad faster), the time you flip the pin. The sample-resolution from your control-loop is much lower, if you don't want to introduce aliasing effects.


E.G. If you wanted to have a PWM dutycycle between 0 - 100% (with 1-step interval), and you run your task at 1ms (so 1khz pin-toggle). Your effective PWM update speed is 100ms. So that would be the maximumum obtainable update-cylcle form your program, using the pin speed.


Also i'm not sure what the fastest setting of the DI8/DO8 module is, but probably fast enough.


To date the only way to gain access to the IO systems it though the GDS, so you will be bound to that mechanism for now. I guess a more 'nice' way to implement something like this would be either implement a high-speed bitbang functionality as a fieldbus, or use the PWM inline module, to offload the high-speed.

<p>Phoenix Contact Netherlands - Technical Consultant</p>
  • Page :
  • 1

There are no replies made for this post yet.
However, you are not allowed to reply to this post.