Need help debugging my keypad test jig.  - Page 1
Forum section: electronics / projects

author: guscrown
author_rank: Regular Contributor
timestamp: May 01, 2015, 08:56:18 pm
content: Alright, first a little background: I designed a USB Keypad using an atmel chip (the ATmega32u4). It is just standard matrix type keypad (3x4) matrix. I am using LUFA for the USB stuff, and I did the "scanning" code with 3 columns and 4 rows, and it works as it should.Now the good stuff: I want to test the reliability of my design and my code my sending say, a million key presses over a period of days. My original concept was getting some relays to replace the physical switches of the keypad and control them via an Arduino or something similar. I was searching around this forum and someone suggested the use a MUX/DEMUX like this one:https://www.sparkfun.com/products/9056I bought two of those, one for the columns, one for the rows, and I decided to use a second 32u4 to control them. This is my connection:This is my code on that 32u4 for simulating the keypresses, it basically writes an address to the mux/demux device, drops the EN line and moves them back again to HIGH and moves on to the next adress:Code:/** AutoKey.c** Created: 4/30/2015 1:05:57 PM* Author: Gus*/#include <avr/io.h>#include <util/delay.h>static void hardwareInit(void);/*The column address sel3ctor is connected to S0 = PB4 and S1 = PB5The row address selector is connected to S0 = PB6, and S1 = PB7To connect COL1 and ROW 1 together you would do the following:Column address = 0x0Row address = 0x0Pull EN line low.*/int main(void){hardwareInit();// _delay_ms(1000);while(1){//Send Key Press "0"PORTB |= 0x1F; // We are selecting Column 2, Row 1._delay_loop_2(4);PORTF &= 0xFC; // We pull PF0 and PF1 low, this ENABLES the mux/demux device and connects them together via the COM line._delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "1"PORTB |= 0xCF;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "2"PORTB |= 0x8F;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "3"PORTB |= 0x4F;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "4"PORTB |= 0xDF;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "5"PORTB |= 0x9F;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "6"PORTB |= 0x5F;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "7"PORTB |= 0xEF;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "8"PORTB |= 0xAF;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "9"PORTB |= 0x6F;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "c"PORTB |= 0x0F;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);//Send Key Press "e"PORTB |= 0x2F;_delay_loop_2(4);PORTF &= 0xFC;_delay_ms(100);PORTF |= 0x03;PORTB &= 0x0F;_delay_ms(350);}}void hardwareInit(void){DDRB |= 0xF0; // Write HIGHT to pins B4, B5, B6 and B7 to make them outputsDDRF |= 0x03; // Write HIGHT to pins F0 and F1 to make them outputsPORTB &= 0x0F; // We make B4-B7 output LOW.PORTF |= 0x03; // WE make F0 and F1 HIGH (the enable is active low)._delay_loop_2(4);}I am using this board as my 32u4 board for simulating the key presses:http://cdn.sparkfun.com/datasheets/Dev/AVR/32U4_Breakout-v11.pdfWhen I plug it in nothing happens, but after about 20 seconds, you will start getting some key presses, usually a 3, 6, 0 and a 'c'. Adter about 20-30 "random" key presses it goes into normal sequence and starts sending the correct key press sequence "0123456789ce". Every so often it goes out of sequence for some reason, and then it kicks back into normal.My keypad scan code utses the internal pull-ups from the AVR on the inputs.I am thinking I am missing something electrically, as the code is pretty straight forward, and there is no reason for it to go out of sequence, and I am not going fast at all, as I am sending 2 key presses per second, and I've tested with the regular mechanical keypad and I've never gotten a wrong character. So I assume something electrically between all of the boards I am connecting together is wrong.Any help or ideas are welcomed.

author: Ian.M
author_rank: Super Contributor
timestamp: May 01, 2015, 09:08:04 pm
content: Do you have a common ground and is your 74HC4067 supply voltage >= your ATmega32u4 supply voltage. Analog switch chips only work properly when you keep all the signals between their supply rails.Also the 70 ohm on resistance may be problematic as you have two in series. Does your original circuit work with 140 ohms in series with the switches?

author: KerryW
author_rank: Regular Contributor
timestamp: May 01, 2015, 10:54:25 pm
content: The 4067 has 4 address lines and you are only using 2 of them. What are you doing with the other 2? They should be tied to ground.

author: guscrown
author_rank: Regular Contributor
timestamp: May 02, 2015, 01:10:53 am
content: Quote from: Ian.M on May 01, 2015, 09:08:04 pmNo, my original circuit has no series resistors.

author: guscrown
author_rank: Regular Contributor
timestamp: May 02, 2015, 01:11:34 am
content: Quote from: KerryW on May 01, 2015, 10:54:25 pmGood catch, they are floating currently.

author: guscrown
author_rank: Regular Contributor
timestamp: May 02, 2015, 01:14:15 am
content: Quote from: Ian.M on May 01, 2015, 09:08:04 pmAnd yes, I made sure all grounds were tied together.

author: guscrown
author_rank: Regular Contributor
timestamp: May 02, 2015, 01:34:18 pm
content: Found the issue: Floating S2 and S3 is no bueno. I grounded them and now it works like a charm.