Home    Bloggers    Messages    Webinars    Resources   
Tw  |  Fb  |  In  |  Rss
Duane Benson

Discovering FPGAs: Using the SPI Interface, Part 3

Duane Benson
devel@latke.net
devel@latke.net
12/11/2012 10:14:49 PM
User Rank
Guru
Re: Are we having fun yet?
"On the one hand, it seems like an FPGA should be configurable with an initial power-up state" - Originally, I was thinking in therms of having, say, an MCU on the same PCB as an FPGA. If the MCU is ready first, it might be confused by the FPGA start up port values. However, it's easy enough to just have the MCU wait until the FPGA is up before trying to talk to it.


That's something I do all the time -- micro and FPGA talking to each other.

You can avoid confusing the micro if you are careful, and that's easy to do. First, the Xilinx FPGAs have a pin called HSWAPEN or PUDC (depending on family) which control whether the FPGA's user I/O are tristated or weakly pulled up during configuration. Set this to whichever makes sense for the application.

Most micros have enough port i/O pins available so you can dedicate one to an "FPGA valid" signal from the FPGA. That pin will have some undriven (by the FPGA) state based on HSWAPEN and any external pullup/pulldown you might have. When the FPGA finishes configuration and it's ready for action (which might mean waiting until a DCM locks or whatever) the FPGA will drive that signal to whatever state you call "active."

The micro can then spin on that signal after booting, or whatever.

Lots of ways to deal with this, all of which are application-dependent.

100%
0%
Duane Benson
Duane Benson
12/11/2012 4:42:35 PM
User Rank
Blogger
Re: Are we having fun yet?
"On the one hand, it seems like an FPGA should be configurable with an initial power-up state" - Originally, I was thinking in therms of having, say, an MCU on the same PCB as an FPGA. If the MCU is ready first, it might be confused by the FPGA start up port values. However, it's easy enough to just have the MCU wait until the FPGA is up before trying to talk to it.

50%
50%
devel@latke.net
devel@latke.net
12/11/2012 2:00:30 PM
User Rank
Guru
Re: Are we having fun yet?
On the one hand, it seems like an FPGA should be configurable with an initial power-up state, but when I remind myself that the FPGA knows nothing until its bitstream has been loaded at turn-on, it becomes moot. It's better practice anyway to just design the whole system to deal with unknown states at power up.

You have to remember that asserting PROGRAM_B to force reconfiguration of a Xilinx FPGA is essentially an FPGA global reset. So when configuration completes, it is perfectly reasonable to assume that it has been reset in the logic sense. As such, initializers as part of signal declarations are an excellent tool to use.

We typically use a reset supervisor to control PROGRAM_B. Obviously it makes good sense to wait until power supplies are stable before allowing configuration to start. There's no point in adding another reset supervisor to control an FPGA's global (designed-in) reset for obvious reasons. Also a situation which requires a full FPGA reset most likely requires full reconfiguration. 

So unless there is some Real Good Reason to provide a full-chip logic reset in addition to what you get from reconfiguration, you don't ned that full-chip reset.

That doesn't mean that localized resets for blocks of logic are not necessary; often they are needed and you should provide them if so. One might use a DCM's locked output signal is a reset; if the clock isn't valid the logic isn't either so this makes sense. (You might want to push the DCM locked signal into a shortish shift register and use the shift register output as a synchronous reset. Whatever.)


HAVING SAID ALL OF THAT: Jez is absolutely correct in that some FPGA families (such as Actel; I recently did a ProASIC-3L design) don't have this sort of end-of-configuration reset. The thing with the Actel flash-based FPGAs is that they configure essentially immediately after power-up, and yes, all of the logic blocks come up as zero, so using a reset supervisor to drive a global reset net makes sense.  The reset supervisor guarantees that the logic reset remains asserted long after the supplies have stabilized and the FPGA configures.

So -- does using an initializer in this way make the code less portable? Probably. Does this matter? Likely not. Any organization with a proper source-code control system can track different versions of a module without much trouble.

50%
50%
Duane Benson
Duane Benson
12/11/2012 10:29:56 AM
User Rank
Blogger
Re: Are we having fun yet?
Jezmo - That makes sense. I do recall reading about sim and pre-setting non-zero values.

