* what clkout signal (waveform, voltages, frequency, duty cycle...) do you expect?
* and what do you see instead?
* show how you tried to achieve the desired result
* show what you have done to debug the problem, and the results.
What I expect is when SS=0,
the MOSI will output a bit of data in register, an then the clkout will output a 1'b1 and 1b0 as SPI rules.
Both MOSI and register pins output are as required, but nothing at clkout pin. Any wrong in the codes?
does absolutely nothing except assign clkout <= 1'b0 as a clock always block updates all the right hand sides of the assignments first and then after that is done applies the assignments to the left hand side. So in this case clkout only gets assigned with 1'b0, the clkout <= 1'b1 gets ignored.
- - - Updated - - -
Please don't try using blocking assignments and # delays to make it work (more software thinking bias).
does absolutely nothing except assign clkout <= 1'b0 as a clock always block updates all the right hand sides of the assignments first and then after that is done applies the assignments to the left hand side. So in this case clkout only gets assigned with 1'b0, the clkout <= 1'b1 gets ignored.
- - - Updated - - -
Please don't try using blocking assignments and # delays to make it work (more software thinking bias).
Thanks! I understand that the clkout <= 1'b1 gets ignored, so the output always 0.
But, I still can't fix it. How can I generate a high-then-low pulse after every output of the register[count],
so the SPI rules can be followed?
always @(posedge clk) begin
clkout <= !clkout;
end
***
but you need a counter to count from 0 to 7 for the bits to transmit... then use a 4 bit counter (at least) and use bit0 of the counter as clkout.
Because bit 0 toggles with every rising edge of the counter_clock.
! is a logical operator, the correct operator to invert the signal is actually ~. In this particular case they do the exact same thing, but I've seen people use the wrong operator on a bus and then they wonder why their code doesn't work correctly.
always @(posedge clk) begin
clkout <= !clkout;
end
***
but you need a counter to count from 0 to 7 for the bits to transmit... then use a 4 bit counter (at least) and use bit0 of the counter as clkout.
Because bit 0 toggles with every rising edge of the counter_clock.
Thanks for your suggestion. The thing is, I'd like to output clkout like b010 transition while transmitting the data in register in order to follow the SPI protocol. But, using bit0 of the counter as clkout only outputs a high or low not b010.
And a loop of posedge seems can only output one bit to clkout.
How can I modified my code?
Do you know how to do logic design? If you have any notes from any class on the subject you should reefer back to them.
You can create that sequence by making a truth table.
A better method would be to use an FSM to generate the entire transfer sequence.