D Flip flop using matlab code(not simulink)

7 vues (au cours des 30 derniers jours)
V V arfitha
V V arfitha le 27 Mai 2021
Modifié(e) : V V arfitha le 28 Mai 2021
I wrote a function to implement d flip flip (using nand gates and hence used the ~(a&b)operation in matlab) .I get an error during execution of my function.What caused it and how do I fix it?
[x,y] = dflipflop(1101101101,1010101010)
Unrecognized function or variable 'q1'.
Error in dflipflop (line 9)
g4 = ~(g1 & q1);
This is the function:
function [Q1,q1] = dflipflop(d,clk)
%dflipflop Summary of this function goes here
% Detailed explanation goes here
% Q1 = d;
% q1 = clk;
g1 = ~(d & clk);
d_not = not(d);
g3 = ~(clk & d_not);
g4 = ~(g1 & q1);
g5 = ~(g3 & Q1);
Q1= g4;
q1 = g5;
end
The circuit diagram that I tried to realize is:
I am using MATLAB Online version.
I needed to use the output q1(from previous stage) to calculate the present output.I actally want to input signals(digital) to the flipflop unit .Is there a way of doing the same?
I am fairly new to Matlab.
  1 commentaire
Rafael Hernandez-Walls
Rafael Hernandez-Walls le 27 Mai 2021
In this line:
g4 = ~(g1 & q1);
You need to declare before the variable q1

Connectez-vous pour commenter.

Réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 27 Mai 2021
Hi,
Here is the fixed code:
[x,y] = dflipflop(1101101101,1010101010)
function [Q1,q1] = dflipflop(d,clk)
%dflipflop Summary of this function goes here
% Detailed explanation goes here
% Q1 = d;
% q1 = clk;
g1 = ~(d & clk);
d_not = not(d);
g3 = ~(clk & d_not);
g4 = ~(g1 & g1);
g5 = ~(g3 & g4);
Q1= g4;
q1 = g5;
end
  1 commentaire
V V arfitha
V V arfitha le 28 Mai 2021
Actally i needed to use the output q1(from previous stage) to calculate the present output.so i think g4 = ~(g1 & g1); this may not be the correct logic.
In such cases do we need to use recurrsive function?

Connectez-vous pour commenter.

Catégories

En savoir plus sur General Applications dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by