Forum Discussion
Altera_Forum
Honored Contributor
15 years agoSimple Key-Led design does not work
Hello
Im using a EPM3064ATC CPLD. My design has 8 switches and two leds. If a button is pressed, then a led should be on. I already tested different variants of code but had no sucess. Attached my code:
module TestSwitch (clk, Switch, Led);
input clk;
input Switch;
output Led;
assign Led = (Switch != 0 ); // switch led on if a button is pressed
assign Led = (Switch | Switch); // same
end
I already tested alll switches by the command:
assign Led = Switch;This design works well with my hardware. So the pin assignment should be ok. I also tried another version with a Block diagram / schematics file using an or8. Same effect. Thank you for your help! Andreas5 Replies
- Altera_Forum
Honored Contributor
Solved, thank you very much for your fast help:):)!!!
Ovs' hint helped!!!!!! Switches and Leds are acitve low. Andreas Now, it's time for a coffe - Altera_Forum
Honored Contributor
Also check the logic levels your switches/leds are using. Often switches have pullups and pulls the signal to GND when pressed. The led could also be connected between VCC and the FPGA output - i.e. ligth when the output is 0. If this is the case you would see the behaviour you describe since you have implemented two "or" functions. Negating all inputs and outputs gives and "and" function instead. Easily tested by pushing all switches - your leds should ligth then.
Regards, Ove Brynestad - Altera_Forum
Honored Contributor
Try to do like this
input switch; input clk; output reg led; always@(posedge clk) begin if(switch) led <= 1; else led <=0; end - Altera_Forum
Honored Contributor
Hello aprado
Thank you for your help. It isreally frustrating ans as you say weird:) I also tested with registering but no success:
Both Leds and all keys are ok as i can control the leds by every key using statement e.g.: assign Led[1] = Switch[1]; assign Led[1] = Switch[2]; assign Led[1] = Switch[3]; ... It seems that signal tap is not supported for this device. Friendly regards Andreasmodule TestSwitch (clk, Switch, Led); input clk; input Switch; output Led; reg Keys; @always @(Switch) Keys = Switch; assign Led = (Keys | Keys); // does not work assign Led = Keys; // that works end - Altera_Forum
Honored Contributor
This is really weird.. try to register the switch and check at each posedge clk (it should work even w/o registering)
Maybe your led or your button is broken? Try to use signal tap and see if those signals are right, also double check your pin assignment