--This code takes in what the user selcted via the switches the BPM and what time Sig and a CLk signal and changes the LED to the correct timing --@author Sam Malicoat, Ryan Kendall library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity LedFlip is Port ( BPM : in STD_LOGIC_VECTOR(6 downto 0); TimeSig : in STD_LOGIC; Tick : in STD_LOGIC; LED : out STD_LOGIC_VECTOR (15 downto 0)); end LedFlip; architecture Behavioral of LedFlip is Signal sLed:STD_LOGIC_VECTOR(15 downto 0); Signal Invert:STD_LOGIC:='0'; Signal temp:STD_LOGIC_VECTOR(23 downto 0); Signal CLKTICK:STD_LOGIC; shared variable freq:integer; Signal Enable:STD_LOGIC; begin --With invert changing the leds count up using the on led as the highlet led and counting down using the off led as the highlighted led Led(7 downto 0)<=sLed(7 downto 0) xor Invert&Invert&Invert&Invert&Invert&Invert&Invert&Invert; Led(15 downto 8)<=sLed(15 downto 8); process(BPM) is variable num:integer:=0; begin num:= to_integer(unsigned(BPM)); Enable<='1'; --We tried using a division loop to calculate how long the wait should be but this would not snythasis becaues the for loop required was so big so we --hard coded each case from 1 to 127. with the user selecting 0 (all switches down) as the metronome being off case(num)is --when 1 => freq:= 300000000; --when 2 => freq:= 150000000; --when 3 => freq:= 100000000; --when 4 => freq:= 75000000; --when 5 => freq:= 60000000; --when 6 => freq:= 50000000; --when 7 => freq:= 42857143; --when 8 => freq:= 37500000; --when 9 => freq:= 33333333; --when 10 => freq:= 30000000; --when 11 => freq:= 27272727; --when 12 => freq:= 25000000; --when 13 => freq:= 23076923; --when 14 => freq:= 21428571; --when 15 => freq:= 20000000; --when 16 => freq:= 18750000; --when 17 => freq:= 17647059; --when 18 => freq:= 16666667; --when 19 => freq:= 15789474; --when 20 => freq:= 15000000; --when 21 => freq:= 14285714; --when 22 => freq:= 13636364; --when 23 => freq:= 13043478; --when 24 => freq:= 12500000; --when 25 => freq:= 12000000; --when 26 => freq:= 11538462; --when 27 => freq:= 11111111; --when 28 => freq:= 10714286; --when 29 => freq:= 10344828; --when 30 => freq:= 10000000; --when 31 => freq:= 9677419; --when 32 => freq:= 9375000; --when 33 => freq:= 9090909; --when 34 => freq:= 8823529; --when 35 => freq:= 8571429; --when 36 => freq:= 8333333; --when 37 => freq:= 8108108; --when 38 => freq:= 7894737; --when 39 => freq:= 7692308; --when 40 => freq:= 7500000; --when 41 => freq:= 7317073; --when 42 => freq:= 7142857; --when 43 => freq:= 6976744; --when 44 => freq:= 6818182; --when 45 => freq:= 6666667; --when 46 => freq:= 6521739; --when 47 => freq:= 6382979; --when 48 => freq:= 6250000; --when 49 => freq:= 6122449; --when 50 => freq:= 6000000; --when 51 => freq:= 5882353; --when 52 => freq:= 5769231; --when 53 => freq:= 5660377; --when 54 => freq:= 5555556; --when 55 => freq:= 5454545; --when 56 => freq:= 5357143; --when 57 => freq:= 5263158; --when 58 => freq:= 5172414; --when 59 => freq:= 5084746; when 60 => freq:= 5000000; when 61 => freq:= 4918033; when 62 => freq:= 4838710; when 63 => freq:= 4761905; when 64 => freq:= 4687500; when 65 => freq:= 4615385; when 66 => freq:= 4545455; when 67 => freq:= 4477612; when 68 => freq:= 4411765; when 69 => freq:= 4347826; when 70 => freq:= 4285714; when 71 => freq:= 4225352; when 72 => freq:= 4166667; when 73 => freq:= 4109589; when 74 => freq:= 4054054; when 75 => freq:= 4000000; when 76 => freq:= 3947368; when 77 => freq:= 3896104; when 78 => freq:= 3846154; when 79 => freq:= 3797468; when 80 => freq:= 3750000; when 81 => freq:= 3703704; when 82 => freq:= 3658537; when 83 => freq:= 3614458; when 84 => freq:= 3571429; when 85 => freq:= 3529412; when 86 => freq:= 3488372; when 87 => freq:= 3448276; when 88 => freq:= 3409091; when 89 => freq:= 3370787; when 90 => freq:= 3333333; when 91 => freq:= 3296703; when 92 => freq:= 3260870; when 93 => freq:= 3225806; when 94 => freq:= 3191489; when 95 => freq:= 3157895; when 96 => freq:= 3125000; when 97 => freq:= 3092784; when 98 => freq:= 3061224; when 99 => freq:= 3030303; when 100 => freq:= 3000000; when 101 => freq:= 2970297; when 102 => freq:= 2941176; when 103 => freq:= 2912621; when 104 => freq:= 2884615; when 105 => freq:= 2857143; when 106 => freq:= 2830189; when 107 => freq:= 2803738; when 108 => freq:= 2777778; when 109 => freq:= 2752294; when 110 => freq:= 2727273; when 111 => freq:= 2702703; when 112 => freq:= 2678571; when 113 => freq:= 2654867; when 114 => freq:= 2631579; when 115 => freq:= 2608696; when 116 => freq:= 2586207; when 117 => freq:= 2564103; when 118 => freq:= 2542373; when 119 => freq:= 2521008; when 120 => freq:= 2500000; when 121 => freq:= 2479339; when 122 => freq:= 2459016; when 123 => freq:= 2439024; when 124 => freq:= 2419355; when 125 => freq:= 2400000; when 126 => freq:= 2380952; when 127 => freq:= 2362205; when others => freq:=10000000; Enable<='0'; --defaulted to off end case; end process; process (timeSig) is begin if(timeSig='0')then sLed(15 downto 8)<="11110000";--turn on 4 left most leds signafing 4/4 time else sLed(15 downto 8)<="11111110";--turn on 7 left most leds signafing 7/4 time end if; end process; process(Tick) is --Tick is piped to the CLk from Finial.vhd moduel variable count:integer:=0; variable target:integer:=0; variable CLKcount:integer:=0; begin if(rising_edge(Tick))then CLKcount:=CLKcount+1; -- else -- invert<='0'; -- sLed(7 downto 0)<="00000000"; end if; target:=freq+freq+freq+freq+freq; target:=target+target+target+target; if(CLKcount>target and Enable='1') then CLKcount:=0; count:=count+1; if(timeSig='0')then -- sLed(15 downto 8)<="11110000";--turn on 4 left most leds signafing 4/4 time if(count>7)then count:=0; end if; else -- sLed(15 downto 8)<="11111110";--turn on 7 left most leds signafing 7/4 time if(count>13)then count:=0; end if; end if; end if; if(TimeSig='0') then --4/4 time signature case (count) is when 0=> sLed(7 downto 0)<="00000001"; Invert<='0'; when 1=> sLed(7 downto 0)<="00000010"; Invert<='0'; when 2=> sLed(7 downto 0)<="00000100"; Invert<='0'; when 3 => sLed(7 downto 0)<="00001000"; Invert<='0'; when 4 => sLed(7 downto 0)<="00001000"; Invert<='1'; when 5 => sLed(7 downto 0)<="00000100"; Invert<='1'; when 6 => sLed(7 downto 0)<="00000010"; Invert<='1'; when 7 => sLed(7 downto 0)<="00000001"; Invert<='1'; when others=> sLed(7 downto 0)<="00000001"; Invert<='0'; count:=0; end case; else -- 7/4 time signature case (count) is when 0=> sLed(7 downto 0)<="00000001"; Invert<='0'; when 1=> sLed(7 downto 0)<="00000010"; Invert<='0'; when 2=> sLed(7 downto 0)<="00000100"; Invert<='0'; when 3 => sLed(7 downto 0)<="00001000"; Invert<='0'; when 4 => sLed(7 downto 0)<="00010000"; Invert<='0'; when 5 => sLed(7 downto 0)<="00100000"; Invert<='0'; when 6 => sLed(7 downto 0)<="01000000"; Invert<='0'; when 7=> sLed(7 downto 0)<="01000000"; Invert<='1'; when 8=> sLed(7 downto 0)<="00100000"; Invert<='1'; when 9=> sLed(7 downto 0)<="00010000"; Invert<='1'; when 10 => sLed(7 downto 0)<="00001000"; Invert<='1'; when 11 => sLed(7 downto 0)<="00000100"; Invert<='1'; when 12 => sLed(7 downto 0)<="00000010"; Invert<='1'; when 13 => sLed(7 downto 0)<="00000001"; Invert<='1'; when others=> sLed(7 downto 0)<="00000001"; Invert<='0'; count:=0; end case; end if; end process; end Behavioral;