UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Explorer
Explorer
4,884 Views
Registered: ‎12-06-2007

LED Problem( When Press Push Button, no LED light up)

When I tried this coding , the FPGA light up 2 LEDs.

 

#include "xgpio.h"

#include "xparameters.h"

 

#define LED_1 0x8

#define LED_2 0x4

 

int main(void)

{

  XGpio gp_out;

 

  XGpio_Initialize(&gp_out, XPAR_LEDS_4BIT_DEVICE_ID);

  XGpio_SetDataDirection (&gp_out, 1, 0x0);

 

  while (1)

  {

 

    XGpio_DiscreteWrite (&gp_out, 1, LED_1 | LED_2); // Light up continuously

 

  }

 }

 

 

But the problem occur when I design a code where push button is pressed , particular LED will light up. Based on below coding, when I press, the information of which LED should be light up is displayed in the hyperterminal. But it does not light the particular LED.

 

#include "xparameters.h"

#include "xgpio.h"

#include "xutil.h"

 

int main (void)

{

   XGpio led,Push;

   int push_check1, push_check=0;

  

   xil_printf("-- Entering main() --\r\n");

 

   XGpio_Initialize(&led,XPAR_LEDS_4BIT_DEVICE_ID);

   XGpio_Initialize(&Push,XPAR_PUSH_BUTTONS_5BIT_DEVICE_ID);

  

   XGpio_SetDataDirection(&led,1,0x0);

   XGpio_SetDataDirection(&Push,1,0xffffffff);

 

 

   xil_printf("Press center push button to exit\r\n");

   xil_printf("Any other to see corresponding LED turn ON\r\n");

  

   push_check = XGpio_DiscreteRead(&Push,1);

 

  

   while(1)

   {

      push_check1 = XGpio_DiscreteRead(&Push,1);

     

      if(push_check1 != push_check)

      {

        push_check=push_check1;

        if(push_check)

        xil_printf("Push buttons status %0x\r\n", push_check1);

      }

 

    if(push_check==0x10)

    {

       break;

    }

   

    XGpio_DiscreteWrite(&led,1,push_check); // Should light up the LED. But it does not.

   }

 

   xil_printf("-- Exiting main() --\r\n");

   return 0;

}

 

Below is the  UCF that was generated by the XPS 9.2 for virtex4 (ML401) board

 

#### Module LEDs_4Bit constraints

Net fpga_0_LEDs_4Bit_GPIO_IO_pin<0> LOC=G5;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<0> IOSTANDARD = LVCMOS25;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<0> PULLUP;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<0> SLEW = SLOW;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<0> DRIVE = 2;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<0> TIG;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<1> LOC=G6;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<1> IOSTANDARD = LVCMOS25;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<1> PULLUP;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<1> SLEW = SLOW;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<1> DRIVE = 2;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<1> TIG;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<2> LOC=A11;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<2> IOSTANDARD = LVCMOS25;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<2> PULLUP;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<2> SLEW = SLOW;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<2> DRIVE = 2;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<2> TIG;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<3> LOC=A12;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<3> IOSTANDARD = LVCMOS25;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<3> PULLUP;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<3> SLEW = SLOW;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<3> DRIVE = 2;
Net fpga_0_LEDs_4Bit_GPIO_IO_pin<3> TIG;


#### Module Push_Buttons_5Bit constraints

Net Push_Buttons_5Bit_GPIO_in_pin<0> LOC=B6;
Net Push_Buttons_5Bit_GPIO_in_pin<0> IOSTANDARD = LVCMOS25;
Net Push_Buttons_5Bit_GPIO_in_pin<0> PULLUP;
Net Push_Buttons_5Bit_GPIO_in_pin<0> SLEW = SLOW;
Net Push_Buttons_5Bit_GPIO_in_pin<0> DRIVE = 2;
Net Push_Buttons_5Bit_GPIO_in_pin<0> TIG;
Net Push_Buttons_5Bit_GPIO_in_pin<1> LOC=E9;
Net Push_Buttons_5Bit_GPIO_in_pin<1> IOSTANDARD = LVCMOS25;
Net Push_Buttons_5Bit_GPIO_in_pin<1> PULLUP;
Net Push_Buttons_5Bit_GPIO_in_pin<1> SLEW = SLOW;
Net Push_Buttons_5Bit_GPIO_in_pin<1> DRIVE = 2;
Net Push_Buttons_5Bit_GPIO_in_pin<1> TIG;
Net Push_Buttons_5Bit_GPIO_in_pin<2> LOC=A6;
Net Push_Buttons_5Bit_GPIO_in_pin<2> IOSTANDARD = LVCMOS25;
Net Push_Buttons_5Bit_GPIO_in_pin<2> PULLUP;
Net Push_Buttons_5Bit_GPIO_in_pin<2> SLEW = SLOW;
Net Push_Buttons_5Bit_GPIO_in_pin<2> DRIVE = 2;
Net Push_Buttons_5Bit_GPIO_in_pin<2> TIG;
Net Push_Buttons_5Bit_GPIO_in_pin<3> LOC=F10;
Net Push_Buttons_5Bit_GPIO_in_pin<3> IOSTANDARD = LVCMOS25;
Net Push_Buttons_5Bit_GPIO_in_pin<3> PULLUP;
Net Push_Buttons_5Bit_GPIO_in_pin<3> SLEW = SLOW;
Net Push_Buttons_5Bit_GPIO_in_pin<3> DRIVE = 2;
Net Push_Buttons_5Bit_GPIO_in_pin<3> TIG;
Net Push_Buttons_5Bit_GPIO_in_pin<4> LOC=E7;
Net Push_Buttons_5Bit_GPIO_in_pin<4> IOSTANDARD = LVCMOS25;
Net Push_Buttons_5Bit_GPIO_in_pin<4> PULLUP;
Net Push_Buttons_5Bit_GPIO_in_pin<4> SLEW = SLOW;
Net Push_Buttons_5Bit_GPIO_in_pin<4> DRIVE = 2;
Net Push_Buttons_5Bit_GPIO_in_pin<4> TIG;

 What should I do to rectify this problem, in such when I push the button , the particular LED should light up ?

 

Thank you

0 Kudos
3 Replies
Contributor
Contributor
4,856 Views
Registered: ‎09-14-2008

Re: LED Problem( When Press Push Button, no LED light up)

Hi

 

i think your failure is here:

  XGpio_SetDataDirection(&led,1,0x0);

   XGpio_SetDataDirection(&Push,1,0xffffffff);

 

Here you declare the Direction of the LED-Port as INput. You have to insert 0x0000 instead of 0xffffffff.

 

Greetings

 

M.Rapp

0 Kudos
Contributor
Contributor
4,855 Views
Registered: ‎09-14-2008

Re: LED Problem( When Press Push Button, no LED light up)

Sorry. Forget it. I looked false
0 Kudos
Explorer
Explorer
4,834 Views
Registered: ‎12-06-2007

Re: LED Problem( When Press Push Button, no LED light up)

Good morning,

 

I know for printf is xil_printf , but what is for scanf? 

 

Thank you

0 Kudos