This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
resources:char_drawer_serial [2020/06/04 14:05] nelson |
resources:char_drawer_serial [2020/06/08 10:55] (current) nelson |
||
---|---|---|---|
Line 56: | Line 56: | ||
// State Machine | // State Machine | ||
- | typedef enum logic[1:0] {A, B, C, D, ERR='X} StateType; | + | typedef enum logic[1:0] {ST_WAIT, ST_WAIT_SENT, ST_SENT, ST_DONE, ERR='X} StateType; |
StateType cs, ns; | StateType cs, ns; | ||
Line 79: | Line 79: | ||
always_ff @(posedge clk) | always_ff @(posedge clk) | ||
if (clrCnt) | if (clrCnt) | ||
- | cnt <= 0; | + | cnt <= 0; |
else if (incCnt) | else if (incCnt) | ||
cnt <= cnt + 1; | cnt <= cnt + 1; | ||
Line 94: | Line 94: | ||
done = 0; | done = 0; | ||
if (reset) | if (reset) | ||
- | ns = A; | + | ns = ST_WAIT; |
else case (cs) | else case (cs) | ||
- | A: begin | + | ST_WAIT: begin |
clrCnt = 1; | clrCnt = 1; | ||
if (enable) | if (enable) | ||
- | ns = B; | + | ns = ST_WAIT_SENT; |
else | else | ||
- | ns = A; | + | ns = ST_WAIT; |
end | end | ||
- | B: begin | + | ST_WAIT_SENT: begin |
send = 1; | send = 1; | ||
if (sent) | if (sent) | ||
- | ns = C; | + | ns = ST_SENT; |
else | else | ||
- | ns = B; | + | ns = ST_WAIT_SENT; |
end | end | ||
- | C: begin | + | ST_SENT: begin |
if (~sent && cnt != 15) begin | if (~sent && cnt != 15) begin | ||
incCnt = 1; | incCnt = 1; | ||
- | ns = B; | + | ns = ST_WAIT_SENT; |
end | end | ||
else if (~sent && cnt == 15) | else if (~sent && cnt == 15) | ||
- | ns = D; | + | ns = ST_DONE; |
else | else | ||
- | ns = C; | + | ns = ST_SENT; |
end | end | ||
- | D: begin | + | ST_DONE: begin |
done = 1; | done = 1; | ||
if (~enable) | if (~enable) | ||
- | ns = A; | + | ns = ST_WAIT; |
else | else | ||
- | ns = D; | + | ns = ST_DONE; |
end | end | ||
default: | default: |