On the one hand, it seems like an FPGA should be configurable with an initial power-up state, but when I remind myself that the FPGA knows nothing until its bitstream has been loaded at turn-on, it becomes moot. It's better practice anyway to just design the whole system to deal with unknown states at power up.

50%
50%
JezmoSSL
JezmoSSL
12/11/2012 7:39:11 AM
User Rank
Blogger
Re: Are we having fun yet?
Yeah it is kind of variable as to which tools and devices allow you to do that I have been working with actel devices recently which do have issues with defining initial values And its always good to have a signal you can wiggle to set everythin to a known state

50%
50%
MartinThompson
MartinThompson
12/11/2012 7:26:59 AM
User Rank
Clever Clogs
Re: Are we having fun yet?
Not true anymore - XST at least can take the init value and put it in the bitstream so that when the FPGA comes out of init, the FFs have the correct initialisation to match the simulation behaviour.

It's been this way since at least ISE 10.  See page 462 of the old user manual:

http://www.xilinx.com/itp/xilinx10/books/docs/xst/xst.pdf

When you give a register an initial value in a declaration, XST sets this value on the output of the register at global reset, or at power up. The assigned value is carried in the NGC file as an INIT attribute on the register, and is independent of any local reset. 

 

50%
50%
JezmoSSL
JezmoSSL
12/11/2012 2:33:49 AM
User Rank
Blogger
Re: Are we having fun yet?
Duane,

what you find is if you define a signal with an initial non-zero value like this

signal :blah stg_logic_vetor(3 downto 0):="1001";

 

then it will get set to that value in simulation, but in the actual hardware, part of the configuration cycle in the FPGA is that all registers which can be are reset to 0, this happens before the logic is actualy running and responding to input signals.So if you want to have registers start with some non-zero value, usualy you define a 'reset' signal which isnt really a reset, which is designed to come up some time after the logic has been configured and is running, which acts to set any registers whch need to be set.

 

you will find that ISE mumbles about this and tells you that registers are all starting at zero.

50%
50%
Duane Benson
Duane Benson
12/10/2012 9:25:09 PM
User Rank
Blogger
Re: Are we having fun yet?
Max - I am having a lot of fun with this. Much of the digital logic knowledged that I'm drawing on comes from waaaay back. But there's some good stuff under all those cob webs.

100%
0%
hamster
hamster
12/10/2012 6:47:40 PM
User Rank
Blogger
Little nitpick...
Hi Duane! I don't know Verilog, but I'll try to code for it...

I usually structure my code like this:
if (SPI_clk_div[8:0] == 9'b111110011) begin
   spi_clk <= ~spi_clk; // Toggle spi clock every tick
   SPI_clk_div[8:0] <= 9'b000000000;
else
   SPI_clk_div <= SPI_clk_div + 1;
end

This makes it obvious that the counter only gets incremented when it is not at its terminal count, and at its termainal count it gets reset. This reminds me of the "default assignment are good / bad" holy wars earlier on...

I used 111110011 rather than 111110100 in my example, as you want your counter to go from 0 to 499, not 0 to 500. The "if" will be using the original value of SPI_clk_div, not the incremented one assigned on the line before....

 

 

50%
50%
Max Maxfield
Max Maxfield
12/10/2012 5:30:58 PM
User Rank
Blogger
Are we having fun yet?
Hi Duane -- I get the impression that you are having a lot of fun learning all of thi sstuff and implementing things like your own SPI core from scratch -- I hope this is the case (that you are indeed enjoying yourself :-)

50%
50%
More Blogs from Duane Benson
Duane has decided that the time is ripe to get his ZedBoard bolted onto his robot with a Linux distribution up and running. That was the ultimate plan anyway, so why wait?
Now it's time to delve deeper into the state machine I'm using to control my I2C interface.
The three states associated with bi-directional "inout" pins can cause confusion for the unwary.
It's time to jump into unexplored territory -- the state machine that will control Duane Benson's I2C interface.
We're now ready for the I2C master to transmit a command set to a remote device.
flash poll
follow us on twitter
follow Xilinx on twitter
like us on facebook
like Xilinx on facebook
All Programmable Planet     About Us     Contact Us     Help     Register     Twitter     Facebook     RSS