Method: HDLRuby::High::Std#make_2edge_clock
- Defined in:
- lib/HDLRuby/std/clocks.rb
#make_2edge_clock(event, times) ⇒ Object
Creates a clock inverted every +times+ occurence of an +event+ and its everted.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/HDLRuby/std/clocks.rb', line 119 def make_2edge_clock(event,times) clock = nil # The resulting clock # Enters the current system HDLRuby::High.cur_system.open do # Ensure times is a value. times = times.to_value if (times == 1) then AnyError.new("Clock multiplier must be >= 2.") end # Create the event counter. # Create the name of the counter. name = HDLRuby.uniq_name # Declare the counter. if @@__clocks_rst then # There is a reset, so no need to initialize. [times.width].inner(name) else # There is no reset, so need to initialize. [times.width].inner(name => 0) end # Get the signal of the counter. counter = get_inner(name) # Create the inverted event counter. # Create the name of the counter. name = HDLRuby.uniq_name # Declare the counter. if @@__clocks_rst then # There is a reset, so no need to initialize. [times.width].inner(name) else # There is no reset, so need to initialize. [times.width].inner(name => 0) end # Get the signal of the counter. counter_inv = get_inner(name) # Create the clock. # Create the name of the clock. name = HDLRuby.uniq_name # Declare the clock. if @@__clocks_rst then # There is a reset, so no need to initialize. bit.inner(name) else # There is no reset, so need to initialize. bit.inner(name => 0) end # Get the signal of the clock. clock = get_inner(name) # Control the even counter. par(event) do if @@__clocks_rst then hif(@@__clocks_rst) { counter <= 0 } helsif(counter == times-1) { counter <= 0 } helse { counter <= counter + 1 } else hif(counter == times-1) { counter <= 0 } helse { counter <= counter + 1 } end end # Control the odd counter. par(event.invert) do if @@__clocks_rst then hif(@@__clocks_rst) { counter_inv <= 0 } helsif(counter == times-1) { counter_inv <= 0 } helse { counter_inv <= counter_inv + 1 } else hif(counter == times-1) { counter_inv <= 0 } helse { counter_inv <= counter_inv + 1 } end end clock <= ((counter > (times/2)) | (counter_inv > (times/2))) end # Return the clock. return clock end |