Hi everyone,
I'm writing SPI-addressable memory that is synchronous to the SPI sck
clock signal.
So far, some components work as expected, but then cease working
depending on how I add to it.
Currently, I receive data over SPI with a shift register. I send data
over SPI with a shift register with asynchronous loading so that I can
preset the data to send.
The issue is in generating the signal to preset the data to send.
I'd like to preset the shift register with a new byte every time 8 bits
have passed along the spi bus while the CS line is pulled low. (aka, a
multi-byte transfer)
Here's the issue: the code below does just that with the "sendNewData"
signal. The problem is that it's very "sensitive to being changed."
1 | module dataCtrl(input logic cs, sck,
|
2 | output logic setNewData);
|
3 |
|
4 | logic [3:0] bitCount;
|
5 |
|
6 | assign andOut = bitCount[2] & bitCount[1] & bitCount[0];
|
7 |
|
8 |
|
9 | always_ff @ (negedge sck, posedge cs)
|
10 | begin
|
11 | if (cs)
|
12 | begin
|
13 | bitCount <= 3'b0000;
|
14 | setNewData <= 1'b1;
|
15 | end
|
16 | else
|
17 | begin
|
18 | bitCount <= bitCount + 3'b0001;
|
19 | setNewData <= andOut;
|
20 | end
|
21 | end
|
22 | endmodule
|
If I extend the width of the bitCount signal to 5 or more bits wide,
aka: change from
to
the code doesn't generate the signal at the right time, and I get data
transferred that is off by one. Does this make sense? I'd like to build
up this module to output other control signals, but I'm hinging my
design on being able to count past 8. Strangely enough, extending this
module in pretty-much any way that builds off of the existing components
reproduces this problem. Do adders need more than one clock cycle to add
if their signals are larger than 4 bits?
I've attached 3 files. The high-level working module. A detailed view of
that same module with the hardware used, and the detailed view of the
module with the larger bitCount signal that doesn't work. (Lastly, the
compiler optimizes away bitCount[3], which isn't used, although the
logic is different.)
Thanks a bunch for your thoughts and input!
Lastly: I'm using a ...
Altera Cyclone IV from a De0 Nano
Quartus II 13.1 Web Edition