Tuesday, May 23, 2017

PIC-based Push-button K9AY Controller

Push-button K9AY controller works!
I can't believe I have been working on this project for three years. I wrote about it earlier, describing the project and how it didn't work, because of the bouncy mechanical switches.

Yes, I bought the PIC16F1503 chips. It also took a while to figure out how to program them.

Conceptually, the software is simple. I program the Timer1 timer to fire every millisecond. Then the cpu loops and waits for an interrupt.

When the interrupt fires, I gather the state of all four of the direction buttons from PortA, and shift each into a byte in memory. This gives me the state of each button for the last eight milliseconds.

When a button is pressed, even if it bounces a bit, it will eventually transition to an on state. If it holds that state for seven milliseconds, it will result in a distinctive pattern: 01111111.

That's what I look for. If a button has this pattern on any interrupt, I consider it to be on. Otherwise, it is off. Take the value of all four buttons and jam them together side by side, and you have a number between 0 and 15. Sixteen values in a lookup table. Look up the current value. If it is zero, do nothing. If non-zero, I write the value out to PortC. The PortC bits control the LEDs on the buttons as well as the control lines for the two relays which select the control voltage for the K9AY loops.

All the work is in the lookup table. It has all zeros except for the four entries where one button has been pressed -- one each for the four directions.

It's all less than 100 instructions.

Most importantly, it works!

My prototype has wiring that's a little flaky. The board flexes a little bit when the buttons are pressed and sometimes the wiring moves a bit and shorts out. I'm thinking that now that I have something that works, I should make a printed circuit board.