On 2007-08-24 11:12, as wrote:
Hi folks,
am a newbie in C++ world. Normally I use matlab more often. But right
now I want to create a Rising Edge
D Flip-Flop model which has two Digital inputs, i.e. INPUTDATA and a
CLOCK. The functionality of Rising Edge D Flip Flop is that whenever a
rising edge of CLOCK signal will occur ( Rising Edge : 0 to 1 ) the
output will be the similar state of INPUTDATA signal, otherwise (if it
will be not a rising edge and CLOCK signal is 0 or 1) then the present
output will be the Previous state of the output.
I am facing the problem in case of accessing the previous values.
If you people have any suggestion please let me know.
You need a class to represent the flip-flip, you need to keep track of
three things, the current state of the flip-flip, the current state of
the input data, and the current clock state. Three bool variables will do.
Then you need a method the tell the flip-flip that the input data has
changed, it should look something like this
void setInput(bool input)
and a method to signal a change in the clock
void clock(bool clock)
and lastly some way to read the state from the flip-flop
bool getState()
The magic should happen in the clock() method, in there you check if the
clock-state is changed since the last call of clock(), and if it is,
check if the state changed from 0 to 1, in which case the state of the
flip-flop should be set to the state of the input.
--
Erik Wikström