Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20688 Discussions

Simple Key-Led design does not work

Altera_Forum
Honored Contributor II
1,167 Views

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! 

 

Andreas
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
325 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
325 Views

Hello aprado 

 

Thank you for your help. It isreally frustrating ans as you say weird:) 

 

I also tested with registering but no success: 

module 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  

 

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 

 

Andreas
0 Kudos
Altera_Forum
Honored Contributor II
325 Views

Try to do like this 

 

input switch; input clk; output reg led; always@(posedge clk) begin if(switch) led <= 1; else led <=0; end
0 Kudos
Altera_Forum
Honored Contributor II
325 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
325 Views

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
0 Kudos
Reply