Class: Circuits::Component::D

Inherits:
Base
  • Object
show all
Defined in:
lib/circuits/component/d.rb

Overview

Positive edge triggered D-type flip flop

Instance Attribute Summary

Attributes inherited from Base

#inputs, #outputs

Instance Method Summary collapse

Methods inherited from Base

#[], #tock

Constructor Details

#initializeD

Returns a new instance of D.



8
9
10
11
12
13
14
15
16
# File 'lib/circuits/component/d.rb', line 8

def initialize
  super(port_mappings: { d: { type: :input, number: 0 },
                         clk: { type: :input, number: 1 },
                         q: { type: :output, number: 0 },
                         not_q: { type: :output, number: 1 } })
  create_sub_components
  link_sub_components
  reset
end

Instance Method Details

#tickObject

Computes the outputs based on the inputs and previous state



19
20
21
22
23
24
# File 'lib/circuits/component/d.rb', line 19

def tick
  3.times.each do
    sub_components.each(&:tick)
    sub_components.each(&:tock)
  end
end