ts-7000
[Top] [All Lists]

[ts-7000] DIO port question

To:
Subject: [ts-7000] DIO port question
From: Mike Dodd <>
Date: Sat, 26 Mar 2005 21:56:06 -0500
I'm trying to test a simple 4x4 keypad matrix on a TS-7250, and am seeing 
some very strange behavior. Is there something I'm missing here?

I have a 16-key keypad wired as a 4x4 matrix; an ohm meter verifies that 
all keys connect their respective row and column together. The columns are 
wired to bits 0-3 on the DIO port (pins 1, 3, 5, and 7), and the rows are 
wired to bits 4-7 (pins 9, 11, 13, and 15).

I've looked at the example keypad.c code from this list, and I understand 
what it's doing. Right now, I'm ignoring the debounce stuff, because I just 
want to see the keys respond.

The problem is, the code is not reliably detecting the depressed keys. Here 
is the test code from my getKeys() function, which is called by main() 
about once every second, so I can see the output. (I'm setting only one 
column pin at a time to an output because several keys might be depressed 
at once, and without series diodes, the output pins would be shorted 
together. So all column pins are set to inputs except when scanning that 
column.)

-----------------------------------------
(In the main function)
PBDR = (unsigned int *)(start + 0x04);
PBDDR = (unsigned int *)(start + 0x14);

unsigned int *dataPort = PBDR;  // Use Port B for keypad data
unsigned int *dataDirReg = PBDDR;  // Direction register for keypad data port
*dataDirReg = 0x00;  // Start with all bits inputs (changed when reading 
keypad)
// Loop to call getKey, then delay.

-----------------------------------------
(In the getKey function)
int col;
col = 0;
*dataDirReg = (1 << col);  // Set one column to output and pull it low
*dataPort = ~(1 << col);
printf("col = %d, *dataPort = %04X\n", col, (*dataPort & 0xff));

col = 1;
*dataDirReg = (1 << col);  // Set one column to output and pull it low
*dataPort = ~(1 << col);
printf("col = %d, *dataPort = %04X\n", col, (*dataPort & 0xff));

col = 2;
*dataDirReg = (1 << col);  // Set one column to output and pull it low
*dataPort = ~(1 << col);
printf("col = %d, *dataPort = %04X\n", col, (*dataPort & 0xff));

col = 3;
*dataDirReg = (1 << col);  // Set one column to output and pull it low
*dataPort = ~(1 << col);
printf("col = %d, *dataPort = %04X\n", col, (*dataPort & 0xff));

*dataDirReg = 0;  // Set all columns back to input
-----------------------------------------

If I comment-out all but one of these sections, everything works as 
expected. I can press any key or combination of keys and see the expected 
result. It doesn't matter which column I un-comment, it works correctly.

But if I have any two columns un-commented, the first one works perfectly, 
but the second one returns unpredictable results. That is, sometimes I see 
zeros for the depressed keys, but other times all the bits are 1.

I'm thinking there is a delay between outputting the 0 and when the 
hardware actually responds. Is this the case? I've put a 'usleep(100000);' 
statement after each section, and that seems to help a little, but it's 
still only 25%-50% correct.

Thanks for any insight into this issue.

Mike

------
Mike Dodd - Montpelier, VA
http://www.mdodd.com



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU