The Signal Processor: Complete Manual

Reference notes for A Handful of Chips.

Tidied up for the bench. When a control loop starts hunting or a heater locks on, check the pin caps first and the chip count second.

Hardware and pins

Syntax rules and parser traps

Operator precedence and logic traps

Operators bind from tightest at the top to loosest at the bottom.

Precedence Operators Notes
1, tightest func(...), ( ) Brackets cost 0. Use them whenever a line looks cramped.
2 ^ Power, right-associative: 2^3^2 means 2^(3^2).
3 -x Unary minus.
4 *, / Multiplication and division.
5 +, - Addition and subtraction.
6 >, <, >=, <=, ==, != Comparisons. Return 1 or 0.
7 ! Boolean NOT. Binds looser than comparisons.
8 & Boolean AND. Binds tighter than \|.
9, loosest \| Boolean OR.

Functions and chip cost

Fit chips into the lower-left Chips slot. It holds up to 64 Cheap Chips, or up to 8 Advanced Chips worth 8 Cheap Chips each. Each Cheap Chip pays for 4 operator cost points:

chips required = ceil(total operator cost / 4)

The status line reads N Cheap Chip(s) required in green when enough chips are fitted, and red when you are short. Short of chips, the output drops to 0 V. Chips are never used up.

Numbers, names, and brackets cost 0.

Syntax Operator Cost Behaviour and State Rules
+, -, *, /, -x 1 Basic arithmetic.
!x 1 Boolean NOT. Returns 1 when x <= 0.5, else 0.
>, <, >=, <=, ==, != 1 Comparisons returning 1 or 0. == and != compare within 0.01.
&, \| 1 Boolean AND and OR. Inputs above 0.5 count as on; returns 1 or 0.
abs(a) 1 Absolute value of a.
min(a,b), max(a,b) 2 Smaller or larger of two values.
sin(a), cos(a), asin(a), acos(a) 2 Trig in radians. asin and acos outside -1..1 produce NaN, which outputs 0 V.
pow(a,b), a^b 2 a to the power b.
if(c,t,e) 2 Returns t when c > 0.5, else e. Stateful calls inside either branch still step every sub-step.
ramp(T) 3 Stateful. Rises linearly from 0 to 1 over T seconds, then repeats from 0.
derivate(x) 3 Stateful. Rate of change per second. First step outputs 0. Smooth noisy signals with rc first.
rs(set,reset) 3 Stateful. SR latch, set first, reset second. Both trigger above 0.5. If both are on, reset wins and outputs 0.
rc(x,tau) 3 Stateful. Low-pass smoothing filter, signal x first, time constant tau in seconds second.
integrate(x,reset) 4 Stateful. Adds x per second. Held at 0 while reset > 0.5.
integrate(x,lo,hi) 4 Stateful. Adds x per second, clamped to lo..hi.
scale(x,in0,in1,out0,out1) 5 Maps x linearly from in0..in1 onto out0..out1. Not clamped internally.
batteryCharge(u) 8 Converts battery voltage ratio u = U / U_nominal into state of charge 0..1.
pid(target,meas,P,I,D) 12 Stateful. PID controller on target - meas. Integral is clamped to 0..1.
pid(target,meas,P,I,D,lo,hi) 14 Stateful. Same controller, with both its integral and its output clamped to lo..hi.

The daytime clock

The built-in variable daytime equals (ticks mod 24000) / 23999:

daytime>0.5 is true all night and costs 1 Cheap Chip.

Cookbook formulas

  1. Thermostat latch — 2 Cheap Chips rs(A<0.6, A>0.8) Wire a Thermal Probe to A and the output to your heater control. set comes first: when A falls below 0.6, 3 V, the heater turns on; when A climbs above 0.8, 4 V, the latch resets and shuts heat off. Reversing the arguments heats when hot.

  2. Night-time yard lamp switch — 1 Cheap Chip daytime>0.5 Outputs 5 V from sunset to sunrise and 0 V by day. Use daytime>0.48 to bring the lamps on just before dusk.

  3. PI temperature or flow controller — 4 Cheap Chips pid(0.7,A,4,0.5,0,0,1) Holds sensor A at 0.7, 3.5 V, with P=4, I=0.5, D=0, and integral plus output clamped to 0..1. Suits a Pipe Control Valve or Submersible Pump.

  4. Sensor averaging and smoothing — 1 Cheap Chip each * Mean of three sensors: (A+B+C)/3 * Two-second low-pass filter: rc(A,2) — signal A first, time constant 2 seconds second.

  5. 2-out-of-3 redundant sensor vote — 2 Cheap Chips * Digital inputs: A&B|A&C|B&C — & binds tighter than |, so no brackets are needed. * Analog inputs with custom threshold: (A>0.5)+(B>0.5)+(C>0.5)>1.5

  6. Battery-charge load shedding — 4 Cheap Chips q = batteryCharge(0.8+0.4*A) rs(q>0.6, q<0.3) Wire a voltage Electrical Probe on a 48 V bank with range set to 38.4–57.6 V, or 184–276 V on a 230 V bank, into A. Naming q pays batteryCharge only once. The latch drops non-essential loads below 30% charge and brings them back above 60%.

  7. Differential gain amplifier — 1 Cheap Chip (A-B)*3 Clamps at the output automatically. If you feed the result into another line inside the same program, clamp it with min(1,max(0,(A-B)*3)) at 2 Cheap Chips.

  8. Sensor window stretcher — 2 Cheap Chips scale(A,0.2,0.8,0,1) Stretches the 1–4 V band of input A across the full 0–5 V output range.

  9. 10-second delay timer and flasher * Delay after release — 3 Cheap Chips: hi = A>0.5 rs(integrate(1, hi) > 10, hi) While A stays high, the latch is held reset at 0 V and the integrator is held at 0. Once A drops low, the integrator counts up at 1 per second and sets the output to 5 V after 10 continuous seconds. * Square-wave flasher — 1 Cheap Chip: ramp(T)<0.5 flashes with period T seconds.

  10. Sudden rate-of-change alarm — 2 Cheap Chips abs(derivate(rc(A,1)))>0.05 Smooths A with a 1-second filter first, then trips to 5 V whenever A rises or falls faster than 0.05, 0.25 V, per second.


Reference index · Back to the contents