Endymion
Junior Member level 3
- Joined
- Nov 18, 2011
- Messages
- 29
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,611
library ieee;
use ieee.std_logic_1164.all;
entity PISO is
port(CLK, SI, nCS : in std_logic;
outpin: out std_logic;
PI : in std_logic_vector(7 downto 0);
SO : out std_logic);
end PISO;
architecture archi of PISO is
signal tmp: std_logic_vector(PI'high downto PI'low);
signal bitOut: std_logic;
begin
process (CLK,nCS)
begin
if (nCS='1') then
tmp <= "10101111";
elsif falling_edge(CLK) then
tmp <= tmp(PI'high -1 downto PI'low) & '0';
end if;
end process;
SO <= tmp(PI'high) when nCS = '0' else 'Z';
outpin <= '1';
end archi;
Second,
why do you use falling edge registers?
third,
nCS, is used as a reset.
I wouldn't do that. a reset signal has a very important role in a synchronous design and it's global (same as clock).
You should use unsigned and signed types instead of std_logic_vector
Because I would like the output to change at the falling edge. This is because the microcontroller is operating at Mode 0 (CPHA = 0 and CPOL = 0) which samples the MISO line at the rising edge.
process (CLK,RST)
begin
if (RST='1') then
tmp <= "10101111";
elsif rising_edge(CLK) then
if nCS = '1' then
tmp <= "10101111";
elsif falling_edge(SCK) then
tmp <= tmp(PI'high -1 downto PI'low) & '0';
end if;
end if;
end process;
Thank you very much. I will simulate this to understand this better. I have one question - and I know this is a very stupid question - but why do I need a global clock? The CPLD works just fine without a GCLK and it utilizes the SCK for shifting the bits out.
Primitive is probably not the right description, it's just that the situations where simply using the SPI clock are actually useful can be somewhat limited. Because of your simplified first attempt at this, you are not appreciating the troubles that you will run into if you try to expand your design to include other functions as I mentioned above.I understand this is a very primitive approach, but I'm trying to understand why is it so primitive?
- As you coded it, it appears your plan is to be sampling 'PI' as part of the async 'reset' time when CS is high. OK, but now think about what this will mean in the implementation. You will have a register with a clock connected to SPI clock; there will need to be asynchronous reset AND preset signals for each bit. There will have to be logic to create these signals, any inadvertant glitch on that logic signal (which you have no control of inside the device) and you'll incorrectly set or clear a bit. You might get it to work, but it would be dicey, you would want to test it over the full temperature and voltage range...and you'd likely have to keep repeating that test every time you change the overall design (not just the SPI portion) because you won't have any real guarantees that something didn't change in the routing.
2. Maybe you want to use this controller to collect data from the SPI controller via SI. Here are some implications of simply using SPI clock
- OK, but again there will be some receiver of the collected data and that receiver will be seeing those bits changing to intermediate values while you're shifting in a new word.
- Does the receiver need to know that you've updated the word? If so, how?
- The receiver of the word is probably running on some other clock, so the output data would need to be synchronized to that clock. If you have multiple receivers they would each have to synchronize it. However, if the SPI controller had access to the clock that everybody else in the design was using, it could simply synchronize it once for all.
Is the nCS of the other CPLD the same nCS of your SPI controller? If so, then yes you should be OK since that will prevent PI from changing while it is being shifted out. It does bring into question though why you have a CPLD to convert a serial stream into parallel and then this controller which then converts the parallel back into serial...but that's a different topic, presumably something else on the board needs to work with the parallel PI at some point.This is something I didn't understand from your post. I am sampling PI whenever nCS is high and PI will be stable the entire time the bits are being shifted out. PI actually comes from a another CPLD which is configured as a Serial In Parallel Out shift register. That CPLD will hold PI till it's nCS goes low and new data is shifted in. When nCS goes back high it will change PI to newly shifted in data.
The 'receiver' is whatever other logic you have in this design that would then work with the data that you collect. For example, let's say the SPI controller shifts in 8 bits to you via SI. You dutifully convert that into an 8 bit number call it 'XYZ' and that 'XYZ' is an output of your SPI controller entity. Presumably there is some other entity in the design that will take 'XYZ' and do something with it; that other entity would be the thing that is the receiver of 'XYZ'.I am sorta confused on what you meant by "receiver" in the above. Eventually, I would like to transfer some data to this SPI slave, yes. But I lose you when you say there will be some receiver of the collected data.
I assume by receiver you meant the shift registered I talked about in the first post?
If you're not going to use it then why would you collect it? What you're saying then is that the 'XYZ' signal that I mentioned above and would then be the output of your SPI controller entity would be left unconnected. If that is the really the case, then synthesis would completely remove 'XYZ' since it is not used.If so, data/instructions that I will send to this device will not be passed on anywhere else at all.
Is the nCS of the other CPLD the same nCS of your SPI controller? If so, then yes you should be OK since that will prevent PI from changing while it is being shifted out. It does bring into question though why you have a CPLD to convert a serial stream into parallel and then this controller which then converts the parallel back into serial...but that's a different topic, presumably something else on the board needs to work with the parallel PI at some point.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?