0

I am trying to simulate a PWM signal output from a digital only PLC. So is it possible to define the digital output pin ON and OFF time in each cycle?

Thanks in advance.

1 Answers1

1

Most plcs with transistor outputs have a pulse generator that you can use. For example on a Schneider PLC you can use the PTO (pulse train output). If for example you were using the signal to move a motor you can define what speed is equivalent to the frequency of the pulses then in the code you can define a velocity to move

VAR
 MC_MoveVelocity_PTO_0: MC_MoveVelocity_PTO;    
 Powerd: MC_Power_PTO;  
 mcPositive: MC_DIRECTION;
END_VAR

//enable pulse train output
Powerd(Axis:=PTO_0,Enable:=TRUE,DriveReady:=TRUE);
//command 
MC_MoveVelocity_PTO_0(Axis:=PTO_0,Execute:=%IX1.1,ContinuousUpdate:=TRUE,Velocity:=100,Acceleration:=1000,Deceleration:=1000,Direction:=mcPositive);

This code should run every cycle so you don't need to update the ON and OFF time each cycle. You could adjust the Velocity it runs at each cycle if you really wanted to.

Or if you wanted to get really basic you could use a timer to turn ON and OFF your output.

VAR
 PWM_Timer: BLINK;
 DigitalOutput: BOOL;
 offTime: TIME := t#10ms;
 onTime: TIME:=t#10ms;
END_VAR

PWM_Timer(ENABLE:=TRUE , TIMELOW:=offTime , TIMEHIGH:=onTime , OUT=>DigitalOutput );

where the timer I used specifies the ON and OFF time that you could adjust. But you do not need to turn ON and OFF the output each cycle. The PLC will take care of that for you.

If you wanted to play around with turning the output ON/OFF each cycle to see what it would do you could do something like

IF DigitalOutput THEN
    DigitalOutput:=FALSE;
ELSE
    DigitalOutput:=TRUE;
END_IF;

So when the plc goes through it's scan it will see the output is off so it will turn it on. On the next cycle it will see that it is on so it will turn it off.

Hope this helps.

mrsargent
  • 2,267
  • 3
  • 19
  • 36
  • I am using the CECC-LK by Festo. It dosn't have the PTO. When I am using the second solution, I get an error, stating; " C0077 : Unknown type: 'BLINK'. " – Subhronil Chaudhuri Mar 09 '17 at 16:57
  • I am using Codesys which has a timer called `BLINK`. What you are working with might have something called a little different. Or it might not have that type of timer at all. If that is the case you will have to make your ON/OFF timer from `TON` or `TOF` timers. – mrsargent Mar 09 '17 at 17:21
  • Thanks a lot for your help, I couldn't get the TON and TOF timer scheme to work in the way that I wanted, but anyways; I kind of took a cue from your ON/OFF scheme, and used a division-remainder based logic to define the duty cycle. It's not the most elegant, but gets the work done. Again, Thanks a ton. – Subhronil Chaudhuri Mar 10 '17 at 07:25