State machine with stack to implement "subroutines"

Hi All,

Playing with the Spartan 3E Starter Kit reference designs, I've found the following "Exercise" in the "Initial Design - LCD Display Control).

Exercise: Implement a hardware state machine which can perform the LCD initialisation sequence. Compare the size of your implementation with the 96 slices required to implement a PicoBlaze processor.

Trying to implement a required state machine, I've found an idea which is quite interesting, but may also seem to be crazy: A state machine with "subroutines". The idea is to implement typical, often used state sequences as "subroutines", which may be "called" after pushing the next state to the stack. In the last state of the subrtoutine-sequence the next state is retrieved from the stack. It seems, that this approach may lead to relatively simple implementation of the complex state machines.

The sources may be found at "alt.sources" newsgroup as topic "FSM with state stack in VHDL", e.g. available via:

formatting link
(please switch to the "original message" to be able to save the shar archive containing the sources).

There are two implementations provided. One implements the stack in registers, but "return" requires only a single cycle. The another one uses additional clock cycle, to simplify access to the stack, which allows XST to implement the stack in the inferred RAM.

The resulting code requires 159 slices in version with stack in inferred RAM, or 189 slices in the version with stack implemented in registers.

The code heavily uses VHDL procedures, but synthesizes correctly with XST. I have also a version, where procedures are replaced with M4 macros, so you can generate the "procedure-free" VHDL for less advanced synthesis tools.

The code is published as public domain. Maybe someone will find this idea useful?

The sources contain also the GHDL testbench: lcd_test_tb.vhd, and the shell script needed to run it. If you are going to run the simulation however, change the definition of the T_CLK from: constant T_CLK : integer := 20; to: constant T_CLK : integer := 2000; Otherwise the simulation will be very loooong, and the resulting file will occupy a lot of space.

--
Regards & Happy New Year!
Wojciech M. Zabolotny
wzab@ise.pw.edu.pl
Reply to
Wojciech Zabolotny
Loading thread data ...

Interesting, and not at all crazy, but not new either.

Something similar was commonly done in the controller state machines used to manage bit-slice microprocessors (vintage

1975-1985 or thereabouts). The AMD 29PL141 family of EPROM-programmable state machines did exactly this.

Of course, if you push this idea much further you'll find your "state register" slowly but surely mutating into a "program counter", and the procedures that implement each state's activity will become "instructions", and .... oh, how about that, I seem to have a programmable processor here....

Seriously though... the tradeoffs that give rise to a spectrum of controller organizations, from pure hardware state machine through to pure general purpose processor, are very interesting. For any given problem, there are sure to be many possible styles of solution with different benefits and drawbacks. Even more interesting, for me at least, is the fascinating social spectrum that mirrors this spectrum of design paradigms - with JavaScript programmers somewhere near one end, and soldering-iron users at the other.

Thanks

--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which 
are not the views of Doulos Ltd., unless specifically stated.
Reply to
Jonathan Bromley

Jonathan wisely avoids suggesting which social group is uppermost!

As he says, the idea is not new. Many such techniques were developed when they were necessary (long before hardware became fast enough and cheap enough to allow a choice).

To solve a few specific problems, it doesn't usually make economic sense to invent a new programming language and write a compiler for it. Similarly, it doesn't usually make economic sense to invent a new processor (even a simple one like that described) to save logic elements in a few specific cases. It's fun and heroic, but usually takes too long to be economic.

Mike

Reply to
MikeShepherd564

Hi

I've just received a Sparkfun Spartan 3E Development Board,

formatting link

I can use the Xilinx parallel port JTAG cable to program the FPGA but I can't figure out how to program the SPI PROM. This PROM, an Atmel AT45DB), has an SPI interface but does not have a JTAG one. You have to do some magic in the Spartan to add the SPI PROM as part of the JTAG chain.

Does anyone know how to do this? How can I use Impact to program an SPI PROM that does not have a JTAG interface?

thanks Bob Smith

Reply to
Bob Smith

