Reputation: 97
I am working with PLCs trying to design a water tank. On one section of the design I am asked to create a clock pulse generator. I am currently trying to do this using ladder diagrams.
I believe I have the logic correct just cant seem to put it together. I want a counter to count the clock pulses that I generate, then I store these pulese in a data memory to ensure the count is retained if the system is switched off and on.
question is how do I design this clock pulse generator.
Kind regards
Upvotes: 0
Views: 25102
Reputation: 2428
Once I had to create a BLINK FB. It is written in Structured Text. But it is suitable to use in a ladder logic program and IN/OUT Variables are named like TON style. The Blink starts with Q = TRUE. If you want to start with FALSE just invert Q and switch the Times!
FUNCTION_BLOCK BLINK
VAR_INPUT
IN : BOOL;
PT_ON : TIME;
PT_OFF : TIME;
END_VAR
VAR_OUTPUT
Q : BOOL;
ET : TIME;
END_VAR
VAR
rtIN : R_TRIG;
tonBlink : TON;
END_VAR
rtIN(CLK := IN);
IF tonBlink.Q OR rtIN.Q THEN
(*Toggle Output*)
Q := NOT Q;
(*Timer Reset call, important to call timer twice in same cycle for correct Blink Time*)
tonBlink(IN:= FALSE);
(*Set corresponding Time*)
IF Q THEN
tonBlink.PT := PT_ON;
ELSE
tonBlink.PT := PT_OFF;
END_IF
END_IF
(*Timer Run call*)
tonBlink(IN:= IN);
IF IN THEN
ET := tonBlink.ET;
ELSE
ET := T#0S;
Q := FALSE;
END_IF
Upvotes: 1
Reputation: 711
In my opinion, this is the most straightforward way to do it, using 1 timer, up counter and modulo operator:
Also note, if your PLC doesnt have modulo, then multiply by -1 each time.
Upvotes: 0
Reputation: 2442
There are a few different ways to create a pulse generator (or commonly known in the plc world as a BLINK timer). As a matter of fact many plc programming softwares have this function block built in to their function block libraries. But if they don't or you just want to make your own you can do something like this
VAR
ton1: TON;
ton2: TON;
StartPulse: BOOL;
startPulseTrig: R_TRIG;
LatchPulseInitial: BOOL;
PulseOutput: BOOL;
Timer1Done: BOOL;
Timer2Done: BOOL;
PulseWidth:TIME:=t#500ms;
END_VAR
If you would like to count the number of pulses and store this value to a variable you can use a simple CTU (counter up) block available in all plc languages.
Review of functionality
StartPulse
variable can be anything you want that will start the counter. In my case I just used an internal bool
variable that I turned on. If you want this timer to start automatically when the plc starts then just initialize this variable to true
. Because StartPulse
only works on the rising edge of the signal the LatchPulseInitial
coil will only ever be set once.LatchPulseInitial
variable goes true this will start ton1
a Timer On Delay (TON)
function block. This will delay the output of the block from turning on for the time of PT
(in my case I have 500ms).ton1
outputs will turn on. this will turn on the Timer1Done
variable and turn off the Timer2Done
and LatchPulseInitial
. Now that LatchPulseInitial
has been turned off it will never interfere with the program again since it can only be turned on by the rising edge of StartPulse
. Note: once the block has reached PT
the outputs will stay on until the input to the block is removed.Timer1Done
is now on ton2
will start counting until PT
is reached. Once PT
is reached the outputs for that block will turn on. This will reset Timer1Done
and set Timer2Done
This will start ton1
again and thus starting the whole process over.PulseOutput
, which is the actual pulse output you are looking for, I have this being set to true when Timer2Done
is true. This is because when this variable is true
it is the high state of the pulse generator. When Timer1Done
is true it is the low state of the pulse generator.PulseOutput
goes true
it will trigger the input on the CTU
which will increment the count of the variable in CV (current value)
by 1.If you are going to be using this logic in numerous places in your program or you plan on reusing it in the future I would make this into its own function block so you won't have to repeat this logic everytime you want to make this type of timer.
Upvotes: 1