12C508 switch
- Could use 16C63, but inelegant
- 12C508 is a small, inexpensive PIC
- One input pin (hooked up to receiver data channel)
- Two output pins ("short pulses", "long pulses")
- Code is simple state machine (lowpin, highpin, inputpin)
- State "off, off, low" (starting state) (output pins low, input pin low, for rising edge)
- Clear both output pins.
- Loop forever while pin low
- When pin goes high, go to "off, off, high"
- State "off, off, high" (output pins low, input pin high, waiting for falling edge)
- Wait for falling edge
- If time to fall was between 0.7mS and 1.5mS, go to "on, off, low"
- If time to fall was between 1.5mS and 2.2mS, go to "off, on, low"
- Otherwise, go to "off, off, low"
- State "on, off, low" (short pulses, waiting for rising edge)
- Set "short pulses" output pin, clear "long pulses" output pin
- Wait for rising edge
- If this takes longer than 30mS, the Rx is dead. Go to "off, off, low".
- Otherwise, goto "on, off, high"
- State "on, off, high" (short pulses, waiting for falling edge)
- Wait for falling edge for at most 3mS
- If we found a falling edge between 0.65 and 1.55mS, go to "on, off, low"
- If we found a falling edge between 1.55 and 2.2mS, go to "off, on, low"
- Otherwise, go to "off, off, low"
- State "off, on, low" (long pulses, waiting for rising edge)
- Set "long pulses" output pin, clear "short pulses" output pin
- Wait for rising edge
- If this takes longer than 30mS, the Rx is dead. Go to "off, off, low".
- Otherwise, goto "off, on, high"
- State "off, on, high" (long pulses, waiting for falling edge)
- Wait for falling edge for at most 3mS
- If we found a falling edge between 0.7 and 1.45mS, go to "on, off, low"
- If we found a falling edge between 1.45 and 2.3mS, go to "off, on, low"
- Otherwise, go to "off, off, low"
- Note hysteresis:
- there is no sharp dividing line at 1.5mS
- Once we are in a state, we have some "inertia"
- Prevents "flickering" at transition point
- Timeouts, timeouts, timeouts
This page works best with Lynx.
mail me
or go home.