cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
413 Views
Registered: ‎01-17-2020

Keypad 4x4 matrix

Help please!! 

I have a project in college on the bord nexys4 ddr. 

The requirements are:

• Walk 1 sequence on columns, at a frequency of 1..2KHz

• The frequency of the sequence to be stable by the timer interrupts

• Capture by logical analysis of the sequence of Walk1 and of the signals on the entrances.

• Connect an 8-line GPIO IP to the JD, which in turn will connect to the keyboard matrix: Top row - outputs (we choose columns), bottom row: inputs (we choose rows)

///////////////////////////////

 

I was advised to use this code example only as I use JD pins:

/******************************************************************************


#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xgpio.h"
#include "xparameters.h"
#include "xil_io.h"
#include "sleep.h"

XGpio Leds_Switches;
XGpio RGB_Push;
XGpio JB_Connector;

#define SS 0
#define MOSI 1
#define MISO 2
#define SCK 3

//Initialize GPIO devices
int InitGpioDevices();

//SPi Transfer functions by Bitbanging
int SpiTransferBitBangGpio8 (XGpio * Deviceptr, u8 * pDsend, u8 * pDrec, u32 NumBytes);
int SpiTransferBitBangGpio16 (XGpio * Deviceptr, u16 * pDsend, u16 * pDrec, u32 NumHalfWords);


int main()
{
int STATUS;
//Structure the date 
u8 DataSend8[4] = {0xA1, 0xB2, 0xC3, 0xD4};
u8 DataRec8[4];
u16 DataSend16[4] = {0xAB12, 0xCD34, 0xEF56, 0x0178};
u16 DataRec16[4];

//Pointeri
u8 * pDsend8, * pDRec8;
u16 * pDsend16, * pDRec16;

u32 i = 0;
u32 LS1Data = 0x1;

init_platform();

print("Hello World\n\r");

// Initialize the GPIO devices
if( InitGpioDevices() == XST_SUCCESS ) xil_printf("\r\nGPIO devices Initialized");
else {
xil_printf("\r\nGPIO devices Initialization Failure");
return XST_FAILURE;
}


//JB pinii 1,2 si 4 = JB_GPIO[0], [1] si [3] le setam ca iesiri
//XGpio_SetDataDirection(&JB_Connector, 1, 0xFF);
//Set initial value for SPI: SS sa fie 0
//XGpio_DiscreteWrite(&JB_Connector, 1, 0xFF);

while(1){

 

//LS1Data = XGpio_DiscreteRead(&JB_Connector, 1);

 

xil_printf("\r\nLS1 Data = 0x%X", LS1Data);
usleep (1000000);
}


cleanup_platform();
return 0;
}


int InitGpioDevices(){
int Status;


Status = XGpio_Initialize(&Leds_Switches, XPAR_LEDS_SWITCHES_DEVICE_ID);
if (Status != XST_SUCCESS) {
xil_printf("\r\nLeds_Switches Initialization Failed\r\n");
return XST_FAILURE;
}

Status = XGpio_Initialize(&RGB_Push, XPAR_RGB_PUSH_DEVICE_ID);
if (Status != XST_SUCCESS) {
xil_printf("\r\nRGB_Push Initialization Failed\r\n");
return XST_FAILURE;
}

Status = XGpio_Initialize(&JB_Connector, XPAR_GPIO_0_DEVICE_ID);
if (Status != XST_SUCCESS) {
xil_printf("\r\nJB_Connector Initialization Failed\r\n");
return XST_FAILURE;
}

return XST_SUCCESS;
}

int SpiTransferBitBangGpio8 (XGpio * Deviceptr, u8 * pDsend, u8 * pDrec, u32 NumBytes){
int i = 0, j = 0;

//copy pointerii
u8 * ppDsend = pDsend; u8 * ppDrec = pDrec;
u8 TempSend, Temprec = 0;

 

for (j= 0; j < NumBytes; j++){
//Incaracm datele
TempSend = * ppDsend; ppDsend++;
//down SS si down CLK
XGpio_DiscreteClear(Deviceptr, 1, (1 << SS) );
XGpio_DiscreteClear(Deviceptr, 1, (1 << SCK) );

for (i = 0; i < 8 ; i++){

//Set MOSI
if (TempSend & 0x80) XGpio_DiscreteSet(Deviceptr, 1, (1 << MOSI) );
else XGpio_DiscreteClear(Deviceptr, 1, (1 << MOSI) );
usleep (1);
//Front pozitiv SCK
XGpio_DiscreteSet(Deviceptr, 1, (1 << SCK) );
//read date
TempSend = TempSend << 1;
Temprec = Temprec << 1;
if ( (XGpio_DiscreteRead(Deviceptr, 1) & (1 << MISO)) ) Temprec = Temprec | 0x1;
else Temprec = Temprec & 0xFE;
usleep (1);
//Front negativ SCK
XGpio_DiscreteClear(Deviceptr, 1, (1 << SCK) );
}
//Up SS
XGpio_DiscreteSet(Deviceptr, 1, (1 << SS) );

//Save date
* ppDrec = Temprec; ppDrec++;
}
return 0;
}

int SpiTransferBitBangGpio16 (XGpio * Deviceptr, u16 * pDsend, u16 * pDrec, u32 NumHalfWords){
int i = 0, j = 0;

//copy pointerii
u16 * ppDsend = pDsend; u16 * ppDrec = pDrec;
u16 TempSend, Temprec = 0;

 

for (j= 0; j < NumHalfWords; j++){
//upload date
TempSend = * ppDsend; ppDsend++;
//down SS and down CLK
XGpio_DiscreteClear(Deviceptr, 1, (1 << SS) );
XGpio_DiscreteClear(Deviceptr, 1, (1 << SCK) );

for (i = 0; i < 16 ; i++){

//Set MOSI
if (TempSend & 0x8000) XGpio_DiscreteSet(Deviceptr, 1, (1 << MOSI) );
else XGpio_DiscreteClear(Deviceptr, 1, (1 << MOSI) );
usleep (1);
//Front pozitiv SCK
XGpio_DiscreteSet(Deviceptr, 1, (1 << SCK) );
//read date
TempSend = TempSend << 1;
Temprec = Temprec << 1;
if ( (XGpio_DiscreteRead(Deviceptr, 1) & (1 << MISO)) ) Temprec = Temprec | 0x1;
else Temprec = Temprec & 0xFE;
usleep (1);
//Front negativ SCK
XGpio_DiscreteClear(Deviceptr, 1, (1 << SCK) );
}
//Up SS
XGpio_DiscreteSet(Deviceptr, 1, (1 << SS) );

//Save date
* ppDrec = Temprec; ppDrec++;
}
return 0;
}

 

 

The constraint line and block diagram are attached below!!

 

set_property -dict { PACKAGE_PIN H4    IOSTANDARD LVCMOS33 } [get_ports { JD_PINS_tri_io[0] }]; #IO_L21N_T3_DQS_35 Sch=jd[1]

set_property -dict { PACKAGE_PIN H1    IOSTANDARD LVCMOS33 } [get_ports { JD_PINS_tri_io[1] }]; #IO_L17P_T2_35 Sch=jd[2]

set_property -dict { PACKAGE_PIN G1    IOSTANDARD LVCMOS33 } [get_ports { JD_PINS_tri_io[2] }]; #IO_L17N_T2_35 Sch=jd[3]

set_property -dict { PACKAGE_PIN G3    IOSTANDARD LVCMOS33 } [get_ports { JD_PINS_tri_io[3] }]; #IO_L20N_T3_35 Sch=jd[4]

set_property -dict { PACKAGE_PIN H2    IOSTANDARD LVCMOS33 } [get_ports { JD_PINS_tri_io[4] }]; #IO_L15P_T2_DQS_35 Sch=jd[7]

set_property -dict { PACKAGE_PIN G4    IOSTANDARD LVCMOS33 } [get_ports { JD_PINS_tri_io[5] }]; #IO_L20P_T3_35 Sch=jd[8]

set_property -dict { PACKAGE_PIN G2    IOSTANDARD LVCMOS33 } [get_ports { JD_PINS_tri_io[6] }]; #IO_L15N_T2_DQS_35 Sch=jd[9]

set_property -dict { PACKAGE_PIN F3    IOSTANDARD LVCMOS33 } [get_ports { JD_PINS_tri_io[7] }]; #IO_L13N_T2_MRCC_35 Sch=jd[10]

 

4x4-Keypad-Module.jpg
capture_20200214215137.jpg

0 Kudos
4 Replies
Highlighted
409 Views
Registered: ‎06-21-2017

Re: Keypad 4x4 matrix

What is your question?

0 Kudos
Highlighted
Visitor
Visitor
393 Views
Registered: ‎01-17-2020

Re: Keypad 4x4 matrix

I need a code, I don't know how to meet the requirements.

0 Kudos
259 Views
Registered: ‎06-21-2017

Re: Keypad 4x4 matrix

No one on this forum will do your work for you.  Try to write the code you need and somebody may try to help.  Your requirements are hard to understand.  You need to define them more clearly.  That will probably help you write code.  Your figure is hard to read.  There is not enough resolution to read anything if the figure is zoomed in.  Are you looking for C code or some type of HDL?  You posted some C code.  Did your instructor tell you to use this as a starting point or did somebody else?  You mention timer interrupts.  Do you know how to generate them and how to respond to an interrupt?

Highlighted
Scholar
Scholar
240 Views
Registered: ‎04-26-2015

Re: Keypad 4x4 matrix

@sturz112 You should check with your teacher/lecturer/professor, but I suspect that their intention was that you would do this assignment (and learn to write the code), not that you would beg others to do it. If you want to post their phone number here, I'll be happy to call and ask them on your behalf...

 

As @bruce_karaffa has so correctly said, try to write it yourself and post here if/when you have a problem. If your question is "how do I write code" you will get no help. If your question is "I wrote this code and implemented it on <hardware>, but the ISR is never running - how can I debug this?" then you will (a) get help, and (b) learn a lot.

 

0 Kudos