Reputation: 1
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.
Upvotes: 0
Views: 904
Reputation: 2442
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.
Upvotes: 1