6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 4:02 am

All times are UTC




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Wed Aug 26, 2015 5:37 pm 
Offline
User avatar

Joined: Wed Feb 13, 2013 1:38 pm
Posts: 589
Location: Michigan, USA
Didn't mean to embarrass you, Mike.

Not sure why the diodes aren't working.

On the software side... I wonder if converting keypad row and column into an index might make it easier to maintain or modify a keymap array that mimics the layout of the actual keypad?

Code:
 #define bitmask(bitnbr) (1 << (bitnbr))

 const char keymap[] = { '0','1','2','3',   // row 0, columns 0..3
                         '4','5','6','7',   // row 1, columns 0..3
                         '8','9','A','B',   // row 2, columns 0..3
                         'C','D','E','F',   // row 3, columns 0..3
                          0 };              // null (no switch pressed)

/********************************************
 *  Scan Keypad                             *
 ********************************************/

 char scan(void)                            // scan keypad matrix
 { char keyndx = 16;                        // null (no switch pressed)
   for(char col = 0; col < 4; col++)        // column 0..3
   { DDRD = bitmask(col);                   // set 'col' bit to output, all others inputs
     PORTD = ~(bitmask(col));               // set 'col' bit to '0', pull-up all other pins
     for(char row = 0; row < 4; row++)      // rows 0..3
     { if(PIND & bitmask(row + 4) == 0)     // if active low key press (row bit == '0')
         keyndx = row * 4 + col;            // save index, 0..15
     }                                      // next row
   }                                        // next col
   return(keymap[keyndx]);                  // return 0 or ASCII keycode
 }


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 26, 2015 5:51 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
It's very odd. I've slowed down the speed of the AVR and also injected a 10ms and then 100ms delay between the row changes. If I do this then you can see the changes on the other side of the diode, but the AVR doesn't pick it up.
If I desolder the wire from the anode side of the diode and put it on the cathode it then all works for that row. Might be something to do with current pull as I measure a draw of 60-80uA on the row when it's working? Not sure.

As for your idea with regard to the key matrix array - I did think of this initially, but I don't get along well with C and so was having some real issues trying to implement certain things - arrays being one of them. Now that you've kindly provided me with an example, I'll give it another go :).

[edit] or maybe the prop delay introduced by the diodes..... I'll try sticking a delay in between the row going low and the column checks...


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 26, 2015 6:08 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Are you sure your inputs are set to be inputs and are not driving a value?


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 26, 2015 7:29 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
BigEd wrote:
Are you sure your inputs are set to be inputs and are not driving a value?

Don't think so. I've double checked the wiring and this is my defintions for the ports/pins on the AVR:
Code:
   // 0=input, 1=output
   
   // rows (PD pins 4-7), columns PD, pins 0-3)
   DDRD = 0b11110000;         // port D, set to 4-7 (output), 0-3 (input)
   PORTD = 0xff;            // port D, pins 4-7 output 1111, pull ups enabled for pins 0-3
   
   // VIA pins (lower nibble=PC, pins 3 to 0 (reversed), upper nibble=PB6 (bit4), PB2 (bit5), PB1 (bit6), PB0 (bit7) 
   DDRC = 0xff;            // port C, set to output
   PORTC = 0x0;            // port C, pull ups disabled
   DDRB = 0xff;            // port B, set to output
   PORTB = 0;               // port B, pull ups disabled


The "good" news is that I now get the short6 circuit issue when more than one key is pressed when they're on different rows :mrgreen:.
I'll put in the tristating for the rows.

[edit]

Here we go. This works fine and no need for those diodes. Still puzzled as to why they don't work though... :?

Code:
unsigned char scanKbd(void)
{
   // ensure that
   //PORTD = 0xff;
   unsigned char scanresult;
   
   scanresult = 0;

   for (int row=4;row<=7;row++)
   {
      KYBD_bit_set(DDRD, KYBD_bit(row));               // set row as output
      KYBD_bit_clear(PORTD, KYBD_bit(row));
      for (int col=0;col<=3;col++)
      {
         if (KYBD_bit_get(PIND, KYBD_bit(col))==0)
         {
            KYBD_bit_set(scanresult, KYBD_bit(col));
            KYBD_bit_set(scanresult, KYBD_bit(row));
         }
      }
      KYBD_bit_set(PORTD, KYBD_bit(row));
      KYBD_bit_clear(DDRD, KYBD_bit(row));               // set row as input (disable it)
   }
   return(scanresult);
}


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 28, 2015 5:55 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
Just received some of these in the post. No wonder they are so cheap. The awesome tactile feel reminds me of the original ZX80... :roll: :wink: .

As discussed previously; I wish I could find a decent keypad which use buttons and are 5x5 or 6x6... :(

Attachment:
cheapkeypad.jpg
cheapkeypad.jpg [ 15.59 KiB | Viewed 532 times ]


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 01, 2015 5:54 am 
Offline

Joined: Sun Apr 10, 2011 8:29 am
Posts: 597
Location: Norway/Japan
banedon wrote:
As discussed previously; I wish I could find a decent keypad which use buttons and are 5x5 or 6x6... :(


There's this great site where you can find all kinds of info.. 6502.org! :) Specifically, this thread: viewtopic.php?f=4&t=3235

If you enter 'white keyboard metal panel machine pushbutton' in Ebay's search you should see a bunch of them. No 6x6 though. I bought a couple of those after seeing chessdoger's post and his design pages. They feel really nice and solid.


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 01, 2015 12:29 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
Dammit I tried ebay, lol! Thanks Tor. I'll investigate when I get home this evening. :)


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2015 9:39 pm 
Offline

Joined: Wed Oct 07, 2015 8:45 pm
Posts: 7
This is pretty much exactly what I've been looking for!
- Is it possible to program the atmega328 by programming the .hex file (/debug folder) to it with a universal device programmer (Eproms, mpu's, etc)? - Or would you have to compile a proper .hex dump with Atmel studio?

--Christoffer


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2015 9:53 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Quote:
One thing: I can't seem to use the diodes. The rapid pulsing of the rows isn't translated throught the 1N4848 diodes - I get a very shallow square wave ripple on the other side. Anyone got any suggestions on a different type? If not, I'll try and slow down the scanning to see if that helps (and yes, I have the diodes the correct way round :p).

1N4148 diodes are plenty fast, but they drop a lot more voltage than Schottky diodes do; so depending on the configuration, it may barely be pulling down to a valid logic-0. Put the diodes on the outputs to keep them from getting shorted together and fighting if two keys are pressed that would otherwise short outputs together. Don't put them on the inputs. What's the value of your pull-up resistors?

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2015 10:55 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
Christoffer wrote:
This is pretty much exactly what I've been looking for!
- Is it possible to program the atmega328 by programming the .hex file (/debug folder) to it with a universal device programmer (Eproms, mpu's, etc)? - Or would you have to compile a proper .hex dump with Atmel studio?

--Christoffer

You should be able to use that hex file. If you have any problems I'm sure that I can dig out my code and recompile it for you.
Let me know.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 41 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: