User-Defined Opcode Database

hysteresis

Implements classic 2-threshold hysteresis. Useful for performance controllers.

Download UDO File

Description

This User Defined Opcode implements the classic HIT / RESET threshold idea. Based on a Max/MSP implementation which is the work of Eric Singer (c) 1994.

Syntax

kboth, khi_tru, klo_tru hysteresis kin, khi_thresh, klo_thresh

Performance

kin -- The input value which is subject to the hysteresis thresholds.

khi_thresh -- This is the HIGH threshold. When the value at kin exceeds this, a 1 outputs at khi_tru and kboth.

klo_thresh -- This is the LOW threshold. When the value at kin exceeds this, a 1 is output at klo_tru.

khi_tru -- Outputs a 1 if kin exceeds the HIGH threshold else 0.

klo_tru -- Again, boolean output of kin exceeding LOW threshold.

kboth -- Outputs a 1 if kin exceeds both thresholds.

Code

opcode	hysteresis, kkk, kkk

kin, khi, klo	xin

if	(kin > klo) then
klotr	=	1
kout	=	1
	if	(kin >= khi) then
	kout	=	1
	khitr	=	1
	else
	kout	=	0
	khitr	=	0
	endif
else
kout	=	0
klotr	=	0
	endif

	xout	kout, khitr, klotr

		endop

Examples

instr	1	;  demonstrate hysteresis

kin	ctrl7	1, 1, 0, 127
khi	ctrl7	1, 7, 0, 127
klo	=	khi - 45

koot, khitr, klotr	hysteresis	kin, khi, klo

	printks	"out: %d\\n\\n", 0.25, koot
	printks	"in: %d, hi: %d, lo: %d\\n\\nhitr: %d, lotr: %d\\n\\n", 0.25, kin, khi, klo, khitr, klotr
		endin

Credits

David Akbari - 2005


Previous Home Next
rbatonXYZ   lowpass