Altera_Forum
Honored Contributor
10 years agoA very simple problem about FPGA I/O Status
Hi All,
Thanks in advance for your time and possible efforts here. What I want to do is to monitor a push button. When it is pushed, its related signal changes from H to L, and light on a LED. After the LED is ON for certain period, turn it OFF. The code is very short, which is listed here: --------------------------------------------------------------------------------- module PushButtomDetect( input Start, /* Start is the signal of Push Button */ input CLK, /* 50Mhz */ output reg Start_Detect_LED); /* connected to drive LED */reg [3:0] Start_Monitor; reg Start_Flag = 0; reg [27:0] DelayCounter; always @(posedge CLK) begin Start_Monitor[0] <= Start; Start_Monitor[3:1] <= Start_Monitor[2:0]; Start_Flag <= Start_Monitor[3]&(~Start_Monitor[2]); /* Monitor H to L Transition */ if(Start_Flag == 1) Start_Detect_LED <= 1; /* LED is ON when Start has a Negative edge */ if(Start_Detect_LED == 1) /* LED is turned OFF when it has been ON for 1 second */ begin DelayCounter <= DelayCounter + 1; if(DelayCounter == 28'b0011_0010_0000_0000_0000_0000_0000) begin DelayCounter <= 28'b0000_0000_0000_0000_0000_0000_0000; Start_Detect_LED <= 0; end end end endmodule ------------------------------------------------------------------------------------------------ start is the signal from push button sw0, which is pulled up by on-board resistor. for this code, everything works as expected. When [/B]I programmed the code into chip, the LED is OFF, [/B]and after I push the button, LED is ON, after 1 second, it is OFF. Fine! However, if I commented the paragraph used to turn off the LED, which is like: ------------------------------------------------------------------------------------------------------- // if(Start_Detect_LED == 1) /* LED is turned OFF when it has been ON for 1 second */ // begin // DelayCounter <= DelayCounter + 1; // if(DelayCounter == 28'b0011_0010_0000_0000_0000_0000_0000) // begin // DelayCounter <= 28'b0000_0000_0000_0000_0000_0000_0000; // Start_Detect_LED <= 0; // end // end ------------------------------------------------------------------------------------------------------ something strange to me happens. when i programmed the code into chip, the led is on immediately after the program process finishes, without push on the button.
I know the status of FPGA would be uncertain during startup. But what is the exact reason here? Thanks~~