Hi Bob,

Xilinx have a sample project for their S3E starter kit to program an SPI flash chip using a picoblaze processor:

formatting link
formatting link

Targets a "STMicro M25P16 SPI Flash" found on the S3e kit. (Not sure how compatible it is with the AT45DB, but would expect them to be fairly similar)

The design itself would be fairly easy to adapt to the Sparkfun board.

Red

Reply to
RedskullDC

Bob

The SPI and JTAG chain can share a header with some switchover of signals, or be entirely seperate as you will see in most of our products. The same 14 way cable(Xilinx pinout) is used for programming. In the IMPACT part of ISE there are seperate menu options for for boundary scan(JTAG) and SPI. When using SPI it is advisable to assert signal Prog_b low (if available) to avoid potential drive conflicts on the SPI.

There is supposed to be some JTAG programming of the SPI coming and this I believe works by loading a temporary design into the FPGA to allow access to the SPI I/O and thence waggling appropriately. There is a Xilinx answer on this and when it will become available. A link is on out Darnaw1 product page if you can't find it.

John Adair Enterpoint Ltd.- Home of Drigmorn1. The low cost FPGA Starter Board.

Reply to
John Adair

You can also do this with some software which will control the JTAG boundry scan register of the FPGA to toggle the pins connectes to the SPI PROM to generate a given programming sequence.

Petter

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Reply to
Petter Gustad

Push the idea one stage further, so that the instructions themselves can suspend to stack and resume operations, and things get even more interesting. Then instructions don't have to be trivial sequential operations, because you don't have to throw away their state and restart them, e.g. to service an interrupt or page fault.

"message send" instructions make compilation for OO programming very simple, hiding the details of searching a hierarchy of method tables.

Or for example, iterator instructions, e.g. to search an entire array, or other "high level" operations can become a seamless part of the instruction set. (Which may be interesting if you have ever pondered how to integrate something like a hardware search engine or FFT processor into software cleanly).

Or an instruction capable of walking a compiler's parse tree, executing whatever code it found at each node, for a halfway house between interpretation and compilation...

In 1980s terms, this was called "closing the semantic gap" (between the level at which people could most productively program, and the machine level).

Nowadays, of course, there IS no semantic gap, because people are taught to program in C or C++.

It makes me shudder to see so many fundamentally unnecessary layers of crud like pure abstract virtual base classes and templates piled on top of the basic simplicity of OO programming.

It doesn't even make things more efficient. The above message send, in C++, does result in a lengthy sequential search of the chain of method tables to find the correct method; while the "message send" instruction hits a cache and could usually be out in six cycles, even in a 1980s first-attempt technology demonstrator.

And common cases suffered much less penalty. "Send Integer +" can obviously add two integers. But in parallel, it can type check them both; and commence the message send process, and either: commit the sum, or continue the message send process, according to the type check results...

We have come such a long way since then.

(incidentally there's not much information online about the Linn Rekursiv, or its language Lingo, and much of that is pretty misleading)

- Brian

Reply to
Brian Drummond

Thanks for posting your code. If you like your style and the design fits and makes timing, go ahead and use it. I agree that almost any description is better than one huge case statement.

There are two ways I know to use procedural code targeting programmable logic.

One way is to make an HDL description of a custom processor to "reduce" the problem to assembly language programming. This seems to be the default academic track found in textbooks. In this style, I would design a hardware processor to execute a custom instruction set. The downside, as Jonathan points out, is that before I can work on solving my problem, I must first designing a custom description language and hardware to run it.

The other way is to use a sequential HDL process to describe all of the clocked register updates by making use of variables, functions and procedures. This style uses the HDL itself as a virtual cpu to describe the cycle by cycle updates to the registers In this method, a simulator is used to debug code by tracing variable values and looking at waveforms. The advantage to this style is that the hdl "instructions" execute in zero time. The real hardware limits are found by static timing, and the design trade-off is pipeline ticks vs Fmax.

-- Mike Treseler

Reply to
Mike Treseler

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.