PICOBLAZE I/O INTERFACE

Please download to get full document.

View again

of 33
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report
Category:

Internet & Technology

Published:

Views: 0 | Pages: 33

Extension: PDF | Download: 0

Share
Related documents
Description
CHAPTER 16 PICOBLAZE I/O INTERFACE 16.1 INTRODUCTION To interact with the external environment, a regular microcontroller chip consists of a variety of built-in I/O peripherals, such as a UART, SPI (serial
Transcript
CHAPTER 16 PICOBLAZE I/O INTERFACE 16.1 INTRODUCTION To interact with the external environment, a regular microcontroller chip consists of a variety of built-in I/O peripherals, such as a UART, SPI (serial peripheral interface), timer, etc. When starting a new development, we select a microcontroller chip according to the I/O requirements of the application and may sometimes need to use additional chips to realize less commonly used functions. Unlike a regular microcontroller, PicoBlaze has no built-in I/O peripherals. It just provides a simple generic input and output structure for an I/O interface. I/O peripherals are constructed as needed and thus are customized to each application. PicoBlaze uses the input and output instructions to transfer data between its internal registers and I/O ports, and its interface consists of the following signals: 0 port-id: an 8-bit signal that specifies the port id (i.e., port address) of an input or output instruction 0 in-port: an 8-bit signal where PicoBlaze obtains input data during operation of an input instruction 0 out-port: an 8-bit signal where PicoBlaze places output data during operation of an output instruction 0 readstrobe: a 1-bit signal that is asserted in the second clock cycle of an input instruction 0 writestrobe: a 1-bit signal that is asserted in the second clock cycle of an output instruction FPGA Protogping by VHDL Examples. By Pong P. Chu 2008 John Wiley & Sons, Inc. 367 368 PICOBLAZE 110 INTERFACE Figure 16.1 Timing diagram of an output instruction. Although there are only two 8-bit ports to input and output data, the 8-bit port-id signal can be used to distinguish different peripherals, and thus it is said that PicoBlaze can support up to 2.56 (i.e., 28) input ports and 256 output ports. In the remaining chapter, we examine the detailed IiO timing of PicoBlaze and illustrate the I/O interface development by adding a series of peripherals for the square circuit of Chapter OUTPUT PORT Output instruction and timing The output instruction writes data to the output port. It has two forms: output sx, (SY) output sx, port-name In the first form, the port id is stored in the SY register. In the second form, the port id is specified explicitly by port name, which is a two-digit hexadecimal number or a previously defined symbolic constant. The output data is always stored in the sx register. The timing diagram of an output instruction, output so, 02 is shown in the top five traces of Figure Recall that each PicoBlaze instruction takes two clock cycles. When the instruction is executed, the content of SO is placed on out-port and 02 is placed on port-id for two clock cycles. The write-strobe signal is asserted in the second clock cycle. It can be used as an enable tick to store data in an output register or to initiate the designated peripheral operation. OUTPUT PORT 369 Figure 16.2 Output decoding of four output registers. Table 16.1 Truth table of a decoding circuit input output write-strobe port -id (1) port-id( 0) en-d Output interface The output interface between PicoBlaze and an output peripheral usually consists of a decoding circuit and necessary output buffers, which are normally an array of registers. The decoding circuit decodes the port id and generates an enable tick accordingly. After the output instruction, the data will be stored in the designated buffer. To illustrate the construction, let us consider a PicoBlaze interface with four output buffers. We assign 0016, OIl6, 0216, and 0316 as their port ids. Note that the six MSBs of the port addresses are identical and only two LSBs are needed to distinguish a port. The block diagram is shown in Figure The key is the decoding circuit, whose function table is shown in Table It is a 2-t0-2~ decoder. In the second clock cycle of an output instruction, write-strobe is asserted and 1 bit of the 4-bit en-d signal is asserted accordingly. The one-clock-cycle enable tick activates the corresponding output register to retrieve data from the out-port signal. The decoding timing diagram of the instruction output so, 02 370 PICOBLAZE 110 INTERFACE is shown at the bottom of Figure During the second clock cycle of the output instruction, the en-d(2) signal is asserted and the data value on out-port is stored in the corresponding buffer at the rising edge of the next clock. Once understanding the basic operation, we can derive the HDL code accordingly. The code segment is process (write-strobe, port-id) begin if write-strobe= '0' then en-d = 0000 ; else case port-id(1 downto 0) when 00 = en-d = 0001 ; when 01 = en-d = 0010 ; when 1'1011 = en-d = 0100 ; when others = end case; end if; end process; en-d = 1000 ; This scheme is very general and can be applied to any number of output ports. The choice of the port address is somewhat arbitrary. We use the binary code in the previous example. If the number of the output port is smaller than eight, one-hot code can be used to simplify the decoding circuit. For example, we can define the four previous port ids as Oi16 (i.e., ), 0216 (i.e., ), 0416 (i.e., ), and (18~6(i.e., ). The decoding logic can be simplified to process (write-strobe, port-id) begin if write_strobe='o' then en-d = 0000 ; else en-d = port-id(3 downto 0); end if; end process; Note that no decoding logic is needed if there is only a single output port. The write-strobe signal can be connected to the register's enable signal, as shown in Figure As discussed in Section , it is good practice to use symbolic aliases for I/O ports and declare its binary address in the header. For example, the initial output port address assignment can be declared as output port definitions constant out-port-a, 00 constant out-port-b, 01 constant out-port-c, 02 constant out-port-d, 04 If the assignment is changed, we need to modify the header but keep the remaining assembly code intact. Using a clear header also allows us easily to identify the port ids when the companion HDL code is developed. is INPUT PORT 371 Figure 16.3 Timing diagram of an input instruction INPUT PORT Input instruction and timing The input instruction reads data from the input port. Similar to the output instruction, it has two forms: input sx, (sy) input sx, port-name The SY register or portname specifies the read port id. The retrieved data is stored in the SX register. The timing diagram of an input instruction, input SO, 02 is shown in Figure When the instruction is executed, 02 is placed on port-id. After two clock cycles, in-port will be sampled at the rising edge of the clock and its value is stored in the SO register. The external circuit must ensure that the input data is stable during the sampling edge to avoid timing violation. As in the output instruction, the read-strobe signal is asserted in the second clock cycle. The function of the readstrobe signal is less obvious and is discussed in the next subsection Input interface The input interface between PicoBlaze and input peripherals usually consists of a multiplexing circuit, which uses port-id as the selection signal to route the desired value to in-port. Sometimes, a decoding circuit similar to the one in the output interface is also necessary to signal the completion of the data access. For the purpose of input interface design, an input port can be classified as a continuousaccess or single-access port. For a continuous-access port, the data is presented continuously, such as the switch input of Section On the other hand, the availability of data of a single-access port is triggered by a single discrete event, such as receiving a character in an UART buffer. The flag FF and buffers discussed in Section are in this category. After the data is retrieved, we must remove it from the buffer to prevent the same data from 372 PICOBLAZE 110 INTERFACE Figure 16.4 Block diagram of four continuous-access ports. Figure 16.5 Block diagram of four single-access ports. being processed again. This is usually done by utilizing a one-clock-cycle tick to clear the flag FF or remove a word from a FIFO buffer. The interface for continuous-access ports involves only a multiplexing circuit. Consider an interface with four such ports. The block diagram is shown in Figure The interface for single-access ports needs a mechanism to remove the retrieved data from the buffer in the end of an input instruction. This can be done by using a decoding circuit that decodes the port-id and read-strobe signals. The circuit is identical to the decoding circuit of the output interface except that write-strobe is replaced by readstrobe. The decoded output can be considered as a removal signal, which is asserted for one clock cycle and removes the previously retrieved data. Consider an interface with four FIFOs. The diagram of the complete decoding and multiplexing circuit is shown in Figure The rv signal is the decoded removal signal. In the end of an input instruction, 1 bit of this 4-bit signal is asserted and the corresponding FIFO performs a read operation, in which the SQUARE PROGRAM WITH A SWITCH AND SEVEN-SEGMENT LED DISPLAY INTERFACE 373 first word is removed from the buffer. Assume that 0016, Oi16, 0216, and 0316 are assigned as the port ids. The HDL code segment for the interface is rn u ltiplexing circuit with port-id(l downto 0) select data = in-data0 when OO , in-data1 when 01 , in-data2 when lo , in-data3 when others ; decoding circuit process(reade-strobe,port-id) begin if read-strobe='o' then rv = 0000 ; else case port-id(1 downto 0) is when If 00 'I = rv = 0001 ; when 01 = rv = 0010 ; when 10 = rv = 0100 ; when others = rv = 1000 ; end case; end if ; end process; In a real application, it is likely that the input interface contains both continuous- and single-access ports. A decoding circuit is only needed for single-access ports SQUARE PROGRAM WITH A SWITCH AND SEVEN-SEGMENT LED DISPLAY INTERFACE To demonstrate the construction of the PicoBlaze I/O interface, we add more versatile input and output peripherals to the square routine of Chapter 15. Recall that the square routine calculates a2 + b2, where a and b are 8-bit unsigned integers. We use the 8-bit switch and a pushbutton to enter the values of a and b. The pushbutton generates a one-clock-cycle tick when pressed. The tick indicates that the current value of the switch should be loaded. The values of a and b are loaded alternately; i.e., the first pressing loads a, the second pressing loads b, the third pushing loads a, and so on. A second pushbutton is also included to clear the PicoBlaze's data RAM and relevant registers. We use four seven-segment LEDs to display the inputs and computed results. The LEDs are arranged as four hexadecimal numbers. Since the range of a2 + b2 is up to 17 bits, the decimal point of the leftmost LED is used for the MSB. The three lower bits of the switch select what to display, which can be a, b, a', b2, or a2 + b2. In summary, the interface consists of the following: Switch: provides the values of a and b and selects the content of the LED display Pushbutton 0: loads the a and b alternatively when pressed Pushbutton I : clears data RAM and relevant registers when pressed Seven-segment LED: displays the selected 17-bit value in four hexadecimal digits 374 PICOBLAZE 110 INTERFACE Figure 16.6 Output interface of a square circuit Output interface Recall that the four seven-segment LEDs on the prototyping board share the same input pins, and a time-multiplexing circuit is required. For a PicoBlaze-based design, the multiplexing can be done by either an external circuit or a software routine. We use the external-circuit approach, which is simpler for assembly code development, in this section and discuss the software approach in Chapter 17. The LED time-multiplexing circuit designed in Section can be used for this purpose. This circuit shields the timing and appears as four independent seven-segment LEDs for external system. The block diagram of the PicoBlaze output interface is shown in Figure The interface consists of four 8-bit output ports, each port representing a seven-segment LED pattern. In the assembly code, the four LED patterns are stored in PicoBlaze s data RAM with symbolic addresses of ledo, ledl, led2, and led3. The corresponding code segment is... ;data RAM address alias constant ledo, 10 constant ledl, 11 constant led2, 12 constant led3, ;output port definitions constant sseg0-port, 00 ;7-seg led 0 constant ssegl-port, 01 ;7-seg led 1 constant sseg2-port, 02 ;7-seg led 2 constant sseg3_port, 03 ;7-seg led 3... disp-led: fetch data, led0 output data, sseg0-port SQUARE PROGRAM WITH A SWITCH AND SEVEN-SEGMENT LED DISPLAY INTERFACE 375 Figure 16.7 Input interface of a square circuit. fetch data, led1 output data, ssegl-port fetch data, led2 output data, sseg2-port fetch data, led3 output data, sseg3-port Input interface The input interface consists of an 8-bit switch and two 1-bit pushbuttons. The former is a continuous-access port since the value is always present. The latter is a single-access port since pressing a button leads to only a single event (e.g., loading a to the register once rather than continuously). Because of the mechanical glitches, a debouncing circuit is needed to generate a clean one-clock-cycle tick. Since PicoBlaze s port can take up 8-bit data, inputs from the two pushbuttons can be grouped together as a single input port. The block diagram of the input interface is shown in Figure The interface consists of two debouncing circuits, a two-to-one multiplexer, a decoding circuit, and two flag FFs. The function of the two flag FFs is discussed in Section They provide a mechanism to set and clear the button-pressing event. When a button is pressed, the debouncing circuit s output sets the flag. It remains asserted until it is retrieved by the PicoBlaze s input instruction, which sets the selection signal of the multiplexer to route the desired value to PicoBlaze s input port, and activates the clear signal. For clarity, we name the pushbutton 1 as the s button (for setting the value) and pushbutton 0 as the c button (for clearing the data RAM). The pseudo code to process the input is ;input the button flags ;if c=l then 376 PICOBLAZE 110 INTERFACE ; call the clearing-ram routine ;if s=l then ; input switch value ; store it to data ram ; toggle a/b address offset Since the s button inputs the values of a and b alternately, we use a global register, switch-a-b, to keep track of which one is being read currently. The register serves as the data RAM address offset, which can be 0 or 2, and its value toggles when the s button is pressed. The corresponding assembly code subroutine is ;input port definitions constant rd-flag-port, 00 ;2 flags (xxxxxxsc): constant sw-port, 01 ;8-bit switch... proc-btn : input s3, rd-flag-port ;get flag ;check and process c button test s3, 01 ;check c button flag jump z, chk-btns ;flag not set call init ;flag set, clear jump pr o c - b t n- done chk-btns : ;check and process s button test s3, 02 ;check s button flag jump z, proc-btn-done ;flag not set input data, sw-port ;get switch load addr, a-lsb ;get addr of a add addr, switch-a-b ; add offset store data, (addr) ;write data to ram ;update current disp position xor switch-a-b, 02 ; toggle between 00, 02 proc-btn-done : Assembly code development After designing the I/O interface, we can derive the assembly program. The development follows the divide-and-conquer approach discussed in Chapter 15 and partitions the main program into several subroutines. The main program is call init ; in it i a 1 iza ti o n forever : ;main loop body call proc-btn ;check C? process buttons call square ;calculate square call load-led-pttn ;store led patterns to ram call disp-led ; output led pattern jump forever The complete code is shown in Listing The square subroutine is fromchapter 15, and the proc-btn and disp-led subroutines are discussed in the previous two subsections. The init subroutine performs system initialization. It uses a loop to load 0 s to data RAM (i.e., clear the RAM) and sets the s wit ch-a-b SQUARE PROGRAM WITH A SWITCH AND SEVEN-SEGMENT LED DISPLAY INTERFACE 377 register to 0 (i.e., read a). The load-led-pttn subroutine reads the switch input, retrieves the desired values from the data RAM, converts the values to seven-segment LED patterns, and stores them to the corresponding locations in the data RAM. These patterns are then written to the output ports in the subsequent disp-led routine. The load-led-pttn routine consists of the get-uppernibble and get-lowernibble routines to extract the two hexadecimal digits and the hex-to-led routine to convert a hexadecimal digit to the corresponding seven-segment LED pattern. The program requires more storage. In addition to the data RAM and registers required for the square subroutine, this program utilizes a new global register switch-a-b to keep track of whether a or b is being read, and 4 bytes in data RAM, whose addresses are labeled ledo, ledl, led2, and led3, to store four seven-segment LED patterns. c Listing 16.1 Square program with a switch and seven-segment LED interface, ; square circuit with 7-seg LED interface, ;program operation : ; - read a and b from switch ; - calculate a*a + b*b ; - display data on 7-seg led, -----_-_ ; data RAM address alias, constant a-lsb, 00 constant b-lsb, 02 constant aa-lsb, 04 IS constant aa-msb, 05 constant bb-lsb, 06 constant bb-msb, 07 constant aabb-lsb, 08 constant aabb-msb, constant aabb-cout, OA constant ledo, 10 constant ledl, 11 constant led2, 12 constant led3, _-_ _------, ; register alias, ;commonly used local variables 30 namereg SO, data ;reg for temporary data namereg sl, addr ;reg for temporary mem & i/o port addr namereg s2, i ; general -purpose loop index ; global variables namereg sf, switch-a-b ;ram offset for current switch input 35, ; port alias, input port definitions 378 PICOBLAZE 110 INTERFACE 40 constant rd-flag-port, 00 ; 2 flags (xxxxxxsc ): constant sw-port, 01 ;&bit switch output port definitions constant sseg0-port, 00 ;7-seg led 0 constant ssegl-port, 01 ;7-seg led I 45 constant sseg2-port, 02 ;7-seg led 2 constant sseg3_port, 03 ;7-seg led 3 ; main program 50 ; ; c a 11 in g h i e ra r c h y ; main ; - init 55 ; - proc-btn - init ; - square - mult-soft ; - load-led-pttn ge t-1 o we r-n i b bl e - get-uppe r-n i b ble - hex-to-led ; - disp-led 65,' call init forever : ;main loop body ; i n i t i a 1 i za t i o n 70 call proc-btn ; check & process buttons call square ; calculate square call load-led-pttn ;store led patterns to ram call disp-led ;output led pattern jump forever 75 ; routine : init ; function : perform initialization, clear register/ram ; output register: 80 ; switch-a-b : cleared to 0 ; temp register: data, i 85 init : ; c 1 ear memory load i, 40 load data, 00 clr-mem-loop : ;unitize loop index to 64 store data, (i) sub i, 01 ;dec loop index 90 jump nz, clr-mem-loop ;repeat until i=o ;clear register load switch-a-b, 00 SQUARE PROGRAM WITH A SWITCH AND SEVEN-SEGMENT LED DISPLAY INTERFACE ; routine : proc-btn ; function: check two buttons and process the display ; input reg: switch-a-b: ram offset (0 for a and 2 for b) IW ; output register: s3: store input port flag switch-a-b: may be toggled ; temp register used: data, addr, proc-btn: input s3, rd-flag-port ;get flag ;check and process c button test s3, 01 ;check c button flag jump z, chk-btns ;flag not set 110 call init ;flag set, clear jump proc-btn-done chk-btns : ;check and process s button test s3, 02 ;check s but on flag IIS jump z, proc-btn-done ;flag not se input data, sw-port ;get switch load addr, a-lsb ;get addr of a add addr, switch-a-b ;add offset store data, (addr) ;write data to ram 120 ; update current disp position xor switch-a-b, 02 ; toggle between 00, 02 proc-btn-done : ; routine : load-led-pttn ; function: read 3 LSBs of switch input and convert the desired values to four led pattern
Recommended
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x