+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Junior Member level 2
    Points: 347, Level: 3

    Join Date
    Nov 2013
    Posts
    20
    Helped
    0 / 0
    Points
    347
    Level
    3

    KEYPAD Scanner 4x4 cpld

    I just try to write a program which detect the 4x4 keypad and decode. I try to learn xilinx application xapp512__verilog.zip, but I still confuse how to write this program.

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 29,635, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,863
    Helped
    1115 / 1115
    Points
    29,635
    Level
    41
    Blog Entries
    9

    Re: KEYPAD Scanner 4x4 cpld

    The model of the reading of a keyboard based on a matrix scanning is a legacy of the times when the number of ports available on chips was much smaller if compared to the current ones. In your case in particular on what you want to scan 16 keys, and would use 8 ports, it wouldn´t be more convenient to read directly all the pins one by one ?

    I´m basing on the fact that this application is not complicated, and you can probably find many implementations on the Web or even here, and a simplest solution would bring to you the same result.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisement

        
       

  3. #3
    Junior Member level 2
    Points: 347, Level: 3

    Join Date
    Nov 2013
    Posts
    20
    Helped
    0 / 0
    Points
    347
    Level
    3

    Re: KEYPAD Scanner 4x4 cpld

    i have got this code on the web but its just 3x4 matrix well i need 4x4 matrix

    Code:
    module keypadscan(reset, 
                      clk, 
                      row, 
                      column, 
                      out);
       // program for 4x3 keypad
       input  reset, clk;
       output [3:0] row; 
       input  [2:0] column; //pullup to vcc 
       output [3:0] out;    //decoded output
    
       reg  [3:0]  row;
       reg  [3:0]  out;
    
       wire        scan_en = &column;
       
       //scanning keypad
       always @(posedge clk or posedge reset)
         if (reset) 
           row <= 4'b1110;
         else if (scan_en)
           row <= {row[2:0], row[3]};
       
                   
       always @(row or column) begin
          out = 4'b0000;
          case ({row,column})
            7'b1110_110 : out = 4'b0001;
            7'b1110_101 : out = 4'b0010;
            7'b1110_011 : out = 4'b0011;
            
            7'b1101_110 : out = 4'b0100;
            7'b1101_101 : out = 4'b0101;
            7'b1101_011 : out = 4'b0110;
            
            7'b1011_110 : out = 4'b0111;
            7'b1011_101 : out = 4'b1000;
            7'b1011_011 : out = 4'b1001;
            
            7'b0111_110 : out = 4'b1110; // decode as E
            7'b0111_101 : out = 4'b0000;
            7'b0111_011 : out = 4'b1111; // decode as F
          endcase // case({row,column})
       end // always @ (row or column)
    endmodule // keypadscan
    - - - Updated - - -

    still this one is giving an error ??
    Last edited by bigdogguru; 16th March 2015 at 15:58. Reason: Combined Multiple Replies



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 29,635, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,863
    Helped
    1115 / 1115
    Points
    29,635
    Level
    41
    Blog Entries
    9

    Re: KEYPAD Scanner 4x4 cpld

    As a first attempt, had you even tried to expand the size of variable column on the code above, and also performed some simulation ?
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  5. #5
    Junior Member level 2
    Points: 347, Level: 3

    Join Date
    Nov 2013
    Posts
    20
    Helped
    0 / 0
    Points
    347
    Level
    3

    Re: KEYPAD Scanner 4x4 cpld

    Quote Originally Posted by andre_teprom View Post
    As a first attempt, had you even tried to expand the size of variable column on the code above, and also performed some simulation ?
    I dont even know how to test it on test bench



    •   AltAdvertisement

        
       

  6. #6
    Advanced Member level 5
    Points: 14,946, Level: 29
    mrflibble's Avatar
    Join Date
    Apr 2010
    Posts
    2,724
    Helped
    687 / 683
    Points
    14,946
    Level
    29

    Re: KEYPAD Scanner 4x4 cpld

    Quote Originally Posted by jokester4u View Post
    I dont even know how to test it on test bench
    In which case this should get you started: http://www.asic-world.com/verilog/ar...h_writing.html



--[[ ]]--