Concept Flow - T flip-flop behavior
Start
Clock Edge?
No→Wait
Yes
Check T Input
T=0
Q=Q
Output Q
Wait for next clock
On each clock edge, if T is 0, output Q stays the same; if T is 1, output Q toggles.
always @(posedge clk) begin if (T == 1) Q <= ~Q; else Q <= Q; end
| Step | Clock Edge | T Input | Previous Q | Action | New Q |
|---|---|---|---|---|---|
| 1 | Yes | 0 | 0 | Q stays the same | 0 |
| 2 | Yes | 1 | 0 | Q toggles | 1 |
| 3 | Yes | 1 | 1 | Q toggles | 0 |
| 4 | Yes | 0 | 0 | Q stays the same | 0 |
| 5 | No | 1 | 0 | No clock edge, no change | 0 |
| Variable | Start | After 1 | After 2 | After 3 | After 4 | After 5 |
|---|---|---|---|---|---|---|
| Q | 0 | 0 | 1 | 0 | 0 | 0 |
| T | 0 | 0 | 1 | 1 | 0 | 1 |
| Clock Edge | N/A | Yes | Yes | Yes | Yes | No |
T Flip-Flop Behavior in Verilog: - On rising clock edge, check T input. - If T=0, Q holds its value. - If T=1, Q toggles (0->1 or 1->0). - No clock edge means no change. - Code: always @(posedge clk) if (T) Q <= ~Q; else Q <= Q;