1) Your code will not work
1.2) it has multiple destructive writes to Boolean accelmotor, which is usually a mistake.
1.2.2) Rung 3 will write a 0 to accelmotor on the scan cycle immediately
after it writes the 1 to when xmotron is 1 (button pressed?). So the timer on Rung 4 will never expire.
1.2.3) the xaxisspeed increment is before the timer, so even if Rung 4 executed for multiple scan cycles, it would increment xaxisspeed on every scan cycle instead of at 1ms intervals.
1.2.3) There is no more than one rising edge to the CTU to increment its value, and it is not tied to xaxisspeed, so even accelmotor was 1 for more than one consecutive scan cycle, the CTU would never complete.
2) The ENO of the PWM instruction is not the PWM output, so everything to the right of the PWM instruction on Rung 2 is not going to work.
2.1) The PWM controls _IO_EM_DO_06 directly; the program does not need a Coil to write to it.
2.1) See this youtube by @Tim Wilborne for handling the prox and direction inputs.
2.2) If the frequency and duty input parameters to the PWM instruction are "frequently" changing while the Enable rung into the PWM instruction is True, the PWM output channel _IO_EM_DO_06 stays off.
2.2.1) I did an experiment where the frequency and duty were derived from an analog input, and the noise (over time) in the analog input kept the PWM instruction from driving the PWM output channel. I had to toggle the enable on then off to get the PWM to follow the updated parameters. I don't know
- the quantitative value for "frequently"
- if this is an issue if only the Freq or only the DutyCycle are being updated "frequently" over time.
The image attached below is an alternate approach that might work; it uses the canonical Start/Stop Circuit pattern (see here
https://www.contactandcoil.com/patterns-of-ladder-logic-programming/startstop-circuit/). The code to handle the direction and prox inputs will need to be added; see the video mentioned above.