Bus I/O

FPGA projects on this site, or abroad

Bus I/O

Postby DJatPS » Sun Nov 15, 2009 3:18 am

Here's another puzzle to me. I have a device with bus. To write to a register on the device you have to do the following:

lower D/C# to tell it you want to write to the command registers.
lower CS# to tell it you are selecting the chip so it will respond to commands.
lower WE# to tell it you are writing.
put an register address on the 8 bit data bus.
Raise WE# to tell it you are done writing the command register then
raise D/C# to tell it you want to write data to the device
lower WE# to tell it you are writing the data to be stored in the register
put the data on the (same) 8 bit data bus.
raise the WE# to tell it you are done writing the data
raise the CS# to release the chip

(we can ignore the timing, assume one clk for each step is sufficient)

I've been trying to wade through verilog examples but can't find anything to help answer some basic questions like: Assuming we wrote a module like: "WriteToRegister(clk,dc,cs,we,addr,data,bus)", what would the code look like, how would it be instatiated and how would it be "called" (forgive my programming viewpoint on the world) to write different values to different registers. Ex. I need to write the (binary) value 01011001 to register (hex) A5 on the device then write 01000000 to B7, etc.?
DJatPS
 
Posts: 8
Joined: Fri Nov 13, 2009 12:43 am
Location: Arkansas

Postby Thoma HAUC » Sun Nov 15, 2009 8:50 am

Hi DJatPS,

It seems that you begin with hardware design and you come probably from software world. I am right?

The main idea would be to, firstly, draw the data path to access to your device than write a sequencer to handle this data path.

You can take a look at this document to get a clear idea on how to proceed: http://thoma.hauc.free.fr/device%20access.pdf

An advise: do not forget, you will handle hardware at very low level...

Thoma
Thoma HAUC
 
Posts: 51
Joined: Thu Aug 26, 2004 4:57 am
Location: Near Paris, France

Postby DJatPS » Tue Nov 17, 2009 12:19 am

Yes, I've been writing software for about 20 years, but I'm irresitably drawn to programmable logic. Years ago I got a book by Murray Sargent III and Richard Shoemaker called "Interfacing Microcomputers to the Real World" on interfacing Z80 micros to different devices. It introduced various TTL logic and interfacing concepts. The authors comment in this chapter, "Now maybe you start to see why this micro stuff can feed nascent drives for power!" To be able to control devices with logic circuits really does spark the imagination. I never got real fluent with the lanuage of gates, breadboarding circuits, or building S100 interface boards, so the book has set on the shelf for years. But the desire to do more with hardware has always simmered in the back of my mind. I'm starting to get the hang of it but still trying to bridge some basic areas between my "old" way of thinking and the circuit way of thinking.

So I took your diagram and have implemented the state machine and also another state machine that triggers the "write" machine with the sequence of initialization values and addresses.

I works like this:

module EP_Write() receives among it's inputs, a control line that tells it when to start (start in the diagram), The machine goes through it states setting the control vector to the values listed in your diagram, finishing with setting the "complete" flag. Then it waits till the start flag resets to 0 before going in to the default idle state.

module EP_Init() has a state machine that has to write about 6 different values to registers in the device. It begins it's work after a reset. It places the address and data for a register on the appropriate buses, then sets the "start" flag which signals the EP_Write to begin it's process. It waits until EP_Write sets the completed flag, then lowers the start flag, and goes to the next state which begins the process over again with the next set of address-data pairs.

It seems to be working good, getting the right signals showing on the oscilloscope. I'm implementing the bidirection data bus now and should have the thing online soon. Might post it here for some feedback when done.
DJatPS
 
Posts: 8
Joined: Fri Nov 13, 2009 12:43 am
Location: Arkansas

Postby Thoma HAUC » Tue Nov 17, 2009 7:30 pm

Hi DJatPS,

Hope to see the final result soon.
If you have other questions, do not hesitate.

Thoma
Thoma HAUC
 
Posts: 51
Joined: Thu Aug 26, 2004 4:57 am
Location: Near Paris, France


Return to General projects