Get MBLogic at SourceForge.net. Fast, secure and Free Open Source 
	software downloads

Help Topics

Topic Details for Soft Logic

Counter and Timer Instructions


Instr. Descr. # Param T CT DS DD KInt KDInt Time Base Symbol
CNTU Count up 2 X X X X X CNTU
CNTD Count down 2 X X X X X CNTD
UDC Up / down counter 2 X X X X X UDC
TMR On delay timer 3 X X X X TMR
TMRA On delay accum. timer 3 X X X X TMRA
TMROFF Off delay timer 3 X X X X TMROFF

Counters

Counter instructions come in three types:

All counter instructions take two parameters. The first is a counter number, and the second is the counter preset. The counter preset may be either a constant or a register address. When the present value of the counter is equal to the preset, the counter status bit turns on. The address of the counter status bit is the same as the counter number. The present value of the counter is stored in the counter data register (CTD) of the same number as the counter number. E.g. for counter CT5, the counter status bit is also CT5, and the present count is in CTD5.

Example:


	// Up counter.
	NETWORK 1
	STR C1
	STR C2
	CNTU CT5 155793
	STR CT5
	OUT Y1
	
	// Down counter.
	NETWORK 2
	STR C11
	STR C12
	CNTD CT15 DD11
	STR CT15
	OUT Y11
	
	// Up/down counter.
	NETWORK 3
	STR C21
	STR C22
	STR C23
	UDC CT25 DS5
	STR CT25
	OUT Y21
	
	// Examine counter present values.
	NETWORK 7
	STRE CTD15 157
	OUT Y112

Timers

Timers come in three types:

All timer instructions take three parameters. The first is the timer address. The second is the timer preset. The timer preset may be either a constant or a register address. The third parameter is the time base. This may be either "ms" (milliseconds), "sec" (seconds), "min" (minutes), "hour" (hours), or "day" (days).

Example:


	// On delay timer.
	NETWORK 4
	STR X1
	TMR T5 25000 ms
	STR T5
	OUT Y51
	
	// Accumulating on delay timer.
	NETWORK 5
	STR X11
	STR X12
	TMRA T6 DS9 sec
	STR T6
	OUT Y52
	
	// Off delay timer.
	NETWORK 6
	STR X62
	TMROFF T192 DS412 min
	STR T192
	OUT Y57
	
	// Examine timer present values.
	NETWORK 7
	STRE TD6 97
	OUT Y120


Ladder Examples

The following shows examples in ladder format.

counter timer example 1 counter timer example 2 counter timer example 2 counter timer example 3