Advertisement
Guest User

EPM240t100C5N 7 Segment Counter

a guest
Nov 11th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. // Code modified from examples found at: http://fpga4fun.com/Opto3.html.
  2.  
  3. module seg7(
  4. input clk,
  5. output segA, segB, segC, segD, segE, segF, segG, segDP, seg1
  6. );
  7.  
  8. // cnt is used as a 24 bit prescaler with a 50MHz global clock in at PIN_12.
  9. // Updates the clock roughly 3 times a second.
  10. reg [23:0] cnt;
  11. always @(posedge clk) cnt <= cnt+24'h1;
  12. wire cntovf = &cnt;
  13.  
  14. // BCD is a counter that counts from 0 to 9
  15. reg [3:0] BCD;
  16. always @(posedge clk) if(cntovf) BCD <= (BCD==4'h9 ? 4'h0 : BCD+4'h1);
  17.  
  18. // 9 bit array to hold data for each 7 seg display.
  19. // There are 8 seven segment displays on the EPM240T100C5N.
  20. // Each display has a PNP driver to turn the display on/off.
  21. // The 8 leftmost bits set each segment either on or off.
  22. // The rightmost bit turns the PNP driver on or off.
  23. // Do a bitwise negate (~) on the array since the segments are all active low.
  24. // They turn on when they are connected to ground.
  25.  
  26. reg [8:0] SevenSeg;
  27. always @(*)
  28. case(BCD)
  29. 4'h0: SevenSeg = ~9'b111111001;
  30. 4'h1: SevenSeg = ~9'b011000001;
  31. 4'h2: SevenSeg = ~9'b110110101;
  32. 4'h3: SevenSeg = ~9'b111100101;
  33. 4'h4: SevenSeg = ~9'b011001101;
  34. 4'h5: SevenSeg = ~9'b101101101;
  35. 4'h6: SevenSeg = ~9'b101111101;
  36. 4'h7: SevenSeg = ~9'b111000001;
  37. 4'h8: SevenSeg = ~9'b111111101;
  38. 4'h9: SevenSeg = ~9'b111101101;
  39. default: SevenSeg = ~9'b000000001;
  40. endcase
  41.  
  42. assign {segA, segB, segC, segD, segE, segF, segG, segDP, seg1} = SevenSeg;
  43. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement