Index: /trunk/3DEES/Paella.cof
===================================================================
--- /trunk/3DEES/Paella.cof	(revision 177)
+++ /trunk/3DEES/Paella.cof	(revision 177)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="US-ASCII" standalone="yes"?>
+<cof>
+	<eprom_name>EPCS16</eprom_name>
+	<flash_loader_device>EP3C25</flash_loader_device>
+	<output_filename>Paella.jic</output_filename>
+	<n_pages>1</n_pages>
+	<width>1</width>
+	<mode>7</mode>
+	<sof_data>
+		<page_flags>1</page_flags>
+		<bit0>
+			<sof_filename>Paella.sof</sof_filename>
+		</bit0>
+	</sof_data>
+	<version>4</version>
+	<options>
+	</options>
+</cof>
Index: /trunk/3DEES/Paella.dpf
===================================================================
--- /trunk/3DEES/Paella.dpf	(revision 177)
+++ /trunk/3DEES/Paella.dpf	(revision 177)
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<pin_planner>
+	<pin_info>
+		<pin name="ADC_D[5]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[5](n)" >
+		</pin>
+		<pin name="ADC_D[4]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[4](n)" >
+		</pin>
+		<pin name="ADC_D[3]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[3](n)" >
+		</pin>
+		<pin name="ADC_D[2]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[2](n)" >
+		</pin>
+		<pin name="ADC_D[1]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[1](n)" >
+		</pin>
+		<pin name="ADC_D[0]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[0](n)" >
+		</pin>
+		<pin name="ADC_DCO" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_DCO(n)" >
+		</pin>
+		<pin name="ADC_FCO" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_FCO(n)" >
+		</pin>
+		<pin name="ADC_D[0](n)" direction="Input" source="Assignments" diff_pair_node="ADC_D[0]" >
+		</pin>
+		<pin name="ADC_D[1](n)" direction="Input" source="Assignments" diff_pair_node="ADC_D[1]" >
+		</pin>
+		<pin name="ADC_D[2](n)" direction="Input" source="Assignments" diff_pair_node="ADC_D[2]" >
+		</pin>
+		<pin name="ADC_D[3](n)" direction="Input" source="Assignments" diff_pair_node="ADC_D[3]" >
+		</pin>
+		<pin name="ADC_D[4](n)" direction="Input" source="Assignments" diff_pair_node="ADC_D[4]" >
+		</pin>
+		<pin name="ADC_D[5](n)" direction="Input" source="Assignments" diff_pair_node="ADC_D[5]" >
+		</pin>
+		<pin name="ADC_DCO(n)" direction="Input" source="Assignments" diff_pair_node="ADC_DCO" >
+		</pin>
+		<pin name="ADC_FCO(n)" direction="Input" source="Assignments" diff_pair_node="ADC_FCO" >
+		</pin>
+	</pin_info>
+	<buses>
+	</buses>
+	<group_file_association>
+	</group_file_association>
+	<pin_planner_file_specifies>
+	</pin_planner_file_specifies>
+</pin_planner>
Index: /trunk/3DEES/Paella.qpf
===================================================================
--- /trunk/3DEES/Paella.qpf	(revision 177)
+++ /trunk/3DEES/Paella.qpf	(revision 177)
@@ -0,0 +1,30 @@
+# -------------------------------------------------------------------------- #
+#
+# Copyright (C) 1991-2009 Altera Corporation
+# Your use of Altera Corporation's design tools, logic functions 
+# and other software and tools, and its AMPP partner logic 
+# functions, and any output files from any of the foregoing 
+# (including device programming or simulation files), and any 
+# associated documentation or information are expressly subject 
+# to the terms and conditions of the Altera Program License 
+# Subscription Agreement, Altera MegaCore Function License 
+# Agreement, or other applicable license agreement, including, 
+# without limitation, that your use is for the sole purpose of 
+# programming logic devices manufactured by Altera and sold by 
+# Altera or its authorized distributors.  Please refer to the 
+# applicable agreement for further details.
+#
+# -------------------------------------------------------------------------- #
+#
+# Quartus II
+# Version 9.0 Build 132 02/25/2009 SJ Web Edition
+# Date created = 14:14:14  August 28, 2009
+#
+# -------------------------------------------------------------------------- #
+
+QUARTUS_VERSION = "9.0"
+DATE = "14:14:14  August 28, 2009"
+
+# Revisions
+
+PROJECT_REVISION = "Paella"
Index: /trunk/3DEES/Paella.qsf
===================================================================
--- /trunk/3DEES/Paella.qsf	(revision 177)
+++ /trunk/3DEES/Paella.qsf	(revision 177)
@@ -0,0 +1,280 @@
+# -------------------------------------------------------------------------- #
+#
+# Copyright (C) 1991-2009 Altera Corporation
+# Your use of Altera Corporation's design tools, logic functions 
+# and other software and tools, and its AMPP partner logic 
+# functions, and any output files from any of the foregoing 
+# (including device programming or simulation files), and any 
+# associated documentation or information are expressly subject 
+# to the terms and conditions of the Altera Program License 
+# Subscription Agreement, Altera MegaCore Function License 
+# Agreement, or other applicable license agreement, including,
+# without limitation, that your use is for the sole purpose of 
+# programming logic devices manufactured by Altera and sold by 
+# Altera or its authorized distributors.  Please refer to the
+# applicable agreement for further details.
+#
+# -------------------------------------------------------------------------- #
+#
+# Quartus II
+# Version 9.0 Build 132 02/25/2009 SJ Web Edition
+# Date created = 14:14:14  August 28, 2009
+#
+# -------------------------------------------------------------------------- #
+#
+# Notes:
+#
+# 1) The default values for assignments are stored in the file:
+#		Paella_assignment_defaults.qdf
+#    If this file doesn't exist, see file:
+#		assignment_defaults.qdf
+#
+# 2) Altera recommends that you do not modify this file. This
+#    file is updated automatically by the Quartus II software
+#    and any changes you make may be lost or overwritten.
+#
+# -------------------------------------------------------------------------- #
+
+
+set_global_assignment -name FAMILY "Cyclone III"
+set_global_assignment -name DEVICE EP3C25Q240C8
+set_global_assignment -name TOP_LEVEL_ENTITY Paella
+set_global_assignment -name ORIGINAL_QUARTUS_VERSION 9.0
+set_global_assignment -name PROJECT_CREATION_TIME_DATE "14:14:14  AUGUST 28, 2009"
+set_global_assignment -name LAST_QUARTUS_VERSION "9.1 SP2"
+set_global_assignment -name DEVICE_FILTER_PACKAGE "ANY QFP"
+set_global_assignment -name DEVICE_FILTER_PIN_COUNT 240
+set_global_assignment -name MIN_CORE_JUNCTION_TEMP 0
+set_global_assignment -name MAX_CORE_JUNCTION_TEMP 85
+set_global_assignment -name AUTO_SHIFT_REGISTER_RECOGNITION OFF
+set_global_assignment -name MISC_FILE Paella.dpf
+set_global_assignment -name MISC_FILE "C:/altera/project_12/Paella.dpf"
+set_global_assignment -name PARTITION_FITTER_PRESERVATION_LEVEL PLACEMENT_AND_ROUTING -section_id Top
+set_global_assignment -name USE_TIMEQUEST_TIMING_ANALYZER OFF
+set_global_assignment -name ENABLE_CLOCK_LATENCY ON
+set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top
+set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top
+set_global_assignment -name NOMINAL_CORE_SUPPLY_VOLTAGE 1.2V
+set_global_assignment -name LL_ROOT_REGION ON -section_id "Root Region"
+set_global_assignment -name LL_MEMBER_STATE LOCKED -section_id "Root Region"
+set_global_assignment -name STRATIX_CONFIGURATION_DEVICE EPCS16
+set_global_assignment -name STRATIX_DEVICE_IO_STANDARD "3.3-V LVTTL"
+set_global_assignment -name USE_CONFIGURATION_DEVICE ON
+set_global_assignment -name CYCLONEIII_CONFIGURATION_DEVICE EPCS16
+set_global_assignment -name FORCE_CONFIGURATION_VCCIO ON
+set_global_assignment -name CONFIGURATION_VCCIO_LEVEL 3.3V
+set_global_assignment -name CYCLONEII_RESERVE_NCEO_AFTER_CONFIGURATION "USE AS REGULAR IO"
+set_global_assignment -name RESERVE_ASDO_AFTER_CONFIGURATION "AS INPUT TRI-STATED"
+set_global_assignment -name FMAX_REQUIREMENT "240 MHz" -section_id "LVDS Data Clock"
+set_instance_assignment -name CLOCK_SETTINGS "LVDS Data Clock" -to ADC_DCO
+set_global_assignment -name FMAX_REQUIREMENT "20 MHz" -section_id "LVDS Frame Clock"
+set_instance_assignment -name CLOCK_SETTINGS "LVDS Frame Clock" -to ADC_FCO
+set_global_assignment -name FMAX_REQUIREMENT "50 MHz" -section_id "USB Clock"
+set_instance_assignment -name CLOCK_SETTINGS "USB Clock" -to USB_IFCLK
+set_global_assignment -name IOBANK_VCCIO 3.3V -section_id 1
+set_global_assignment -name IOBANK_VCCIO 3.3V -section_id 2
+set_global_assignment -name IOBANK_VCCIO 3.3V -section_id 3
+set_global_assignment -name IOBANK_VCCIO 3.3V -section_id 4
+set_global_assignment -name IOBANK_VCCIO 2.5V -section_id 5
+set_global_assignment -name IOBANK_VCCIO 2.5V -section_id 6
+set_global_assignment -name IOBANK_VCCIO 3.3V -section_id 7
+set_global_assignment -name IOBANK_VCCIO 3.3V -section_id 8
+set_location_assignment PIN_21 -to LED
+set_location_assignment PIN_33 -to USB_IFCLK
+set_location_assignment PIN_37 -to USB_PA6
+set_location_assignment PIN_38 -to USB_PA4
+set_location_assignment PIN_39 -to USB_PA2
+set_location_assignment PIN_41 -to USB_FLAGB
+set_location_assignment PIN_43 -to USB_FLAGA
+set_location_assignment PIN_44 -to USB_PB[4]
+set_location_assignment PIN_45 -to USB_PB[5]
+set_location_assignment PIN_46 -to USB_PB[6]
+set_location_assignment PIN_49 -to USB_PB[7]
+set_location_assignment PIN_50 -to USB_SLRD
+set_location_assignment PIN_51 -to USB_SLWR
+set_location_assignment PIN_52 -to USB_PB[0]
+set_location_assignment PIN_55 -to USB_PB[1]
+set_location_assignment PIN_56 -to USB_PB[2]
+set_location_assignment PIN_57 -to USB_PB[3]
+set_location_assignment PIN_78 -to PWM[0]
+set_location_assignment PIN_80 -to PWM[1]
+set_location_assignment PIN_81 -to PWM[2]
+set_location_assignment PIN_82 -to PWM[3]
+set_location_assignment PIN_114 -to SPI_SEL[0]
+set_location_assignment PIN_117 -to ADC_RST
+set_location_assignment PIN_118 -to SPI_CLK
+set_location_assignment PIN_119 -to SPI_SDO
+set_location_assignment PIN_120 -to SPI_SEL[1]
+set_location_assignment PIN_137 -to "ADC_D[0](n)"
+set_location_assignment PIN_139 -to ADC_D[0]
+set_instance_assignment -name IO_STANDARD LVDS -to ADC_D[0]
+set_location_assignment PIN_142 -to "ADC_D[1](n)"
+set_location_assignment PIN_143 -to ADC_D[1]
+set_instance_assignment -name IO_STANDARD LVDS -to ADC_D[1]
+set_location_assignment PIN_144 -to "ADC_D[2](n)"
+set_location_assignment PIN_145 -to ADC_D[2]
+set_instance_assignment -name IO_STANDARD LVDS -to ADC_D[2]
+set_location_assignment PIN_147 -to "ADC_D[3](n)"
+set_location_assignment PIN_148 -to ADC_D[3]
+set_instance_assignment -name IO_STANDARD LVDS -to ADC_D[3]
+set_location_assignment PIN_149 -to "ADC_DCO(n)"
+set_location_assignment PIN_150 -to ADC_DCO
+set_instance_assignment -name IO_STANDARD LVDS -to ADC_DCO
+set_location_assignment PIN_151 -to "ADC_FCO(n)"
+set_location_assignment PIN_152 -to ADC_FCO
+set_instance_assignment -name IO_STANDARD LVDS -to ADC_FCO
+set_location_assignment PIN_159 -to "ADC_D[4](n)"
+set_location_assignment PIN_160 -to ADC_D[4]
+set_instance_assignment -name IO_STANDARD LVDS -to ADC_D[4]
+set_location_assignment PIN_162 -to "ADC_D[5](n)"
+set_location_assignment PIN_164 -to ADC_D[5]
+set_instance_assignment -name IO_STANDARD LVDS -to ADC_D[5]
+set_location_assignment PIN_181 -to RAM_ADDR[12]
+set_location_assignment PIN_182 -to RAM_DQAP
+set_location_assignment PIN_183 -to RAM_DQA[0]
+set_location_assignment PIN_184 -to RAM_DQA[1]
+set_location_assignment PIN_185 -to RAM_DQA[2]
+set_location_assignment PIN_186 -to RAM_DQA[3]
+set_location_assignment PIN_187 -to RAM_DQA[4]
+set_location_assignment PIN_188 -to RAM_DQA[5]
+set_location_assignment PIN_189 -to RAM_DQA[6]
+set_location_assignment PIN_194 -to RAM_DQA[7]
+set_location_assignment PIN_195 -to RAM_ADDR[13]
+set_location_assignment PIN_196 -to RAM_ADDR[14]
+set_location_assignment PIN_197 -to RAM_ADDR[15]
+set_location_assignment PIN_200 -to RAM_ADDR[16]
+set_location_assignment PIN_201 -to RAM_ADDR[17]
+set_location_assignment PIN_202 -to RAM_ADDR[18]
+set_location_assignment PIN_203 -to RAM_ADDR[19]
+set_location_assignment PIN_207 -to RAM_ADDR[20]
+set_location_assignment PIN_210 -to CLK_100MHz
+set_location_assignment PIN_214 -to RAM_ADDR[21]
+set_location_assignment PIN_216 -to RAM_ADDR[0]
+set_location_assignment PIN_217 -to RAM_ADDR[1]
+set_location_assignment PIN_218 -to RAM_ADDR[2]
+set_location_assignment PIN_219 -to RAM_ADDR[3]
+set_location_assignment PIN_221 -to RAM_ADDR[4]
+set_location_assignment PIN_223 -to RAM_ADDR[5]
+set_location_assignment PIN_224 -to RAM_DQBP
+set_location_assignment PIN_226 -to RAM_DQB[0]
+set_location_assignment PIN_230 -to RAM_DQB[1]
+set_location_assignment PIN_231 -to RAM_DQB[2]
+set_location_assignment PIN_232 -to RAM_DQB[3]
+set_location_assignment PIN_233 -to RAM_DQB[4]
+set_location_assignment PIN_234 -to RAM_DQB[5]
+set_location_assignment PIN_235 -to RAM_DQB[6]
+set_location_assignment PIN_236 -to RAM_DQB[7]
+set_location_assignment PIN_237 -to RAM_ADDR[6]
+set_location_assignment PIN_238 -to RAM_ADDR[7]
+set_location_assignment PIN_239 -to RAM_CLK
+set_location_assignment PIN_240 -to RAM_WE
+set_location_assignment PIN_4 -to RAM_ADDR[8]
+set_location_assignment PIN_5 -to RAM_ADDR[9]
+set_location_assignment PIN_6 -to RAM_ADDR[10]
+set_location_assignment PIN_9 -to RAM_ADDR[11]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to LED
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CLK_100MHz
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_FLAGA
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_FLAGB
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PA6
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PA4
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PA2
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PB[7]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PB[6]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PB[5]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PB[4]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PB[3]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PB[2]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PB[1]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_PB[0]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_SLRD
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_SLWR
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to USB_IFCLK
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to PWM[0]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to PWM[1]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to PWM[2]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to PWM[3]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SPI_SEL[0]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to ADC_RST
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SPI_CLK
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SPI_SDO
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SPI_SEL[1]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[0]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[1]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[2]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[3]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[4]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[5]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[6]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[7]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[8]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[9]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[10]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[11]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[12]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[13]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[14]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[15]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[16]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[17]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[18]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[19]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[20]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_ADDR[21]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_CLK
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_WE
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQAP
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQA[0]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQA[1]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQA[2]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQA[3]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQA[4]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQA[5]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQA[6]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQA[7]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQBP
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[0]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[1]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[2]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[3]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[4]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[5]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[6]
+set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[7]
+set_instance_assignment -name AUTO_OPEN_DRAIN_PINS ON -to PWM[0]
+set_instance_assignment -name AUTO_OPEN_DRAIN_PINS ON -to PWM[1]
+set_instance_assignment -name AUTO_OPEN_DRAIN_PINS ON -to PWM[2]
+set_instance_assignment -name AUTO_OPEN_DRAIN_PINS ON -to PWM[3]
+
+set_global_assignment -name MISC_FILE "D:/altera/MultiChannelUSB/Paella.dpf"
+set_global_assignment -name VERILOG_FILE Paella.v
+set_global_assignment -name VERILOG_FILE adc_lvds.v
+set_global_assignment -name VERILOG_FILE cic_pipeline.v
+set_global_assignment -name VERILOG_FILE cic_filter.v
+set_global_assignment -name VERILOG_FILE uwt_bior31.v
+set_global_assignment -name VERILOG_FILE sys_pll.v
+set_global_assignment -name VERILOG_FILE control.v
+set_global_assignment -name VERILOG_FILE analyser.v
+set_global_assignment -name VERILOG_FILE amplitude.v
+set_global_assignment -name VERILOG_FILE deconv.v
+set_global_assignment -name VERILOG_FILE delay.v
+set_global_assignment -name VERILOG_FILE coincidence.v
+set_global_assignment -name VERILOG_FILE counter.v
+set_global_assignment -name VERILOG_FILE histogram32.v
+set_global_assignment -name VERILOG_FILE histogram16.v
+set_global_assignment -name VERILOG_FILE trigger.v
+set_global_assignment -name VERILOG_FILE oscilloscope.v
+set_global_assignment -name VERILOG_FILE configuration.v
+set_global_assignment -name VERILOG_FILE usb_fifo.v
+set_global_assignment -name VERILOG_FILE i2c_fifo.v
+set_global_assignment -name VERILOG_FILE spi_fifo.v
+set_global_assignment -name VERILOG_FILE test.v
+set_global_assignment -name MIF_FILE test.mif
+set_global_assignment -name VERILOG_FILE average.v
+set_global_assignment -name VERILOG_FILE extrema.v
+set_global_assignment -name VERILOG_FILE filter.v
+set_global_assignment -name VERILOG_FILE new_filter.v
+set_global_assignment -name VERILOG_FILE clip.v
+set_global_assignment -name VERILOG_FILE pwm.v
+
+set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
Index: /trunk/3DEES/Paella.v
===================================================================
--- /trunk/3DEES/Paella.v	(revision 177)
+++ /trunk/3DEES/Paella.v	(revision 177)
@@ -0,0 +1,451 @@
+module Paella
+	(
+		input	wire			CLK_100MHz,
+		output	wire			LED,
+
+		input	wire			ADC_DCO,
+		input	wire			ADC_FCO,
+		input	wire	[5:0]	ADC_D,
+
+		output	wire	[3:0]	PWM,
+
+		output	wire	[1:0]	SPI_SEL,
+		output	wire			SPI_SDO,
+		output	wire			SPI_CLK,
+		output	wire			ADC_RST,
+
+		output	wire			USB_SLRD,
+		output	wire			USB_SLWR,
+		input	wire			USB_IFCLK,
+		input	wire			USB_FLAGA, // EMPTY flag for EP6
+		input	wire			USB_FLAGB, // FULL flag for EP8
+		output	wire			USB_PA2,
+		output	wire			USB_PA4,
+		output	wire			USB_PA6,
+		inout	wire	[7:0]	USB_PB,
+
+		output	wire			RAM_CLK,
+		output	wire			RAM_WE,
+		output	wire	[21:0]	RAM_ADDR,
+		inout	wire			RAM_DQAP,
+		inout	wire	[7:0]	RAM_DQA,
+		inout	wire			RAM_DQBP,
+		inout	wire	[7:0]	RAM_DQB
+	);
+
+	localparam	N		=	12;
+
+	//	Turn output ports off
+/*
+	assign	RAM_CLK		=	1'b0;
+	assign	RAM_CE1		=	1'b0;
+	assign	RAM_WE		=	1'b0;
+	assign	RAM_ADDR	=	20'h00000;
+*/
+	assign	ADC_RST = 1'b0;
+
+	assign	RAM_CLK = sys_clock;
+
+	assign	USB_PA2		=	~usb_rden;
+	assign	USB_PA4		=	usb_addr;
+	assign	USB_PA6		=	~usb_pktend;
+
+	wire			usb_wrreq, usb_rdreq, usb_rden, usb_pktend;
+	wire			usb_tx_wrreq, usb_rx_rdreq;
+	wire			usb_tx_full, usb_rx_empty;
+	wire	[7:0]	usb_tx_data, usb_rx_data;
+	wire			usb_addr;
+
+	assign	USB_SLRD = ~usb_rdreq;
+	assign	USB_SLWR = ~usb_wrreq;
+
+	usb_fifo usb_unit
+	(
+		.usb_clock(USB_IFCLK),
+		.usb_data(USB_PB),
+		.usb_full(~USB_FLAGB),
+		.usb_empty(~USB_FLAGA),
+		.usb_wrreq(usb_wrreq),
+		.usb_rdreq(usb_rdreq),
+		.usb_rden(usb_rden),
+		.usb_pktend(usb_pktend),
+		.usb_addr(usb_addr),
+
+		.clock(sys_clock),
+
+		.tx_full(usb_tx_full),
+		.tx_wrreq(usb_tx_wrreq),
+		.tx_data(usb_tx_data),
+
+		.rx_empty(usb_rx_empty),
+		.rx_rdreq(usb_rx_rdreq),
+		.rx_q(usb_rx_data)
+	);
+		
+	wire	[11:0]	osc_mux_data [4:0];
+
+	wire	[11:0]	trg_mux_data;
+	wire			trg_flag;
+
+	wire	[2:0]	coi_data;
+	wire			coi_flag;
+
+	wire	[4*12-1:0]	int_mux_data [N-1:0];
+
+	wire			amp_flag [N-1:0];
+	wire	[11:0]	amp_data [N-1:0];
+
+	wire			cnt_good [N-1:0];
+	wire	[15:0]	cnt_bits_wire;
+
+	wire			sys_clock, sys_frame;
+
+    wire	[11:0]	adc_data [N-1:0];
+    wire	[11:0]	sys_data [N-1:0];
+	wire	[11:0]	tst_data;
+
+    wire	[11:0]	cmp_data;
+    wire	[11:0]	del_data;
+
+	wire	[20:0]	cic_data [N-1:0];
+
+	wire	[11:0]	dec_data [N-1:0];
+	wire	[11:0]	clp_data [N-1:0];
+	wire	[11:0]	tmp_data [1:0];
+
+	wire			i2c_reset;
+/*
+	sys_pll sys_pll_unit(
+		.inclk0(CLK_100MHz),
+		.c0(sys_clock),
+		.c1(ADC_DCO),
+		.c2(ADC_FCO));
+
+	wire			ADC_DCO, ADC_FCO;
+
+	test test_unit(
+		.clock(ADC_FCO),
+		.data(tst_data));
+
+	adc_lvds #(
+		.size(3),
+		.width(12)) adc_lvds_unit (
+		.clock(sys_clock),
+		.lvds_dco(ADC_DCO),
+		.lvds_fco(ADC_FCO),
+		.lvds_d(36'd0),
+		.test(tst_data),
+		.trig(12'd0),
+		.adc_frame(sys_frame),
+		.adc_data({cmp_data, adc_data[2], adc_data[1], adc_data[0]}));
+*/
+	sys_pll sys_pll_unit(
+		.inclk0(CLK_100MHz),
+		.c0(sys_clock));
+
+	adc_lvds #(
+		.size(6),
+		.width(24)) adc_lvds_unit (
+		.clock(sys_clock),
+		.lvds_dco(ADC_DCO),
+		.lvds_fco(ADC_FCO),
+		.lvds_d({ADC_D[5], ADC_D[4], ADC_D[3], ADC_D[2], ADC_D[1], ADC_D[0]}),
+		.adc_frame(sys_frame),
+		.adc_data({
+			adc_data[11], adc_data[10], adc_data[9], adc_data[8],
+			adc_data[7], adc_data[6], adc_data[5], adc_data[4],
+			adc_data[3], adc_data[2], adc_data[1], adc_data[0]}));
+
+	wire	[15:0]		cfg_bits [63:0];
+	wire	[1023:0]	int_cfg_bits;
+
+	wire	[39:0]	cfg_mux_selector;
+
+	wire 			cfg_reset;
+
+	wire 	[12:0]	bus_ssel;
+	wire			bus_wren;
+	wire	[31:0]	bus_addr;
+	wire	[15:0]	bus_mosi;
+	wire 	[15:0]	bus_miso [10:0];
+	wire 	[12:0]	bus_busy;
+
+	wire 	[15:0]	mrg_bus_miso;
+	wire 			mrg_bus_busy;
+
+	wire 	[12*16-1:0]	int_bus_miso;
+
+	genvar j;
+
+	generate
+		for (j = 0; j < 64; j = j + 1)
+		begin : CONFIGURATION_OUTPUT
+			assign cfg_bits[j] = int_cfg_bits[j*16+15:j*16];
+		end
+	endgenerate
+
+	configuration configuration_unit (
+		.clock(sys_clock),
+		.reset(cfg_reset),
+		.bus_ssel(bus_ssel[0]),
+		.bus_wren(bus_wren),
+		.bus_addr(bus_addr[5:0]),
+		.bus_mosi(bus_mosi),
+		.bus_miso(bus_miso[0]),
+		.bus_busy(bus_busy[0]),
+		.cfg_bits(int_cfg_bits));
+
+	generate
+		for (j = 0; j < 12; j = j + 1)
+		begin : MUX_DATA
+			assign int_mux_data[j] = {
+				amp_data[j],
+				clp_data[j],
+				cic_data[j][19:8],
+				sys_data[j]};
+		end
+	endgenerate
+
+	assign cfg_mux_selector = {cfg_bits[4][7:0], cfg_bits[3], cfg_bits[2]};
+
+	lpm_mux #(
+		.lpm_size(4*12),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(12),
+		.lpm_widths(6)) trg_mux_unit (
+		.sel(cfg_bits[4][13:8]),
+		.data({
+			int_mux_data[11], int_mux_data[10], int_mux_data[9], int_mux_data[8],
+			int_mux_data[7], int_mux_data[6], int_mux_data[5], int_mux_data[4],
+			int_mux_data[3], int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
+		.result(trg_mux_data));
+
+	generate
+		for (j = 0; j < 5; j = j + 1)
+		begin : OSC_CHAIN
+		
+			lpm_mux #(
+				.lpm_size(4*12),
+				.lpm_type("LPM_MUX"),
+				.lpm_width(12),
+				.lpm_widths(6)) osc_mux_unit (
+				.sel(cfg_mux_selector[j*8+5:j*8]),
+				.data({
+					int_mux_data[11], int_mux_data[10], int_mux_data[9], int_mux_data[8],
+					int_mux_data[7], int_mux_data[6], int_mux_data[5], int_mux_data[4],
+					int_mux_data[3], int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
+				.result(osc_mux_data[j]));
+		end
+	endgenerate
+
+	trigger trigger_unit (
+		.clock(sys_clock),
+		.frame(sys_frame),
+		.reset(cfg_bits[0][0]),
+		.cfg_data(cfg_bits[5][11:0]),
+		.trg_data(trg_mux_data),
+		.trg_flag(trg_flag));
+	
+	oscilloscope oscilloscope_unit (
+		.clock(sys_clock),
+		.frame(sys_frame),
+		.reset(cfg_bits[0][1]),
+		.cfg_data(cfg_bits[5][12]),
+		.trg_flag(trg_flag),
+		.osc_data({cmp_data[3:0], osc_mux_data[4], osc_mux_data[3], osc_mux_data[2], osc_mux_data[1], osc_mux_data[0]}),
+		.ram_wren(RAM_WE),
+		.ram_addr(RAM_ADDR),
+		.ram_data({RAM_DQA, RAM_DQAP, RAM_DQB, RAM_DQBP}),
+		.bus_ssel(bus_ssel[1]),
+		.bus_wren(bus_wren),
+		.bus_addr(bus_addr[19:0]),
+		.bus_mosi(bus_mosi),
+		.bus_miso(bus_miso[1]),
+		.bus_busy(bus_busy[1]));
+
+	new_filter #(.size(12), .width(12)) filter_unit (
+		.clock(sys_clock),
+		.frame(sys_frame),
+		.reset(1'b0),
+		.inp_data({
+			sys_data[11], sys_data[10], sys_data[9], sys_data[08],
+			sys_data[7], sys_data[6], sys_data[5], sys_data[4],
+			sys_data[3], sys_data[2], sys_data[1], sys_data[0]}),
+		.out_data({
+			cic_data[11], cic_data[10], cic_data[9], cic_data[8],
+			cic_data[7], cic_data[6], cic_data[5], cic_data[4],
+			cic_data[3], cic_data[2], cic_data[1], cic_data[0]}));
+
+	generate
+		for (j = 0; j < 3; j = j + 1)
+		begin : DECONV_CHAIN
+
+			clip #(.shift(22), .width(20), .widthr(12)) clip_unit (
+				.clock(sys_clock),
+				.frame(sys_frame),
+				.reset(1'b0),
+//				.del_data({6'd14, 6'd14, 6'd14, 6'd14}),
+				.del_data({cfg_bits[39+8*j][5:0], cfg_bits[37+8*j][5:0], cfg_bits[35+8*j][5:0], cfg_bits[33+8*j][5:0]}),
+				.amp_data({6'd17, 6'd17, 6'd17, 6'd17}),
+//				.tau_data({16'd17193, 16'd17193, 16'd17193, 16'd17193}), /* exp(-14/1125)*1024*17 */
+				.tau_data({cfg_bits[38+8*j], cfg_bits[36+8*j], cfg_bits[34+8*j], cfg_bits[32+8*j]}),
+				.inp_data({
+					cic_data[j*4+3][19:0], cic_data[j*4+2][19:0],
+					cic_data[j*4+1][19:0], cic_data[j*4+0][19:0]}),
+				.out_data({
+					clp_data[j*4+3], clp_data[j*4+2], 
+					clp_data[j*4+1], clp_data[j*4+0]}));
+
+		end
+	endgenerate
+
+	generate
+		for (j = 0; j < 12; j = j + 1)
+		begin : MCA_CHAIN
+
+			assign sys_data[j] = (cfg_bits[1][j]) ? (adc_data[j] ^ 12'hfff) : (adc_data[j]);
+
+			amplitude #(.width(12)) amplitude_unit_2 (
+				.clock(sys_clock),
+				.frame(sys_frame),
+				.reset(1'b0),
+				.cfg_data({1'b0, 12'd0, 12'd5}),
+//				.cfg_data({cfg_bits[7+2*j][12:0], cfg_bits[6+2*j][11:0]}),
+//				.inp_data(dec_data[j]),
+				.inp_data(clp_data[j]),
+				.out_flag(amp_flag[j]),
+				.out_data(amp_data[j]));
+		end
+	endgenerate
+
+	histogram32 histogram32_unit (
+		.clock(sys_clock),
+		.frame(sys_frame),
+		.reset(cfg_bits[0][5]),
+		.hst_good((amp_flag[0]) & (cnt_good[0]) & (cfg_bits[13][1])),
+		.hst_data(amp_data[0]),
+/*
+		.hst_good((amp_flag[j]) & (cnt_good[j]) & (cfg_bits[13][1])),
+		.hst_data(amp_data[j]),
+*/
+		.bus_ssel(bus_ssel[2]),
+		.bus_wren(bus_wren),
+		.bus_addr(bus_addr[12:0]),
+		.bus_mosi(bus_mosi),
+		.bus_miso(bus_miso[2]),
+		.bus_busy(bus_busy[2]));
+
+	counter hst_counter_unit (
+		.clock(sys_clock),
+//		.frame((sys_frame) & (~ana_dead[0])),
+		.frame(sys_frame),
+		.reset(cfg_bits[0][8]),
+		.setup(cfg_bits[13][0]),
+		.count(cfg_bits[13][1]),
+		.bus_ssel(bus_ssel[5]),
+		.bus_wren(bus_wren),
+		.bus_addr(bus_addr[1:0]),
+		.bus_mosi(bus_mosi),
+		.bus_miso(bus_miso[5]),
+		.bus_busy(bus_busy[5]),
+		.cnt_good(cnt_good[0]));
+
+
+	i2c_fifo i2c_unit(
+		.clock(sys_clock),
+		.reset(i2c_reset),
+/*
+		normal connection
+		.i2c_sda(I2C_SDA),
+		.i2c_scl(I2C_SCL),
+
+		following is a cross wire connection for EPT
+*/
+		.i2c_sda(I2C_SCL),
+		.i2c_scl(I2C_SDA),
+		
+		.bus_ssel(bus_ssel[11]),
+		.bus_wren(bus_wren),
+		.bus_mosi(bus_mosi),
+		.bus_busy(bus_busy[11]));
+
+	spi_fifo spi_unit(
+		.clock(sys_clock),
+		.reset(1'b0),
+		.spi_sel(SPI_SEL),
+		.spi_sdo(SPI_SDO),
+		.spi_clk(SPI_CLK),
+		
+		.bus_ssel(bus_ssel[12]),
+		.bus_wren(bus_wren),
+		.bus_mosi(bus_mosi),
+		.bus_busy(bus_busy[12]));
+
+	pwm pwm_unit(
+		.clock(sys_clock),
+		.cfg_data({cfg_bits[31], cfg_bits[30], cfg_bits[29]}),
+		.out_data(PWM));
+
+	generate
+		for (j = 0; j < 11; j = j + 1)
+		begin : BUS_OUTPUT
+			assign int_bus_miso[j*16+15:j*16] = bus_miso[j];
+		end
+	endgenerate
+
+	lpm_mux #(
+		.lpm_size(12),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(16),
+		.lpm_widths(4)) bus_miso_mux_unit (
+		.sel(bus_addr[31:28]),
+		.data(int_bus_miso),
+		.result(mrg_bus_miso));
+
+	lpm_mux #(
+		.lpm_size(13),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(1),
+		.lpm_widths(4)) bus_busy_mux_unit (
+		.sel(bus_addr[31:28]),
+		.data(bus_busy),
+		.result(mrg_bus_busy));
+
+	lpm_decode #(
+		.lpm_decodes(13),
+		.lpm_type("LPM_DECODE"),
+		.lpm_width(4)) lpm_decode_unit (
+		.data(bus_addr[31:28]),
+		.eq(bus_ssel));
+
+
+	control control_unit (
+		.clock(sys_clock),
+		.rx_empty(usb_rx_empty),
+		.tx_full(usb_tx_full),
+		.rx_data(usb_rx_data),
+		.rx_rdreq(usb_rx_rdreq),
+		.tx_wrreq(usb_tx_wrreq),
+		.tx_data(usb_tx_data),
+		.bus_wren(bus_wren),
+		.bus_addr(bus_addr),
+		.bus_mosi(bus_mosi),
+		.bus_miso(mrg_bus_miso),
+		.bus_busy(mrg_bus_busy),
+		.led(LED));
+
+/*
+	altserial_flash_loader #(
+		.enable_shared_access("OFF"),
+		.enhanced_mode(1),
+		.intended_device_family("Cyclone III")) sfl_unit (
+		.noe(1'b0),
+		.asmi_access_granted(),
+		.asmi_access_request(),
+		.data0out(),
+		.dclkin(),
+		.scein(),
+		.sdoin());
+*/
+
+endmodule
Index: /trunk/3DEES/UserInterface.tcl
===================================================================
--- /trunk/3DEES/UserInterface.tcl	(revision 177)
+++ /trunk/3DEES/UserInterface.tcl	(revision 177)
@@ -0,0 +1,2200 @@
+package require XOTcl
+
+package require BLT
+package require swt
+package require usb
+
+package require zlib
+
+wm minsize . 1000 700
+
+namespace eval ::mca {
+    namespace import ::xotcl::*
+
+    namespace import ::blt::vector
+    namespace import ::blt::graph
+    namespace import ::blt::tabnotebook
+
+# -------------------------------------------------------------------------
+
+    variable oscCodes
+    array set oscCodes {
+        1 {Channel 1}
+        2 {Channel 2}
+        3 {Channel 3}
+        4 {Channel 4}
+        5 {Channel 5}
+        6 {Trigger}
+    }
+
+# -------------------------------------------------------------------------
+
+    variable adcCodes
+    array set adcCodes {
+        1 {ADC 1}
+        2 {ADC 2}
+        3 {ADC 3}
+        4 {ADC 4}
+        5 {ADC 5}
+        6 {ADC 6}
+        7 {ADC 7}
+        8 {ADC 8}
+        9 {ADC 9}
+       10 {ADC 10}
+       11 {ADC 11}
+       12 {ADC 12}
+    }
+
+# -------------------------------------------------------------------------
+
+    variable inpCodes
+    array set inpCodes {
+        0 {r}
+        1 {f}
+        2 {d}
+        3 {c}
+    }
+
+# -------------------------------------------------------------------------
+
+    proc validate {max size value} {
+        if {![regexp {^[0-9]*$} $value]} {
+            return 0
+        } elseif {[regexp {^0[0-9]+$} $value]} {
+            return 0
+        } elseif {$value > $max} {
+            return 0
+        } elseif {[string length $value] > $size} {
+            return 0
+        } else {
+            return 1
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    proc doublevalidate {max value} {
+        if {![regexp {^[0-9]{0,2}\.?[0-9]{0,3}$} $value]} {
+            return 0
+        } elseif {[regexp {^0[0-9]+$} $value]} {
+            return 0
+        } elseif {$value > $max} {
+            return 0
+        } else {
+            return 1
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    proc legendLabel {master row key title} {
+        label ${master}.${key}_label -anchor w -text ${title}
+        label ${master}.${key}_value -width 10 -anchor e -text {}
+
+        grid ${master}.${key}_label -row ${row} -column 1 -sticky w
+        grid ${master}.${key}_value -row ${row} -column 2 -sticky ew
+    }
+
+# -------------------------------------------------------------------------
+
+    proc legendButton {master row key title var bg {fg black}} {
+        checkbutton ${master}.${key}_check -variable $var
+        label ${master}.${key}_label -anchor w -text ${title} -bg ${bg} -fg $fg
+        label ${master}.${key}_value -width 10 -anchor e -text {} -bg ${bg} -fg $fg
+
+        grid ${master}.${key}_check -row ${row} -column 0 -sticky w
+        grid ${master}.${key}_label -row ${row} -column 1 -sticky w
+        grid ${master}.${key}_value -row ${row} -column 2 -sticky ew
+    }
+
+# -------------------------------------------------------------------------
+
+    Class UsbController
+
+# -------------------------------------------------------------------------
+
+    UsbController instproc usbConnect {} {
+        my instvar handle
+
+        puts usbConnect
+
+        if {[my exists handle]} {
+            $handle disconnect
+            unset handle
+        }
+if {1} {
+        while {[catch {usb::connect 0x09FB 0x6001 1 1 0} result]} {
+            set answer [tk_messageBox -icon error -type retrycancel \
+                -message {Cannot access USB device} -detail $result]
+#            puts $result
+            if {[string equal $answer cancel]} exit
+        }
+
+        set handle $result
+
+}
+    }
+
+# -------------------------------------------------------------------------
+
+    UsbController instproc usbHandle {} {
+        my instvar handle
+
+        if {[my exists handle]} {
+            return $handle
+        } else {
+            my usbConnect
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    UsbController instproc usbCmd {command} {
+        set code [catch {[my usbHandle] writeRaw [usb::convert $command]} result]
+        switch -- $code {
+            1 {
+#                puts $result
+                my usbConnect
+            }
+        }
+
+    }
+
+# -------------------------------------------------------------------------
+
+    UsbController instproc usbCmdReadRaw {command size data} {
+        my usbCmd $command
+
+        set code [catch {[my usbHandle] readRaw $size} result]
+        switch -- $code {
+            0 {
+                set $data $result
+            }
+            1 {
+#                puts $result
+                my usbConnect
+            }
+            5 {
+#                puts Busy
+            }
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    UsbController instproc usbCmdReadRaw {command size data} {
+        my usbCmd $command
+
+        set code [catch {[my usbHandle] readRaw $size} result]
+        switch -- $code {
+            0 {
+                set $data $result
+            }
+            1 {
+#                puts $result
+                my usbConnect
+            }
+            5 {
+#                puts Busy
+            }
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    UsbController instproc usbCmdReadHex {command width size data} {
+        my usbCmd $command
+
+        set code [catch {[my usbHandle] readHex $width $size} result]
+        switch -- $code {
+            0 {
+                set $data $result
+            }
+            1 {
+#                puts $result
+                my usbConnect
+            }
+            5 {
+#                puts Busy
+            }
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    Class SpiDisplay -parameter {
+        {master}
+        {controller}
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc init {} {
+
+        my setup
+
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc destroy {} {
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc start {} {
+        my instvar config
+
+        trace add variable [myvar dac1] write [myproc dac1_update]
+        trace add variable [myvar dac2] write [myproc dac2_update]
+
+        ${config(1)}.dac1 set 0
+        ${config(1)}.dac2 set 0
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc setup {} {
+        my instvar number master
+        my instvar config
+
+        set config(1) [labelframe ${master}.cfg1 -borderwidth 1 -relief sunken -text {DAC}]
+
+        frame ${config(1)}.limits
+        label ${config(1)}.limits.min -text {2.5V}
+        label ${config(1)}.limits.max -text {0.0V}
+
+        scale ${config(1)}.dac1 -orient vertical -from 4095 -to 0 -tickinterval 0 -variable [myvar dac1]
+        scale ${config(1)}.dac2 -orient vertical -from 4095 -to 0 -tickinterval 0 -variable [myvar dac2]
+
+        pack ${config(1)}.limits.min -anchor n -side top -pady 10
+        pack ${config(1)}.limits.max -anchor s -side bottom -pady 9
+
+        grid ${config(1)}.dac1 ${config(1)}.dac2 ${config(1)}.limits -sticky ns -pady 7
+
+        
+        set config(2) [labelframe ${master}.cfg2 -borderwidth 1 -relief sunken -text {ADC}]
+
+        frame ${config(2)}.spc1 -width 130 -height 10
+        frame ${config(2)}.spc2 -width 130 -height 10
+        frame ${config(2)}.spc3 -width 130 -height 10
+
+        button ${config(2)}.reset -text {Reset} -command [myproc adc_reset]
+        button ${config(2)}.pattern -text {Test pattern} -command [myproc adc_pattern]
+        button ${config(2)}.ramp -text {Test ramp} -command [myproc adc_ramp]
+        button ${config(2)}.100mV -text {Test 100 mV} -command [myproc adc_100mV]
+        button ${config(2)}.150mV -text {Test 150 mV} -command [myproc adc_150mV]
+        button ${config(2)}.fltr0 -text {Filter 14MHz} -command [myproc adc_fltr0]
+        button ${config(2)}.fltr1 -text {Filter 10MHz} -command [myproc adc_fltr1]
+        button ${config(2)}.fltr2 -text {Filter 7.5MHz} -command [myproc adc_fltr2]
+
+        grid ${config(2)}.spc1
+        grid ${config(2)}.reset -sticky ew -pady 3 -padx 5
+        grid ${config(2)}.spc2
+        grid ${config(2)}.pattern -sticky ew -pady 3 -padx 5
+        grid ${config(2)}.ramp -sticky ew -pady 3 -padx 5
+        grid ${config(2)}.100mV -sticky ew -pady 3 -padx 5
+        grid ${config(2)}.150mV -sticky ew -pady 3 -padx 5
+        grid ${config(2)}.spc3
+        grid ${config(2)}.fltr0 -sticky ew -pady 3 -padx 5
+        grid ${config(2)}.fltr1 -sticky ew -pady 3 -padx 5
+        grid ${config(2)}.fltr2 -sticky ew -pady 3 -padx 5
+
+        grid ${config(1)} -row 1 -column 1 -sticky ns
+        grid ${config(2)} -row 1 -column 2 -sticky ns
+
+		grid columnconfigure ${master} 0 -weight 1
+		grid columnconfigure ${master} 1 -weight 1
+		grid columnconfigure ${master} 2 -weight 1
+		grid columnconfigure ${master} 3 -weight 1
+
+		grid rowconfigure ${master} 0 -weight 0
+		grid rowconfigure ${master} 1 -weight 1
+		grid rowconfigure ${master} 2 -weight 0
+
+        grid rowconfigure ${config(1)} 0 -weight 1
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc dac1_update args {
+        my instvar controller dac1
+
+        set value [format {3%03x} $dac1]
+
+        set prefix [format {%x} 12]
+
+        set command {}
+        append command 0001${prefix}00000020000000402[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 3]00
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc dac2_update args {
+        my instvar controller dac2
+
+        set value [format {b%03x} $dac1]
+
+        set prefix [format {%x} 12]
+
+        set command {}
+        append command 0001${prefix}00000020000000402[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 3]00
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc adc_reset args {
+        my instvar controller
+
+        set prefix [format {%x} 12]
+        
+        set command {}
+
+        set value {000001}
+        append command 0001${prefix}00000020000000401[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 5]
+
+        set value {040008}
+        append command 0001${prefix}00000020000000401[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 5]
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc adc_pattern args {
+        my instvar controller
+
+        set value {022000}
+
+        set prefix [format {%x} 12]
+        
+        set command {}
+        append command 0001${prefix}00000020000000401[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 5]
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc adc_ramp args {
+        my instvar controller
+
+        set value {02E000}
+
+        set prefix [format {%x} 12]
+        
+        set command {}
+        append command 0001${prefix}00000020000000401[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 5]
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc adc_100mV args {
+        my instvar controller
+
+        set value {070080}
+
+        set prefix [format {%x} 12]
+        
+        set command {}
+        append command 0001${prefix}00000020000000401[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 5]
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc adc_150mV args {
+        my instvar controller
+
+        set value {070180}
+
+        set prefix [format {%x} 12]
+        
+        set command {}
+        append command 0001${prefix}00000020000000401[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 5]
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc adc_fltr0 args {
+        my instvar controller
+
+        set value {070000}
+
+        set prefix [format {%x} 12]
+        
+        set command {}
+        append command 0001${prefix}00000020000000401[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 5]
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc adc_fltr1 args {
+        my instvar controller
+
+        set value {070004}
+
+        set prefix [format {%x} 12]
+        
+        set command {}
+        append command 0001${prefix}00000020000000401[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 5]
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    SpiDisplay instproc adc_fltr2 args {
+        my instvar controller
+
+        set value {070008}
+
+        set prefix [format {%x} 12]
+        
+        set command {}
+        append command 0001${prefix}00000020000000401[string range $value 0 1]
+        append command 0001${prefix}000000200000004[string range $value 2 5]
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    Class MuxDisplay -parameter {
+        {master}
+        {controller}
+    }
+
+# -------------------------------------------------------------------------
+
+    MuxDisplay instproc init {} {
+
+        my setup
+
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    MuxDisplay instproc destroy {} {
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    MuxDisplay instproc start {} {
+        variable adcCodes
+        my instvar config chan_val
+
+        set chan_val(1) 0
+        set chan_val(2) 0
+        set chan_val(3) 0
+        set chan_val(4) 0
+        set chan_val(5) 0
+        set chan_val(6) 0
+
+        trace add variable [myvar chan_val] write [myproc chan_val_update]
+        trace add variable [myvar polar] write [myproc polar_update]
+
+        $config(1).chan_0_1 select
+        $config(2).chan_0_2 select
+        $config(3).chan_0_3 select
+        $config(4).chan_0_4 select
+        $config(5).chan_0_5 select
+        $config(6).chan_0_1 select
+
+        foreach {ch dummy} [array get adcCodes] {
+          $config(inv).polar_${ch} deselect
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    MuxDisplay instproc setup {} {
+        variable oscCodes
+        variable adcCodes
+        variable inpCodes
+        my instvar master
+        my instvar config
+
+        set size [array size inpCodes]
+        set oscList [array get oscCodes]
+        set adcList [array get adcCodes]
+        set inpList [array get inpCodes]
+
+        set mux [frame ${master}.mux]
+        set key [frame ${master}.key]
+        set inv [frame ${master}.inv]
+        
+        foreach {osc title} $oscList {
+            set config($osc) [labelframe ${mux}.$osc -borderwidth 1 -relief sunken -text $title]
+            set column 1
+            foreach {code input} $inpList {
+                label $config($osc).input_${input} -text " ${input}"
+                grid $config($osc).input_${input} -row 0 -column ${column} -sticky w
+                incr column
+            }
+            foreach {ch dummy} $adcList {
+                label $config($osc).chan_${ch} -text "${ch} "
+                grid $config($osc).chan_${ch} -row ${ch} -column 0 -sticky ew
+                foreach {code input} $inpList {
+                    set column [expr {$code + 1}]
+                    set value [expr {$size * ($ch - 1) + $code}]
+                    radiobutton $config($osc).chan_${code}_${ch} -variable [myvar chan_val($osc)] -value ${value}
+                    grid $config($osc).chan_${code}_${ch} -row ${ch} -column ${column} -sticky w
+                }
+            }
+            set column [expr {($osc - 1) % 6}]
+            set row [expr {($osc - 1) / 6}]
+            grid $config($osc) -row ${row} -column ${column} -sticky news -padx 10
+        }
+
+        set config(key) [labelframe ${key}.frame -borderwidth 1 -relief sunken -text {legend}]
+
+        label $config(key).r -text "r - raw signal"
+        grid $config(key).r -row 0 -column 0 -sticky news
+
+        label $config(key).f -text "f - filtered signal"
+        grid $config(key).f -row 0 -column 1 -sticky news
+ 
+        label $config(key).d -text "d - deconvoluted signal"
+        grid $config(key).d -row 0 -column 2 -sticky news
+ 
+        label $config(key).c -text "c - clipped signal"
+        grid $config(key).c -row 0 -column 3 -sticky news
+
+        grid $config(key) -row 0 -column 0 -sticky news -padx 10
+
+        
+        set config(inv) [labelframe ${inv}.frame -borderwidth 1 -relief sunken -text {polarity inversion}]
+        label $config(inv).chan_label -text "channel "
+        grid $config(inv).chan_label -row 0 -column 0 -sticky e
+        label $config(inv).polar_label -text "polarity"
+        grid $config(inv).polar_label -row 1 -column 0 -sticky e
+        foreach {ch dummy} $adcList {
+            label $config(inv).chan_${ch} -text "${ch} "
+            grid $config(inv).chan_${ch} -row 0 -column ${ch} -sticky ew
+            checkbutton $config(inv).polar_${ch} -variable [myvar polar($ch)]
+            grid $config(inv).polar_${ch} -row 1 -column ${ch} -sticky w
+        }
+        grid $config(inv) -row 0 -column 0 -sticky news -padx 10
+
+        grid ${key} -row 0 -column 0 -sticky news
+        grid ${mux} -row 1 -column 0 -sticky news
+        grid ${inv} -row 2 -column 0 -sticky news
+
+        grid columnconfigure ${master} 0 -weight 1
+        grid rowconfigure ${master} 0 -weight 1
+        grid rowconfigure ${master} 1 -weight 1
+        grid rowconfigure ${master} 2 -weight 1
+
+        grid columnconfigure ${inv} 0 -weight 1
+
+        grid columnconfigure ${key} 0 -weight 1
+        grid columnconfigure $config(key) 0 -weight 1
+        grid columnconfigure $config(key) 1 -weight 1
+        grid columnconfigure $config(key) 2 -weight 1
+        grid columnconfigure $config(key) 3 -weight 1
+
+        
+        grid columnconfigure ${mux} 0 -weight 1
+        grid columnconfigure ${mux} 1 -weight 1
+        grid columnconfigure ${mux} 2 -weight 1
+        grid columnconfigure ${mux} 3 -weight 1
+        grid columnconfigure ${mux} 4 -weight 1
+        grid columnconfigure ${mux} 5 -weight 1
+
+
+    }
+
+
+# ------------------------------------------------------------------------
+
+    MuxDisplay instproc chan_val_update args {
+        my instvar controller chan_val
+
+        set byte1 [format {%02x%02x} $chan_val(2) $chan_val(1)]
+        set byte2 [format {%02x%02x} $chan_val(4) $chan_val(3)]
+        set byte3 [format {%02x%02x} $chan_val(6) $chan_val(5)]
+
+        $controller usbCmd 000200020004${byte1}000200030004${byte2}000200040004${byte3}
+    }
+
+# -------------------------------------------------------------------------
+
+    MuxDisplay instproc polar_update args {
+        my instvar controller polar
+        
+        set value {0b}
+        for {set i 12} {$i >= 1} {incr i -1} {
+            append value $polar($i)  
+        }
+
+        set value [format {%04x} $value]
+
+        $controller usbCmd 000200010004${value}
+    }
+
+# -------------------------------------------------------------------------
+
+    Class HstDisplay -parameter {
+        {number}
+        {master}
+        {controller}
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc init {} {
+
+        my set data {}
+
+        vector create [myvar xvec](4096)
+        vector create [myvar yvec](4096)
+
+        # fill one vector for the x axis with 4096 points
+        [myvar xvec] seq -0.5 4095.5
+
+        my setup
+
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc destroy {} {
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc start {} {
+        my instvar config
+
+        trace add variable [myvar data] write [myproc data_update]
+        trace add variable [myvar cntr_val] write [myproc cntr_val_update]
+        trace add variable [myvar rate_val] write [myproc rate_val_update]
+
+        trace add variable [myvar axis] write [myproc axis_update]
+        trace add variable [myvar thrs] write [myproc thrs_update]
+        trace add variable [myvar thrs_val] write [myproc thrs_update]
+        trace add variable [myvar base] write [myproc base_update]
+        trace add variable [myvar base_typ] write [myproc base_typ_update]
+        trace add variable [myvar base_val] write [myproc base_val_update]
+
+        ${config}.axis_check select
+
+        ${config}.thrs_check select
+        ${config}.thrs_field set 25
+
+        ${config}.base_auto select
+        ${config}.base_field set 20
+        ${config}.base_check select
+
+        set cntr_tmp 1200000000
+        my set cntr_val $cntr_tmp
+        my set cntr_bak $cntr_tmp
+        my set cntr_old $cntr_tmp
+        my set yvec_bak 0.0
+        my set yvec_old 0.0
+
+        my set rate_val(inst) 0.0
+        my set rate_val(mean) 0.0
+
+#        my cntr_reset
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc setup {} {
+        my instvar number master
+        my instvar xvec yvec graph
+        my instvar config thrs thrs_val base base_typ base_val
+        my instvar cntr_h cntr_m cntr_s
+
+        # create a graph widget and show a grid
+        set graph [graph ${master}.graph -height 250 -leftmargin 80]
+        $graph crosshairs configure -hide no -linewidth 1 -color darkblue -dashes {2 2}
+        $graph grid configure -hide no
+        $graph legend configure -hide yes
+        $graph axis configure x -min 0 -max 4096
+
+        set config [frame ${master}.config -width 170]
+
+        checkbutton ${config}.axis_check -text {log scale} -variable [myvar axis]
+
+        frame ${config}.spc1 -width 170 -height 30
+
+        frame ${config}.rate_frame -borderwidth 0 -width 170
+        legendLabel ${config}.rate_frame 0 inst {Inst. rate, 1/s}
+        legendLabel ${config}.rate_frame 1 mean {Avg. rate, 1/s}
+
+        frame ${config}.spc2 -width 170 -height 30
+
+        frame ${config}.chan_frame -borderwidth 0 -width 170
+        legendLabel ${config}.chan_frame 0 axisy {Bin entries}
+        legendLabel ${config}.chan_frame 1 axisx {Bin number}
+
+        frame ${config}.spc3 -width 170 -height 30
+
+        frame ${config}.cntr_frame -borderwidth 0 -width 170
+
+        label ${config}.cntr_frame.h -width 3 -anchor w -text {h}
+        entry ${config}.cntr_frame.h_field -width 3 -textvariable [myvar cntr_h] \
+            -validate all -vcmd {::mca::validate 999 3 %P}
+        label ${config}.cntr_frame.m -width 3 -anchor w -text {m}
+        entry ${config}.cntr_frame.m_field -width 3 -textvariable [myvar cntr_m] \
+            -validate all -vcmd {::mca::validate 59 2 %P}
+        label ${config}.cntr_frame.s -width 3 -anchor w -text {s}
+        entry ${config}.cntr_frame.s_field -width 6 -textvariable [myvar cntr_s] \
+            -validate all -vcmd {::mca::doublevalidate 59.999 %P}
+
+        grid ${config}.cntr_frame.h_field ${config}.cntr_frame.h \
+            ${config}.cntr_frame.m_field ${config}.cntr_frame.m ${config}.cntr_frame.s_field ${config}.cntr_frame.s
+
+        frame ${config}.spc4 -width 170 -height 10
+
+        button ${config}.start -text Start \
+            -bg yellow -activebackground yellow -command [myproc cntr_start]
+        button ${config}.reset -text Reset \
+            -bg red -activebackground red -command [myproc cntr_reset]
+
+        frame ${config}.spc5 -width 170 -height 30
+
+        checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
+        spinbox ${config}.thrs_field -from 1 -to 4095 \
+            -increment 5 -width 10 -textvariable [myvar thrs_val] \
+            -validate all -vcmd {::mca::validate 4095 4 %P}
+
+        frame ${config}.spc6 -width 170 -height 30
+
+        checkbutton ${config}.base_check -text baseline -variable [myvar base]
+        radiobutton ${config}.base_auto -text automatic -variable [myvar base_typ] -value 1
+        radiobutton ${config}.base_const -text constant -variable [myvar base_typ] -value 0
+        spinbox ${config}.base_field -from 1 -to 4095 \
+            -increment 5 -width 10 -textvariable [myvar base_val] \
+            -validate all -vcmd {::mca::validate 4095 4 %P}
+
+        frame ${config}.spc7 -width 170 -height 30
+
+        button ${config}.register -text Register \
+            -bg lightblue -activebackground lightblue -command [myproc register]
+
+        grid ${config}.axis_check -sticky w
+        grid ${config}.spc1
+        grid ${config}.rate_frame -sticky ew -padx 5
+        grid ${config}.spc2
+        grid ${config}.chan_frame -sticky ew -padx 5
+        grid ${config}.spc3
+        grid ${config}.cntr_frame -sticky ew -padx 5
+        grid ${config}.spc4
+        grid ${config}.start -sticky ew -pady 3 -padx 5
+        grid ${config}.reset -sticky ew -pady 3 -padx 5
+        grid ${config}.spc5
+        grid ${config}.thrs_check -sticky w
+        grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
+        grid ${config}.spc6
+        grid ${config}.base_check -sticky w
+        grid ${config}.base_auto -sticky w
+        grid ${config}.base_const -sticky w
+        grid ${config}.base_field -sticky ew -pady 1 -padx 5
+        grid ${config}.spc7
+        grid ${config}.register -sticky ew -pady 3 -padx 5
+
+        grid ${graph} -row 0 -column 0 -sticky news
+        grid ${config} -row 0 -column 1
+
+        grid rowconfigure ${master} 0 -weight 1
+        grid columnconfigure ${master} 0 -weight 1
+        grid columnconfigure ${master} 1 -weight 0 -minsize 80
+
+        grid columnconfigure ${config}.rate_frame 1 -weight 1
+        grid columnconfigure ${config}.chan_frame 1 -weight 1
+
+        # enable zooming
+        Blt_ZoomStack $graph
+
+        my crosshairs $graph
+
+        #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
+
+        # create one element with data for the x and y axis, no dots
+        $graph element create Spectrum1 -color blue -linewidth 2 -symbol none -smooth step -xdata [myvar xvec] -ydata [myvar yvec]
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc coor_update {W x y} {
+        my instvar config graph
+
+        $W crosshairs configure -position @${x},${y}
+
+        set index [$W axis invtransform x $x]
+        set index [::tcl::mathfunc::round $index]
+        catch {
+            ${config}.chan_frame.axisy_value configure -text [[myvar yvec] index $index]
+            ${config}.chan_frame.axisx_value configure -text ${index}.0
+        }
+    }
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc crosshairs {graph} {
+        set method [myproc coor_update]
+        bind $graph <Motion> [list [self] coor_update %W %x %y]
+        bind $graph <Leave> {
+            %W crosshairs off
+        }
+        bind $graph <Enter> {
+            %W crosshairs on
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc axis_update args {
+        my instvar axis graph
+        if {$axis} {
+            $graph axis configure y -min 1 -max 1E10 -logscale yes
+        } else {
+            $graph axis configure y -min {} -max {} -logscale no
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc thrs_update args {
+        my instvar controller config number thrs thrs_val
+
+        if {[string equal $thrs_val {}]} {
+            set thrs_val 0
+        }
+
+        set val_addr [format %02x [expr {6 + 2 * ${number}}]]
+
+        if {$thrs} {
+            ${config}.thrs_field configure -state normal
+            set value [format %03x $thrs_val]
+        } else {
+            ${config}.thrs_field configure -state disabled
+            set value 000
+        }
+
+        $controller usbCmd 000200${val_addr}00040${value}
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc base_update args {
+        my instvar controller config number base base_typ
+
+        set val_addr [format %02x [expr {7 + 2 * ${number}}]]
+
+        if {$base} {
+            ${config}.base_auto configure -state normal
+            ${config}.base_const configure -state normal
+            my base_typ_update
+        } else {
+            ${config}.base_auto configure -state disabled
+            ${config}.base_const configure -state disabled
+            ${config}.base_field configure -state disabled
+            $controller usbCmd 000200${val_addr}0004${base_typ}000
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc base_typ_update args {
+        my instvar config base_typ
+
+        switch -- $base_typ {
+            1 {
+                ${config}.base_field configure -state disabled
+            }
+            0 {
+                ${config}.base_field configure -state normal
+            }
+        }
+
+        my base_val_update
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc base_val_update args {
+        my instvar controller number base_typ base_val
+
+        if {[string equal $base_val {}]} {
+            set base_val 0
+        }
+
+        set val_addr [format %02x [expr {7 + 2 * ${number}}]]
+        set value [format %03x $base_val]
+
+        $controller usbCmd 000200${val_addr}0004${base_typ}${value}
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc rate_val_update {name key op} {
+        my instvar config rate_val
+
+        ${config}.rate_frame.${key}_value configure -text [format {%.2e} $rate_val(${key})]
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc cntr_val_update args {
+        my instvar cntr_val cntr_h cntr_m cntr_s
+
+        set cntr_tmp [expr {${cntr_val}/20000}]
+        set cntr_h [expr {${cntr_tmp}/3600000}]
+        set cntr_m [expr {${cntr_tmp}%3600000/60000}]
+        set cntr_s [expr {${cntr_tmp}%3600000%60000/1000.0}]
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc cntr_setup {} {
+        my instvar controller number cntr_val
+
+        set word0 [format %08x [expr {${cntr_val} & 0xFFFFFFFF}]]
+        set word1 [format %08x [expr {${cntr_val} >> 32}]]
+
+        set prefix [format %x [expr {5 + ${number}}]]
+
+        set command {}
+        append command 0001${prefix}000000200000004[string range $word0 4 7]
+        append command 0001${prefix}000000200010004[string range $word0 0 3]
+        append command 0001${prefix}000000200020004[string range $word1 4 7]
+        append command 0001${prefix}000000200030004[string range $word1 0 3]
+
+        # send counter value
+        $controller usbCmd $command
+
+        # load counter value
+#        set val_addr [format %02x [expr {12 + ${number}}]]
+#        $controller usbCmd 000200${val_addr}00040001000200${val_addr}00040000
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc cntr_reset {} {
+        my instvar controller number after_handle
+        my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old
+
+        my cntr_stop
+
+        set value [format %04x [expr {1 << (5 + ${number})}]]
+        $controller usbCmd 000200000004${value}0002000000040000
+
+        set cntr_val $cntr_bak
+        my cntr_setup
+
+        set cntr_old $cntr_bak
+        set yvec_bak 0.0
+        set yvec_old 0.0
+        
+        my acquire
+
+        my cntr_ready
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc cntr_ready {} {
+        my instvar config cntr_val cntr_bak
+
+        set cntr_val $cntr_bak
+
+        ${config}.start configure -text Start -command [myproc cntr_start]
+        ${config}.reset configure -state active
+
+        ${config}.cntr_frame.h_field configure -state normal
+        ${config}.cntr_frame.m_field configure -state normal
+        ${config}.cntr_frame.s_field configure -state normal
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc cntr_start {} {
+        my instvar config
+        my instvar cntr_h cntr_m cntr_s
+        my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old
+
+        set h $cntr_h
+        set m $cntr_m
+        set s $cntr_s
+
+        if {[string equal $h {}]} {
+            set h 0
+        }
+        if {[string equal $m {}]} {
+            set m 0
+        }
+        if {[string equal $s {}]} {
+            set s 0
+        }
+
+        set cntr_tmp [expr {${h}*3600000 + ${m}*60000 + ${s}*1000}]
+        set cntr_tmp [expr {entier(20000 * ${cntr_tmp})}]
+
+        if {$cntr_tmp > 0} {
+            ${config}.cntr_frame.h_field configure -state disabled
+            ${config}.cntr_frame.m_field configure -state disabled
+            ${config}.cntr_frame.s_field configure -state disabled
+
+            set cntr_val $cntr_tmp
+            set cntr_bak $cntr_tmp
+            set cntr_old $cntr_tmp
+            set yvec_bak [usb::integrateBlt [myvar yvec] 0]
+            set yvec_old $yvec_bak
+
+            my cntr_setup
+
+            my cntr_resume
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc cntr_pause {} {
+        my instvar config
+
+        my cntr_stop
+
+        ${config}.start configure -text Resume -command [myproc cntr_resume]
+#        ${config}.reset configure -state active
+
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc cntr_resume {} {
+        my instvar controller config number auto
+
+        set val_addr [format %02x [expr {13 + ${number}}]]
+
+        ${config}.start configure -text Pause -command [myproc cntr_pause]
+#        ${config}.reset configure -state disabled
+
+        $controller usbCmd 000200${val_addr}00040002
+
+        set auto 1
+
+        after 100 [myproc acquire_loop]
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc cntr_stop {} {
+        my instvar controller config number auto
+
+        set val_addr [format %02x [expr {13 + ${number}}]]
+
+        $controller usbCmd 000200${val_addr}00040000
+
+        set auto 0
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc data_update args {
+        my instvar data
+        usb::convertBlt $data 4 [myvar yvec]
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc acquire_loop {} {
+        my instvar cntr_val auto
+
+        my acquire
+
+        if {$cntr_val == 0} {
+            my cntr_stop
+            my cntr_ready
+        } elseif {$auto} {
+            after 1000 [myproc acquire_loop]
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc acquire {} {
+        my instvar controller config number
+        my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old rate_val
+
+        set size 4096
+
+        set prefix [format {%x} [expr {$number + 2}]]
+
+        set value [format {%08x} [expr {$size * 2}]]
+
+        set command 0001${prefix}000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000
+
+        $controller usbCmdReadRaw $command [expr {$size * 4}] [myvar data]
+        set yvec_new [usb::integrateBlt [myvar yvec]]
+
+        set prefix [format {%x} [expr {$number + 5}]]
+        set command 0001${prefix}000000200000003000400050000
+
+        $controller usbCmdReadHex $command 8 1 [myvar cntr_val]
+        set cntr_new $cntr_val
+
+        if {$cntr_new < $cntr_old} {
+            set rate_val(inst) [expr {($yvec_new - $yvec_old)*20000000/($cntr_old - $cntr_new)}]
+            set rate_val(mean) [expr {($yvec_new - $yvec_bak)*20000000/($cntr_bak - $cntr_new)}]
+            set yvec_old $yvec_new
+            set cntr_old $cntr_new
+        }
+   }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc save_data {data} {
+        my instvar number
+
+        set types {
+            {{Data Files}       {.dat}        }
+            {{All Files}        *             }
+        }
+
+        set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S]
+        set fname spectrum_[expr {$number + 1}]_${stamp}.dat
+
+        set fname [tk_getSaveFile -filetypes $types -initialfile $fname]
+        if {[string equal $fname {}]} {
+            return
+        }
+
+        set x [catch {
+            set fid [open $fname w+]
+            puts $fid $data
+            close $fid
+        }]
+
+        if { $x || ![file exists $fname] || ![file isfile $fname] || ![file readable $fname] } {
+            tk_messageBox -icon error \
+                -message "An error occurred while writing to \"$fname\""
+        } else {
+            tk_messageBox -icon info \
+                -message "File \"$fname\" written successfully"
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    HstDisplay instproc register {} {
+        my save_data [join [[myvar yvec] range 0 4095] \n]
+    }
+
+# -------------------------------------------------------------------------
+
+    Class CntDisplay -parameter {
+        {master}
+        {controller}
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc init {} {
+
+        my set data {}
+        my set cntr 0
+        my set recs 0
+
+        vector create [myvar xvec](16384)
+        vector create [myvar yvec](16384)
+
+        # fill one vector for the x axis with 16384 points
+        [myvar xvec] seq -0.5 16384.5
+
+        my setup
+
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc destroy {} {
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc start {} {
+        my instvar config
+
+        trace add variable [myvar data] write [myproc data_update]
+
+        trace add variable [myvar thrs_val] write [myproc thrs_val_update]
+
+        trace add variable [myvar cntr] write [myproc cntr_update]
+        trace add variable [myvar recs] write [myproc recs_update]
+
+        trace add variable [myvar axis] write [myproc axis_update]
+
+        ${config}.axis_check select
+
+        my set thrs_val 100
+
+        my set cntr_val 100
+        my set cntr_bak 100
+        my set recs_val 100
+        my set recs_bak 100
+
+#        my cntr_reset
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc setup {} {
+        my instvar master
+        my instvar xvec yvec graph
+        my instvar config
+        my instvar cntr_ms
+
+        # create a graph widget and show a grid
+        set graph [graph ${master}.graph -height 250 -leftmargin 80]
+        $graph crosshairs configure -hide no -linewidth 1 -color darkblue -dashes {2 2}
+        $graph grid configure -hide no
+        $graph legend configure -hide yes
+        $graph axis configure x -min 0 -max 16384
+
+        set config [frame ${master}.config -width 170]
+
+        checkbutton ${config}.axis_check -text {log scale} -variable [myvar axis]
+
+        frame ${config}.spc1 -width 170 -height 30
+
+        frame ${config}.chan_frame -borderwidth 0 -width 170
+        legendLabel ${config}.chan_frame 0 mean  {Mean value}
+        legendLabel ${config}.chan_frame 1 entr  {Total entries}
+        legendLabel ${config}.chan_frame 2 empty {}
+        legendLabel ${config}.chan_frame 3 axisy {Bin entries}
+        legendLabel ${config}.chan_frame 4 axisx {Bin number}
+
+        frame ${config}.spc3 -width 170 -height 30
+
+        label ${config}.thrs -text {amplitude threshold}
+        spinbox ${config}.thrs_field -from 1 -to 4095 \
+            -increment 5 -width 10 -textvariable [myvar thrs_val] \
+            -validate all -vcmd {::mca::validate 4095 4 %P}
+
+        frame ${config}.spc4 -width 170 -height 30
+
+        label ${config}.cntr -text {time of exposure (s)}
+        spinbox ${config}.cntr_field -from 0 -to 9999 \
+            -increment 10 -width 10 -textvariable [myvar cntr_val] \
+            -validate all -vcmd {::mca::validate 9999 4 %P}
+
+        frame ${config}.spc5 -width 170 -height 10
+
+        label ${config}.recs -text {number of exposures}
+        spinbox ${config}.recs_field -from 0 -to 99999 \
+            -increment 10 -width 10 -textvariable [myvar recs_val] \
+            -validate all -vcmd {::mca::validate 99999 5 %P}
+
+        frame ${config}.spc6 -width 170 -height 10
+
+        button ${config}.start -text {Start}  \
+            -bg yellow -activebackground yellow -command [myproc recs_start]
+
+        button ${config}.reset -text Reset \
+            -bg red -activebackground red -command [myproc cntr_reset]
+
+        frame ${config}.spc7 -width 170 -height 30
+
+        button ${config}.register -text Register \
+            -bg lightblue -activebackground lightblue -command [myproc register]
+
+        grid ${config}.axis_check -sticky w
+        grid ${config}.spc1
+        grid ${config}.chan_frame -sticky ew -padx 5
+        grid ${config}.spc3
+        grid ${config}.thrs -sticky w -pady 1 -padx 3
+        grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
+        grid ${config}.spc4
+        grid ${config}.cntr -sticky w -pady 1 -padx 3
+        grid ${config}.cntr_field -sticky ew -pady 1 -padx 5
+        grid ${config}.spc5
+        grid ${config}.recs -sticky w -pady 1 -padx 3
+        grid ${config}.recs_field -sticky ew -pady 1 -padx 5
+        grid ${config}.spc6
+        grid ${config}.start -sticky ew -pady 3 -padx 5
+        grid ${config}.reset -sticky ew -pady 3 -padx 5
+        grid ${config}.spc7
+        grid ${config}.register -sticky ew -pady 3 -padx 5
+
+        grid ${graph} -row 0 -column 0 -sticky news
+        grid ${config} -row 0 -column 1
+
+        grid rowconfigure ${master} 0 -weight 1
+        grid columnconfigure ${master} 0 -weight 1
+        grid columnconfigure ${master} 1 -weight 0 -minsize 80
+
+        grid columnconfigure ${config}.chan_frame 1 -weight 1
+
+        # enable zooming
+        Blt_ZoomStack $graph
+
+        my crosshairs $graph
+
+        #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
+
+        # create one element with data for the x and y axis, no dots
+        $graph element create Spectrum1 -color blue -linewidth 2 -symbol none -smooth step -xdata [myvar xvec] -ydata [myvar yvec]
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc coor_update {W x y} {
+        my instvar config graph
+
+        $W crosshairs configure -position @${x},${y}
+
+        set index [$W axis invtransform x $x]
+        set index [::tcl::mathfunc::round $index]
+        catch {
+            ${config}.chan_frame.axisy_value configure -text [[myvar yvec] index $index]
+            ${config}.chan_frame.axisx_value configure -text ${index}.0
+        }
+    }
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc crosshairs {graph} {
+        set method [myproc coor_update]
+        bind $graph <Motion> [list [self] coor_update %W %x %y]
+        bind $graph <Leave> {
+            %W crosshairs off
+        }
+        bind $graph <Enter> {
+            %W crosshairs on
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc thrs_val_update args {
+        my instvar controller config thrs_val
+
+        if {[string equal $thrs_val {}]} {
+            set thrs_val 0
+        }
+
+        set val_addr [format %02x 12]
+
+        ${config}.thrs_field configure -state normal
+        set value [format %03x $thrs_val]
+
+        $controller usbCmd 000200${val_addr}00040${value}
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc cntr_update args {
+        my instvar cntr cntr_val
+        set cntr_val [expr {${cntr}/20000000}]
+
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc recs_update args {
+        my instvar recs recs_val
+        set recs_val [expr {${recs}*1}]
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc cntr_setup {} {
+        my instvar controller cntr_val
+
+        set cntr_tmp [expr {${cntr_val} * 20000000}]
+        set word0 [format {%08x} [expr {${cntr_tmp} & 0xFFFFFFFF}]]
+        set word1 [format {%08x} [expr {${cntr_tmp} >> 32}]]
+
+        set prefix [format {%x} 9]
+
+        set command {}
+        append command 0001${prefix}000000200000004[string range $word0 4 7]
+        append command 0001${prefix}000000200010004[string range $word0 0 3]
+        append command 0001${prefix}000000200020004[string range $word1 4 7]
+        append command 0001${prefix}000000200030004[string range $word1 0 3]
+
+        # send counter value
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc recs_setup {} {
+        my instvar controller recs_val
+
+        set word0 [format {%08x} [expr {${recs_val} & 0xFFFFFFFF}]]
+        set word1 [format {%08x} [expr {${recs_val} >> 32}]]
+
+        set prefix [format {%x} 10]
+
+        set command {}
+        append command 0001${prefix}000000200000004[string range $word0 4 7]
+        append command 0001${prefix}000000200010004[string range $word0 0 3]
+        append command 0001${prefix}000000200020004[string range $word1 4 7]
+        append command 0001${prefix}000000200030004[string range $word1 0 3]
+
+        # send counter value
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc cntr_reset {} {
+        my instvar controller after_handle
+        my instvar cntr_val cntr_bak recs_val recs_bak
+
+        my cntr_stop
+
+        set value [format {%04x} [expr {1 << 11}]]
+        $controller usbCmd 000200000004${value}0002000000040000
+
+        my recs_stop
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc cntr_ready {} {
+        my instvar config cntr_val cntr_bak recs_val recs_bak
+
+        set cntr_val $cntr_bak
+        set recs_val $recs_bak
+
+        ${config}.start configure -text Start -command [myproc recs_start]
+        ${config}.reset configure -state active
+
+        ${config}.start configure -state active
+        ${config}.cntr_field configure -state normal
+        ${config}.recs_field configure -state normal
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc recs_start {} {
+        my instvar controller config auto
+        my instvar cntr_val cntr_bak recs_val recs_bak
+
+        if {$cntr_val > 0 && $recs_val > 0} {
+            ${config}.start configure -text {Stop} -command [myproc recs_stop]
+            ${config}.cntr_field configure -state disabled
+            ${config}.recs_field configure -state disabled
+
+            set cntr_bak $cntr_val
+            set recs_bak $recs_val
+
+            my cntr_setup
+            my recs_setup
+
+            set val_addr [format {%02x} 16]
+
+            $controller usbCmd 000200${val_addr}00040002
+
+            set auto 1
+
+            after 100 [myproc acquire_loop]
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc recs_stop {} {
+        my instvar cntr_val cntr_bak recs_val recs_bak
+
+        my cntr_stop
+
+        set cntr_val $cntr_bak
+        my cntr_setup
+
+        set recs_val $recs_bak
+        my recs_setup
+
+        my acquire
+
+        my cntr_ready
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc cntr_stop {} {
+        my instvar controller config auto
+
+        set val_addr [format {%02x} 16]
+
+        $controller usbCmd 000200${val_addr}00040000
+
+        set auto 0
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc acquire_loop {} {
+        my instvar recs_val auto
+
+        my acquire
+
+        if {$recs_val == 0} {
+            my cntr_stop
+            my cntr_ready
+        } elseif {$auto} {
+            after 1000 [myproc acquire_loop]
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc data_update args {
+        my instvar config data
+        usb::convertBlt $data 2 [myvar yvec]
+
+        ${config}.chan_frame.mean_value configure \
+            -text [format {%.2e} [usb::integrateBlt [myvar yvec] 1]]
+        ${config}.chan_frame.entr_value configure \
+            -text [usb::integrateBlt [myvar yvec] 0]
+
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc axis_update args {
+        my instvar axis graph
+        if {$axis} {
+            $graph axis configure y -min 1 -max 1E5 -logscale yes
+        } else {
+            $graph axis configure y -min {} -max {} -logscale no
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc acquire {} {
+        my instvar controller config
+        my instvar cntr cntr_val recs recs_val
+
+        set size 16384
+
+        set prefix [format {%x} 8]
+
+        set value [format {%08x} $size]
+
+        set command 0001${prefix}000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000
+
+        $controller usbCmdReadRaw $command [expr {$size * 2}] [myvar data]
+
+        set prefix [format {%x} 9]
+        set command 0001${prefix}000000200000003000400050000
+
+        $controller usbCmdReadHex $command 8 1 [myvar cntr]
+
+        set prefix [format {%x} 10]
+        set command 0001${prefix}000000200000003000400050000
+
+        $controller usbCmdReadHex $command 8 1 [myvar recs]
+   }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc save_data {data} {
+
+        set types {
+            {{Data Files}       {.dat}        }
+            {{All Files}        *             }
+        }
+
+        set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S]
+        set fname counts_${stamp}.dat
+
+        set fname [tk_getSaveFile -filetypes $types -initialfile $fname]
+        if {[string equal $fname {}]} {
+            return
+        }
+
+        set x [catch {
+            set fid [open $fname w+]
+            puts $fid $data
+            close $fid
+        }]
+
+        if { $x || ![file exists $fname] || ![file isfile $fname] || ![file readable $fname] } {
+            tk_messageBox -icon error \
+                -message "An error occurred while writing to \"$fname\""
+        } else {
+            tk_messageBox -icon info \
+                -message "File \"$fname\" written successfully"
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    CntDisplay instproc register {} {
+        my save_data [join [[myvar yvec] range 0 16383] \n]
+    }
+
+# -------------------------------------------------------------------------
+
+    Class OscDisplay -parameter {
+        {master}
+        {controller}
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc init {} {
+        my instvar sequence data xvec yvec
+
+        set data {}
+        
+        set sequence 0
+
+#        set xvec [vector create #auto(262144)]
+        set xvec [vector create #auto(10000)]
+
+        for {set i 1} {$i <= 9} {incr i} {
+#          dict set yvec $i [vector create #auto(262144)]
+          dict set yvec $i [vector create #auto(10000)]
+        }
+
+        # fill one vector for the x axis
+#        $xvec seq 0 262143
+        $xvec seq 0 10000
+
+        my setup
+
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc destroy {} {
+        next
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc start {} {
+        my instvar config
+        my instvar recs_val directory
+
+        set directory $::env(HOMEPATH)
+        set recs_val 100
+
+        trace add variable [myvar chan] write [myproc chan_update]
+
+        trace add variable [myvar data] write [myproc data_update]
+
+        trace add variable [myvar auto] write [myproc auto_update]
+
+        trace add variable [myvar thrs] write [myproc thrs_update 0]
+        trace add variable [myvar thrs_val] write [myproc thrs_update 0]
+
+        trace add variable [myvar recs_val] write [myproc recs_val_update]
+
+        trace add variable [myvar last] write [myproc last_update]
+
+        ${config}.chan_frame.chan1_check select
+        ${config}.chan_frame.chan2_check select
+        ${config}.chan_frame.chan3_check select
+        ${config}.chan_frame.chan4_check select
+        ${config}.chan_frame.chan5_check select
+        ${config}.chan_frame.chan6_check select
+
+        ${config}.thrs_check select
+        ${config}.thrs_field set 100
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc setup {} {
+        my instvar master
+        my instvar xvec yvec graph
+        my instvar config
+
+        # create a graph widget and show a grid
+        set graph [graph ${master}.graph -height 250 -leftmargin 80]
+        $graph crosshairs configure -hide no -linewidth 1 -color darkblue -dashes {2 2}
+        $graph grid configure -hide no
+        $graph legend configure -hide yes
+        $graph axis configure x -min 0 -max 10000
+        $graph axis configure y -min 0 -max 4100
+
+#        scale ${master}.last -orient horizontal -from 1 -to 27 -tickinterval 0 -showvalue no -variable [myvar last]
+
+        set config [frame ${master}.config -width 170]
+
+        frame ${config}.chan_frame -width 170
+        legendButton ${config}.chan_frame 0 chan1 {Channel 1} [myvar chan(1)] turquoise2
+        legendButton ${config}.chan_frame 1 chan2 {Channel 2} [myvar chan(2)] SpringGreen2
+        legendButton ${config}.chan_frame 2 chan3 {Channel 3} [myvar chan(3)] orchid2
+        legendButton ${config}.chan_frame 3 chan4 {Channel 4} [myvar chan(4)] orange2
+        legendButton ${config}.chan_frame 4 chan5 {Channel 5} [myvar chan(5)] blue1 white
+        legendButton ${config}.chan_frame 5 chan6 {Channel 6} [myvar chan(6)] gray65 white
+        legendLabel  ${config}.chan_frame 6 axisx {Time axis}
+
+        frame ${config}.spc1 -width 170 -height 30
+
+        checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto]
+
+        frame ${config}.spc2 -width 170 -height 30
+
+        checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
+        spinbox ${config}.thrs_field -from 1 -to 4095 \
+            -increment 5 -width 10 -textvariable [myvar thrs_val] \
+            -validate all -vcmd {::mca::validate 4095 4 %P}
+
+        frame ${config}.spc3 -width 170 -height 30
+
+        button ${config}.acquire -text Acquire \
+            -bg green -activebackground green -command [myproc acquire_start]
+        button ${config}.register -text Register \
+            -bg lightblue -activebackground lightblue -command [myproc register]
+
+        frame ${config}.spc4 -width 170 -height 30
+
+        label ${config}.recs -text {number of records}
+        spinbox ${config}.recs_field -from 0 -to 10000 \
+            -increment 10 -width 10 -textvariable [myvar recs_val] \
+            -validate all -vcmd {::mca::validate 10000 5 %P}
+
+        frame ${config}.spc5 -width 170 -height 10
+
+        button ${config}.sequence -text {Start Recording} -command [myproc sequence_start] \
+            -bg yellow -activebackground yellow
+
+        frame ${config}.spc6 -width 170 -height 10
+
+        button ${config}.recover -text {Read file} \
+            -bg lightblue -activebackground lightblue -command [myproc recover]
+
+        grid ${config}.chan_frame -sticky ew
+        grid ${config}.spc1
+        grid ${config}.auto_check -sticky w
+        grid ${config}.spc2
+        grid ${config}.thrs_check -sticky w
+        grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
+        grid ${config}.spc3
+        grid ${config}.acquire -sticky ew -pady 3 -padx 5
+        grid ${config}.register -sticky ew -pady 3 -padx 5
+        grid ${config}.spc4
+        grid ${config}.recs -sticky w -pady 1 -padx 3
+        grid ${config}.recs_field -sticky ew -pady 1 -padx 5
+        grid ${config}.spc5
+        grid ${config}.sequence -sticky ew -pady 3 -padx 5
+        grid ${config}.spc6
+        grid ${config}.recover -sticky ew -pady 3 -padx 5
+
+        grid ${graph} -row 0 -column 0 -sticky news
+        grid ${config} -row 0 -column 1
+
+#        grid ${master}.last -row 1 -column 0 -columnspan 2 -sticky ew
+
+        grid rowconfigure ${master} 0 -weight 1
+        grid columnconfigure ${master} 0 -weight 1
+        grid columnconfigure ${master} 1 -weight 0 -minsize 120
+
+        grid columnconfigure ${config}.chan_frame 2 -weight 1
+
+        # enable zooming
+        Blt_ZoomStack $graph
+
+        my crosshairs $graph
+
+        # create one element with data for the x and y axis, no dots
+        $graph pen create pen1 -color turquoise3 -linewidth 2 -symbol none
+        $graph pen create pen2 -color SpringGreen3 -linewidth 2 -symbol none
+        $graph pen create pen3 -color orchid3 -linewidth 2 -symbol none
+        $graph pen create pen4 -color orange3 -linewidth 2 -symbol none
+        $graph pen create pen5 -color blue2 -linewidth 2 -symbol none
+        $graph pen create pen6 -color gray55 -linewidth 2 -symbol none
+
+        $graph element create Spectrum1 -pen pen1 -xdata $xvec -ydata [dict get $yvec 1]
+        $graph element create Spectrum2 -pen pen2 -xdata $xvec -ydata [dict get $yvec 2]
+        $graph element create Spectrum3 -pen pen3 -xdata $xvec -ydata [dict get $yvec 3]
+        $graph element create Spectrum4 -pen pen4 -xdata $xvec -ydata [dict get $yvec 4]
+        $graph element create Spectrum5 -pen pen5 -xdata $xvec -ydata [dict get $yvec 5]
+        $graph element create Spectrum6 -pen pen6 -xdata $xvec -ydata [dict get $yvec 6]
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc coor_update {W x y} {
+        my instvar xvec yvec graph
+        my instvar config
+
+        $W crosshairs configure -position @${x},${y}
+
+        set index [$W axis invtransform x $x]
+        set index [::tcl::mathfunc::round $index]
+        catch {
+            ${config}.chan_frame.chan1_value configure -text [[dict get $yvec 1] index $index]
+            ${config}.chan_frame.chan2_value configure -text [[dict get $yvec 2] index $index]
+            ${config}.chan_frame.chan3_value configure -text [[dict get $yvec 3] index $index]
+            ${config}.chan_frame.chan4_value configure -text [[dict get $yvec 4] index $index]
+            ${config}.chan_frame.chan5_value configure -text [[dict get $yvec 5] index $index]
+            ${config}.chan_frame.chan6_value configure -text [[dict get $yvec 6] index $index]
+            ${config}.chan_frame.axisx_value configure -text ${index}.0
+        }
+    }
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc crosshairs {graph} {
+        set method [myproc coor_update]
+        bind $graph <Motion> [list [self] coor_update %W %x %y]
+        bind $graph <Leave> {
+            %W crosshairs off
+        }
+        bind $graph <Enter> {
+            %W crosshairs on
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc chan_update {name key op} {
+        my instvar config graph chan
+
+        if {$chan(${key})} {
+            $graph pen configure pen${key} -linewidth 2
+        } else {
+            $graph pen configure pen${key} -linewidth 0
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc recs_val_update args {
+        my instvar recs_val
+        if {[string equal $recs_val {}]} {
+            set recs_val 0
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc last_update args {
+        my instvar graph last
+
+        set first [expr {$last - 1}]
+
+        $graph axis configure x -min ${first}0000 -max ${last}0000
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc thrs_update {reset args} {
+        my instvar controller config thrs thrs_val
+
+        if {[string equal $thrs_val {}]} {
+            set thrs_val 0
+        }
+
+        if {$thrs} {
+            ${config}.thrs_field configure -state normal
+            set value [format %03x $thrs_val]
+        } else {
+            ${config}.thrs_field configure -state disabled
+            set value 000
+        }
+
+        set command {}
+        if {$reset} {
+            append command 0002000500041${value}
+        }
+        append command 0002000500040${value}
+
+        $controller usbCmd $command
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc data_update args {
+        my instvar data yvec
+        my instvar graph chan waiting sequence auto
+
+        usb::convertOsc $data $yvec
+
+        foreach {key value} [array get chan] {
+            $graph pen configure pen${key} -dashes 0
+        }
+
+        set waiting 0
+
+        if {$sequence} {
+            my sequence_register
+        } elseif {$auto} {
+            after 1000 [myproc acquire_start]
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc acquire_start {} {
+        my instvar graph chan controller waiting
+
+        foreach {key value} [array get chan] {
+            $graph pen configure pen${key} -dashes dot
+        }
+
+        # restart
+        my thrs_update 1
+
+        set waiting 1
+
+        after 200 [myproc acquire_loop]
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc acquire_loop {} {
+        my instvar controller waiting
+
+#        set size 262144
+        set size 10000
+
+        set value [format {%08x} [expr {$size * 4}]]
+
+        set command 00011000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000
+        
+        $controller usbCmdReadRaw $command [expr {$size * 8}] [myvar data]
+
+        if {$waiting} {
+            after 200 [myproc acquire_loop]
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc auto_update args {
+        my instvar config auto
+
+        if {$auto} {
+            ${config}.recs_field configure -state disabled
+            ${config}.sequence configure -state disabled
+            ${config}.acquire configure -state disabled
+            ${config}.register configure -state disabled
+            ${config}.recover configure -state disabled
+
+            my acquire_start
+        } else {
+            ${config}.recs_field configure -state normal
+            ${config}.sequence configure -state active
+            ${config}.acquire configure -state active
+            ${config}.register configure -state active
+            ${config}.recover configure -state active
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc save_data {fname} {
+        my instvar data
+
+        set fid [open $fname w+]
+        fconfigure $fid -translation binary -encoding binary
+
+#        puts -nonewline $fid [binary format "H*iH*" "1f8b0800" [clock seconds] "0003"]
+#        puts -nonewline $fid [zlib deflate $data]
+        puts -nonewline $fid $data
+#        puts -nonewline $fid [binary format i [zlib crc32 $data]]
+#        puts -nonewline $fid [binary format i [string length $data]]
+
+        close $fid
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc open_data {} {
+        set types {
+            {{Data Files}       {.dat}     }
+            {{All Files}        *             }
+        }
+
+        set fname [tk_getOpenFile -filetypes $types]
+        if {[string equal $fname {}]} {
+            return
+        }
+
+        set x [catch {
+            set fid [open $fname r+]
+            fconfigure $fid -translation binary -encoding binary
+#            set size [file size $fname]
+#            seek $fid 10
+#            my set data [zlib inflate [read $fid [expr {$size - 18}]]]
+            my set data [read $fid]
+            close $fid
+        }]
+
+        if { $x || ![file exists $fname] || ![file isfile $fname] || ![file readable $fname] } {
+            tk_messageBox -icon error \
+                -message "An error occurred while reading \"$fname\""
+        } else {
+            tk_messageBox -icon info \
+                -message "File \"$fname\" read successfully"
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc register {} {
+        set types {
+            {{Data Files}       {.dat}     }
+            {{All Files}        *             }
+        }
+
+        set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S]
+        set fname oscillogram_${stamp}.dat
+
+        set fname [tk_getSaveFile -filetypes $types -initialfile $fname]
+        if {[string equal $fname {}]} {
+            return
+        }
+    
+        if {[catch {my save_data $fname} result]} {
+            tk_messageBox -icon error \
+                -message "An error occurred while writing to \"$fname\""
+        } else {
+            tk_messageBox -icon info \
+                -message "File \"$fname\" written successfully"
+        }
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc recover {} {
+        my open_data
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc sequence_start {} {
+        my instvar config recs_val recs_bak directory counter sequence
+
+        set counter 1
+        if {$counter > $recs_val} {
+            return
+        }
+
+        set directory [tk_chooseDirectory -initialdir $directory -title {Choose a directory}]
+
+        if {[string equal $directory {}]} {
+           return
+        }
+
+        ${config}.recs_field configure -state disabled
+        ${config}.sequence configure -text {Stop Recording} -command [myproc sequence_stop]
+        ${config}.acquire configure -state disabled
+        ${config}.register configure -state disabled
+        ${config}.recover configure -state disabled
+        
+        set recs_bak $recs_val
+
+        set sequence 1
+
+        my acquire_start
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc sequence_register {} {
+        my instvar config recs_val recs_bak directory counter
+
+        set fname [file join $directory oscillogram_$counter.dat]
+
+        my incr counter
+
+        if {[catch {my save_data $fname} result]} {
+            tk_messageBox -icon error \
+                -message "An error occurred while writing to \"$fname\""
+        } elseif {$counter <= $recs_bak} {
+            set recs_val [expr {$recs_bak - $counter}]
+            my acquire_start
+            return
+        }
+        
+        my sequence_stop
+    }
+
+# -------------------------------------------------------------------------
+
+    OscDisplay instproc sequence_stop {} {
+        my instvar config recs_val recs_bak sequence
+
+        set sequence 0
+        
+        set recs_val $recs_bak
+
+        ${config}.recs_field configure -state normal
+        ${config}.sequence configure -text {Start Recording} -command [myproc sequence_start]
+        ${config}.acquire configure -state active
+        ${config}.register configure -state active
+        ${config}.recover configure -state active
+    }
+
+# -------------------------------------------------------------------------
+
+    namespace export MuxDisplay
+    namespace export HstDisplay
+    namespace export CntDisplay
+    namespace export OscDisplay
+}
+
+set notebook [::blt::tabnotebook .notebook -borderwidth 1 -selectforeground black -side bottom]
+
+grid ${notebook} -row 0 -column 0  -sticky news -pady 5
+
+grid rowconfigure . 0 -weight 1
+grid columnconfigure . 0 -weight 1
+
+::mca::UsbController usb
+usb usbCmd 00000000
+
+set window [frame ${notebook}.spi]
+$notebook insert end -text "DAC & ADC control" -window $window -fill both
+::mca::SpiDisplay spi -master $window -controller usb
+
+set window [frame ${notebook}.mux]
+$notebook insert end -text "Interconnect" -window $window -fill both
+::mca::MuxDisplay mux -master $window -controller usb
+
+set window [frame ${notebook}.ept]
+$notebook insert end -text "Oscilloscope" -window $window -fill both
+::mca::OscDisplay osc -master $window -controller usb
+
+update
+
+spi start
+
+mux start
+
+osc start
+
+spi adc_reset
Index: /trunk/3DEES/adc_lvds.v
===================================================================
--- /trunk/3DEES/adc_lvds.v	(revision 177)
+++ /trunk/3DEES/adc_lvds.v	(revision 177)
@@ -0,0 +1,123 @@
+
+(* ALTERA_ATTRIBUTE = {"{-to int_data_p} DDIO_INPUT_REGISTER=HIGH; {-to int_data_n} DDIO_INPUT_REGISTER=LOW"} *)
+
+module adc_lvds
+	#(
+		parameter	size	=	8, // number of channels
+		parameter	width	=	24 // channel resolution
+	)
+	(
+		input	wire						clock,
+
+		input	wire						lvds_dco,
+		input	wire						lvds_fco,
+ 		input	wire	[size-1:0]			lvds_d,
+
+		output	wire						adc_frame,
+		output	wire	[size*width-1:0]	adc_data
+
+	);
+	localparam	width2	=	width + 2;
+		
+	reg							state, int_rdreq, adc_frame_reg;
+	wire						int_wrfull, int_rdempty;
+
+	reg		[size-1:0]			int_data_p, int_data_n;
+
+	reg 	[2:0]				int_edge_reg;
+
+	reg 	[size*width-1:0]	int_fifo_reg;
+	wire	[size*width-1:0]	int_fifo_wire;
+
+	reg 	[size*width2-1:0]	int_data_reg;
+	wire	[size*width2-1:0]	int_data_wire;
+
+	wire	[size*width-1:0]	int_q_wire;
+	reg		[size*width-1:0]	adc_data_reg;
+	
+
+
+	genvar j;
+
+	generate
+		for (j = 0; j < size; j = j + 1)
+		begin : INT_DATA
+// MSB first
+//			assign int_data_wire[j*width+width-1:j*width] = {int_data_reg[j*width+width-3:j*width], int_data_p[j], int_data_n[j]};
+// LSB first
+//			assign int_data_wire[j*width+width-1:j*width] = {int_data_n[j], int_data_p[j], int_data_reg[j*width+width-1:j*width+2]};
+			assign int_data_wire[j*width2+width2-1:j*width2] = {int_data_n[j], int_data_p[j], int_data_reg[j*width2+width2-1:j*width2+2]};
+			assign int_fifo_wire[j*width+width-1:j*width] = int_data_reg[j*width2+width2-3:j*width2];
+		end
+	endgenerate
+
+	dcfifo #(
+		.intended_device_family("Cyclone III"),
+		.lpm_numwords(16),
+		.lpm_showahead("ON"),
+		.lpm_type("dcfifo"),
+		.lpm_width(size*width),
+		.lpm_widthu(4),
+		.rdsync_delaypipe(4),
+		.wrsync_delaypipe(4),
+		.overflow_checking("ON"),
+		.underflow_checking("ON"),
+		.use_eab("ON")) fifo_unit (
+//		.data(int_data_wire),
+		.data(int_fifo_reg),
+		.rdclk(clock),
+		.rdreq((~int_rdempty) & int_rdreq),
+		.wrclk(lvds_fco),
+		.wrreq(~int_wrfull),
+		.q(int_q_wire),
+		.rdempty(int_rdempty),
+		.wrfull(int_wrfull),
+		.aclr(),
+		.rdfull(),
+		.rdusedw(),
+		.wrempty(),
+		.wrusedw());
+
+	always @ (posedge clock)
+	begin
+		case (state)
+			1'b0:
+			begin
+				int_rdreq <= 1'b1;
+				adc_frame_reg <= 1'b0;
+				state <= 1'b1;
+			end
+
+			1'b1: 
+			begin
+				if (~int_rdempty)
+				begin
+					int_rdreq <= 1'b0;
+					adc_frame_reg <= 1'b1;
+					adc_data_reg <= int_q_wire;
+					state <= 1'b0;
+				end
+			end
+		endcase
+	end
+	
+	always @ (negedge lvds_dco)
+	begin
+		int_data_n <= lvds_d;
+	end
+
+	always @ (posedge lvds_dco)
+	begin
+		int_data_p <= lvds_d;
+		int_data_reg <= int_data_wire;
+		int_edge_reg <= {(~int_edge_reg[1]), int_edge_reg[0], lvds_fco};
+		if (int_edge_reg[1] & int_edge_reg[2])
+		begin
+			int_fifo_reg <= int_fifo_wire;
+		end
+	end
+
+	assign	adc_frame = adc_frame_reg;
+	assign	adc_data = adc_data_reg;
+
+endmodule
Index: /trunk/3DEES/amplitude.v
===================================================================
--- /trunk/3DEES/amplitude.v	(revision 177)
+++ /trunk/3DEES/amplitude.v	(revision 177)
@@ -0,0 +1,100 @@
+module amplitude
+	#(
+		parameter	width	=	12 // bit width of the input data
+	)
+	(
+		input	wire				clock, frame, reset,
+		input	wire	[width-1:0]	cfg_data,
+		input	wire	[width-1:0]	inp_data,
+		output	wire	[width-1:0]	out_data,
+		output	wire				out_flag
+	);
+
+	reg					int_case_reg, int_case_next;
+	reg					out_flag_reg, out_flag_next;
+	reg					int_flag_reg, int_flag_next;
+	reg		[width-1:0]	int_mini_reg, int_mini_next;
+	reg		[width-1:0]	out_data_reg, out_data_next;
+	reg		[width-1:0]	inp_data_reg [1:0], inp_data_next [1:0];
+
+	wire				int_comp_wire;
+	reg					int_comp_reg, int_comp_next;
+
+	assign int_comp_wire = (inp_data_reg[1] < inp_data);
+
+	always @(posedge clock)
+	begin
+		if (reset)
+		begin
+			int_case_reg <= 1'b0;
+			int_mini_reg <= {(width){1'b0}};
+			inp_data_reg[0] <= {(width){1'b0}};
+			inp_data_reg[1] <= {(width){1'b0}};
+			out_data_reg <= {(width){1'b0}};
+			out_flag_reg <= 1'b0;
+			int_flag_reg <= 1'b0;
+			int_comp_reg <= 1'b0;
+		end
+		else
+		begin
+			int_case_reg <= int_case_next;
+			int_mini_reg <= int_mini_next;
+			inp_data_reg[0] <= inp_data_next[0];
+			inp_data_reg[1] <= inp_data_next[1];
+			out_data_reg <= out_data_next;
+			out_flag_reg <= out_flag_next;
+			int_flag_reg <= int_flag_next;
+			int_comp_reg <= int_comp_next;
+		end
+	end
+	
+	always @*
+	begin
+		int_case_next = int_case_reg;
+		int_mini_next = int_mini_reg;
+		inp_data_next[0] = inp_data_reg[0];
+		inp_data_next[1] = inp_data_reg[1];
+		out_data_next = out_data_reg;
+		out_flag_next = out_flag_reg;
+		int_flag_next = int_flag_reg;
+		int_comp_next = int_comp_reg;
+		
+		case (int_case_reg)
+			0:
+			begin
+				if (frame)
+				begin
+					inp_data_next[0] = inp_data;
+					inp_data_next[1] = inp_data_reg[0];
+					int_comp_next = int_comp_wire;
+					out_data_next = {(width){1'b0}};
+					out_flag_next = 1'b0;
+					// minimum
+					if ((~int_comp_reg) & (int_comp_wire))
+					begin
+						int_mini_next = inp_data_reg[0];
+						int_flag_next = 1'b1;
+					end
+					// maximum
+					else if ((int_comp_reg) & (~int_comp_wire) & (int_flag_reg))
+					begin
+						out_data_next = inp_data_reg[0] - int_mini_reg;
+						int_flag_next = 1'b0;
+						int_case_next = 1'b1;
+					end
+                end
+ 			end
+			
+			1:
+			begin
+				out_flag_next = (out_data_reg >= cfg_data);
+				int_case_next = 1'b0;
+ 			end
+
+		endcase
+	end
+
+	assign out_data = out_data_reg;
+	assign out_flag = out_flag_reg;
+
+endmodule
Index: /trunk/3DEES/analyser.v
===================================================================
--- /trunk/3DEES/analyser.v	(revision 177)
+++ /trunk/3DEES/analyser.v	(revision 177)
@@ -0,0 +1,187 @@
+module analyser
+	(
+		input	wire			clock, frame, reset,
+		input	wire	[24:0]	cfg_data,
+		input	wire	[1:0]	uwt_flag,
+		input	wire	[11:0]	uwt_data,
+		output	wire			ana_dead,
+		output	wire			ana_good,
+		output	wire	[11:0]	ana_data,
+		output	wire	[11:0]	ana_base
+	);
+
+	reg		[2:0]	state_reg, state_next;
+	reg		[4:0]	counter_reg, counter_next;
+	reg				dead_reg, dead_next;
+	reg				good_reg, good_next;
+	reg		[11:0]	data_reg, data_next;
+
+	reg		[19:0]	sample_reg, sample_next;
+
+	reg		[19:0]	buffer_reg [31:0];
+	reg		[19:0]	buffer_next [31:0];
+
+	wire	[11:0]	baseline = buffer_reg[31][16:5];
+	wire			counter_max = (&counter_reg);
+
+	integer i;
+
+	always @(posedge clock)
+	begin
+		if (reset)
+		begin
+			state_reg <= 3'd0;
+			counter_reg <= 5'd0;
+			sample_reg <= 20'd0;
+			dead_reg <= 1'b0;
+			good_reg <= 1'b0;
+			data_reg <= 12'd0;
+
+			for (i = 0; i <= 31; i = i + 1)
+			begin
+				buffer_reg[i] <= 20'hfffff;
+			end
+		end
+		else
+		begin
+			state_reg <= state_next;
+			counter_reg <= counter_next;
+			sample_reg <= sample_next;
+			dead_reg <= dead_next;
+			good_reg <= good_next;
+			data_reg <= data_next;
+
+			for (i = 0; i <= 31; i = i + 1)
+			begin
+				buffer_reg[i] <= buffer_next[i];
+			end
+		end
+	end
+	
+	always @*
+	begin
+		state_next = state_reg;
+		counter_next = counter_reg;
+		sample_next = sample_reg;
+		dead_next = dead_reg;
+		good_next = good_reg;
+		data_next = data_reg;
+		
+		for (i = 0; i <= 31; i = i + 1)
+		begin
+			buffer_next[i] = buffer_reg[i];
+		end
+
+		case (state_reg)
+			0: // skip first 32 samples
+			begin
+				if (frame)
+				begin
+					counter_next = counter_reg + 5'd1;
+					if (counter_max)
+					begin
+						state_next = 3'd1;
+					end
+                end
+ 			end
+
+			1: // skip first 32 baseline samples
+			begin
+				if (frame)
+				begin
+					for (i = 0; i < 31; i = i + 1)
+					begin
+						buffer_next[i+1] = buffer_reg[i] + {8'd0, uwt_data};
+					end
+					buffer_next[0] = {8'd0, uwt_data};
+
+					counter_next = counter_reg + 5'd1;
+					if (counter_max)
+					begin
+						state_next = 3'd2;
+					end
+                end
+ 			end
+
+			2:
+			begin
+				if (frame)
+				begin
+
+					if (cfg_data[24])
+					begin
+						if (uwt_data > baseline)
+						begin
+							data_next = uwt_data - baseline;
+						end
+						else
+						begin
+							data_next = 12'd0;
+						end
+					end
+					else
+					begin
+						if (uwt_data > cfg_data[23:12])
+						begin
+							data_next = uwt_data - cfg_data[23:12];
+						end
+						else
+						begin
+							data_next = 12'd0;
+						end
+					end
+	
+					sample_next = {8'd0, uwt_data};
+
+					dead_next = 1'b1;
+					good_next = 1'b0;
+
+					state_next = 3'd3;
+				end
+			end
+			
+			3:
+			begin
+
+				// if (sample - baseline < threshold)
+				if (data_reg < cfg_data[11:0])
+				begin
+					for (i = 0; i < 31; i = i + 1)
+					begin
+						buffer_next[i+1] = buffer_reg[i] + sample_reg;
+					end
+					buffer_next[0] = sample_reg;
+					dead_next = 1'b0;
+				end
+
+				state_next = 3'd2;
+
+				// skip 32 samples after peak
+				if (counter_max)
+				begin
+					if (uwt_flag[1])
+					begin
+						counter_next = 5'd0;
+						state_next = 3'd4;
+					end
+				end
+				else
+				begin
+					counter_next = counter_reg + 5'd1;
+				end	
+			end
+
+			4:
+			begin
+				good_next = dead_reg;
+				state_next = 2'd2;
+ 			end
+		endcase
+	end
+
+	assign ana_dead = dead_reg;
+	assign ana_good = good_reg;
+	assign ana_data = data_reg;
+	assign ana_base = baseline;
+
+endmodule
Index: /trunk/3DEES/average.v
===================================================================
--- /trunk/3DEES/average.v	(revision 177)
+++ /trunk/3DEES/average.v	(revision 177)
@@ -0,0 +1,305 @@
+module average
+	#(
+		parameter	size	=	1, // number of channels
+		parameter	width	=	16 // bit width of the input data
+	)
+	(
+		input	wire						clock, frame, reset,
+		input	wire	[3*size*6-1:0]		del_data,
+		input	wire	[3*size*width-1:0]	inp_data,
+		output	wire	[3*size*width2-1:0]	out_data
+	);
+
+	localparam	width1	=	width + 1;
+	localparam	width2	=	width + 6 + 1;
+
+	reg							int_wren_reg, int_wren_next;
+	reg		[1:0]				int_chan_reg, int_chan_next;
+	reg		[2:0]				int_case_reg, int_case_next;
+	reg		[7:0]				int_addr_reg, int_addr_next;
+
+	reg		[5:0]				del_addr_reg, del_addr_next;
+	wire	[5:0]				del_addr_wire;
+	wire	[7:0]				int_addr_wire;
+
+	reg		[size*width2-1:0]	acc_data_reg [3:0], acc_data_next [3:0];
+	wire	[size*width2-1:0]	acc_data_wire;
+
+	reg		[size*width1-1:0]	sub_data_reg [3:0], sub_data_next [3:0];
+	wire	[size*width1-1:0]	sub_data_wire;
+
+	reg		[size*width-1:0]	inp_data_reg [2:0], inp_data_next [2:0];
+	wire	[size*width-1:0]	inp_data_wire [3:0];
+
+	integer i;
+	genvar j;
+
+	generate
+		for (j = 0; j < size; j = j + 1)
+		begin : INT_DATA
+			assign inp_data_wire[0][j*width+width-1:j*width] = inp_data[(3*j+0)*width+width-1:(3*j+0)*width];
+			assign inp_data_wire[1][j*width+width-1:j*width] = inp_data[(3*j+1)*width+width-1:(3*j+1)*width];
+			assign inp_data_wire[2][j*width+width-1:j*width] = inp_data[(3*j+2)*width+width-1:(3*j+2)*width];
+                                                                                         
+			lpm_mux #(
+				.lpm_size(3),
+				.lpm_type("LPM_MUX"),
+				.lpm_width(8),
+				.lpm_widths(2)) mux_unit_1 (
+				.sel(int_chan_next),
+				.data({
+					2'd2, del_data[(3*j+2)*6+6-1:(3*j+2)*6],
+					2'd1, del_data[(3*j+1)*6+6-1:(3*j+1)*6],
+					2'd0, del_data[(3*j+0)*6+6-1:(3*j+0)*6]}),
+				.result(int_addr_wire));
+
+			lpm_add_sub	#(
+				.lpm_direction("SUB"),
+				.lpm_hint("ONE_INPUT_IS_CONSTANT=NO,CIN_USED=NO"),
+				.lpm_representation("UNSIGNED"),
+				.lpm_type("LPM_ADD_SUB"),
+				.lpm_width(6)) add_unit_1 (
+				.dataa(del_addr_reg),
+				.datab(int_addr_wire[5:0]),
+				.result(del_addr_wire));
+
+			lpm_add_sub	#(
+				.lpm_direction("SUB"),
+				.lpm_hint("ONE_INPUT_IS_CONSTANT=NO,CIN_USED=NO"),
+				.lpm_representation("SIGNED"),
+				.lpm_type("LPM_ADD_SUB"),
+				.lpm_width(width1)) sub_unit_1 (
+				.dataa({{(width1-width){1'b0}}, inp_data_reg[0][j*width+width-1:j*width]}),
+				.datab({{(width1-width){1'b0}}, inp_data_wire[3][j*width+width-1:j*width]}),
+				.result(sub_data_wire[j*width1+width1-1:j*width1]));
+
+			lpm_add_sub	#(
+				.lpm_direction("ADD"),
+				.lpm_hint("ONE_INPUT_IS_CONSTANT=NO,CIN_USED=NO"),
+				.lpm_representation("SIGNED"),
+				.lpm_type("LPM_ADD_SUB"),
+				.lpm_width(width2)) acc_unit_1 (
+				.dataa({{(width2-width1+1){sub_data_reg[0][j*width1+width1-1]}}, sub_data_reg[0][j*width1+width1-2:j*width1]}),
+				.datab(acc_data_reg[0][j*width2+width2-1:j*width2]),
+				.result(acc_data_wire[j*width2+width2-1:j*width2]));
+
+		end
+	endgenerate
+
+
+	altsyncram #(
+		.address_aclr_b("NONE"),
+		.address_reg_b("CLOCK0"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_input_b("BYPASS"),
+		.clock_enable_output_b("BYPASS"),
+		.intended_device_family("Cyclone III"),
+		.lpm_type("altsyncram"),
+		.numwords_a(256),
+		.numwords_b(256),
+		.operation_mode("DUAL_PORT"),
+		.outdata_aclr_b("NONE"),
+		.outdata_reg_b("CLOCK0"),
+		.power_up_uninitialized("FALSE"),
+		.read_during_write_mode_mixed_ports("DONT_CARE"),
+		.widthad_a(8),
+		.widthad_b(8),
+		.width_a(size*width),
+		.width_b(size*width),
+		.width_byteena_a(1)) ram_unit_1 (
+		.wren_a(int_wren_reg),
+		.clock0(clock),
+		.address_a(int_addr_reg),
+		.address_b({int_addr_wire[7:6], del_addr_wire}),
+		.data_a(inp_data_reg[0]),
+		.q_b(inp_data_wire[3]),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.data_b({(size*width){1'b1}}),
+		.eccstatus(),
+		.q_a(),
+		.rden_a(1'b1),
+		.rden_b(1'b1),
+		.wren_b(1'b0));
+
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			int_wren_reg <= 1'b1;
+			int_chan_reg <= 2'd0;
+			int_case_reg <= 3'd0;
+			del_addr_reg <= 6'd0;
+			int_addr_reg <= 8'd0;
+			for(i = 0; i <= 2; i = i + 1)
+			begin
+				inp_data_reg[i] <= {(size*width){1'b0}};
+			end
+			for(i = 0; i <= 3; i = i + 1)
+			begin
+				sub_data_reg[i] <= {(size*width1){1'b0}};
+				acc_data_reg[i] <= {(size*width2){1'b0}};
+			end
+		end
+		else
+		begin
+			int_wren_reg <= int_wren_next;
+			int_chan_reg <= int_chan_next;
+			int_case_reg <= int_case_next;
+			del_addr_reg <= del_addr_next;
+			int_addr_reg <= int_addr_next;
+			for(i = 0; i <= 2; i = i + 1)
+			begin
+				inp_data_reg[i] <= inp_data_next[i];
+			end                  
+			for(i = 0; i <= 3; i = i + 1)
+			begin
+				sub_data_reg[i] <= sub_data_next[i];
+				acc_data_reg[i] <= acc_data_next[i];
+			end
+		end             
+	end
+	
+	always @*
+	begin
+		int_wren_next = int_wren_reg;
+		int_chan_next = int_chan_reg;
+		int_case_next = int_case_reg;
+		del_addr_next = del_addr_reg;
+		int_addr_next = int_addr_reg;
+		for(i = 0; i <= 2; i = i + 1)
+		begin
+			inp_data_next[i] = inp_data_reg[i];
+		end                  
+		for(i = 0; i <= 3; i = i + 1)
+		begin
+			sub_data_next[i] = sub_data_reg[i];
+			acc_data_next[i] = acc_data_reg[i];
+		end
+
+		case (int_case_reg)		
+			0:
+			begin
+				// write zeros
+				int_wren_next = 1'b1;
+				del_addr_next = 6'd0;
+				int_addr_next = 8'd0;
+				for(i = 0; i <= 2; i = i + 1)
+				begin
+					inp_data_next[i] = {(size*width){1'b0}};
+				end                  
+				for(i = 0; i <= 3; i = i + 1)
+				begin
+					sub_data_next[i] = {(size*width1){1'b0}};
+					acc_data_next[i] = {(size*width2){1'b0}};
+				end
+
+				int_case_next = 3'd1;
+			end	
+			1:
+			begin
+				// write zeros
+				int_addr_next = int_addr_reg + 8'd1;
+				if (&int_addr_reg)
+				begin
+					int_wren_next = 1'b0;
+					int_chan_next = 2'd0;
+					int_case_next = 3'd2;
+				end
+			end	
+			2: // frame
+			begin
+				if (frame)
+				begin
+					int_wren_next = 1'b1;
+
+					int_addr_next[7:6] = 2'd0;
+					
+					// set read addr for 2nd pipeline
+					int_chan_next = 2'd1;
+
+					// register input data for 2nd and 3rd sums
+					inp_data_next[1] = inp_data_wire[1];
+					inp_data_next[2] = inp_data_wire[2];
+
+					// prepare registers for 1st sum					
+					inp_data_next[0] = inp_data_wire[0];
+
+					sub_data_next[0] = sub_data_reg[1];
+					acc_data_next[0] = acc_data_reg[1];
+
+					int_case_next = 3'd3;
+				end
+
+			end
+			3:  // 1st sum
+			begin				
+				int_addr_next[7:6] = 2'd1;
+
+				// set read addr for 3rd pipeline
+				int_chan_next = 2'd2;
+
+				// prepare registers for 2nd sum
+				inp_data_next[0] = inp_data_reg[1];
+					
+				sub_data_next[0] = sub_data_reg[2];
+				acc_data_next[0] = acc_data_reg[2];
+				
+				// register 1st sum
+				sub_data_next[1] = sub_data_wire;
+				acc_data_next[1] = acc_data_wire;
+
+				int_case_next = 3'd4;
+			end
+			4: // 2nd sum
+			begin
+				int_addr_next[7:6] = 2'd2;
+
+				// prepare registers for 3rd sum	
+				inp_data_next[0] = inp_data_reg[2];
+
+				sub_data_next[0] = sub_data_reg[3];
+				acc_data_next[0] = acc_data_reg[3];
+				
+				// register 2nd sum
+				sub_data_next[2] = sub_data_wire;
+				acc_data_next[2] = acc_data_wire;
+				
+				del_addr_next = del_addr_reg + 6'd1;
+
+				int_case_next = 3'd5;
+			end
+			5:  // 3rd sum
+			begin				
+				int_wren_next = 1'b0;
+
+				// set read addr for 1st pipeline
+				int_chan_next = 2'd0;
+
+				// register 3rd sum
+				sub_data_next[3] = sub_data_wire;
+				acc_data_next[3] = acc_data_wire;
+                                             
+				int_addr_next[5:0] = del_addr_reg;
+
+				int_case_next = 3'd2;
+			end
+			default:
+			begin
+				int_case_next = 3'd0;
+			end
+		endcase
+	end
+
+	assign out_data = {acc_data_reg[3], acc_data_reg[2], acc_data_reg[1]};
+
+endmodule
Index: /trunk/3DEES/cic_filter.v
===================================================================
--- /trunk/3DEES/cic_filter.v	(revision 177)
+++ /trunk/3DEES/cic_filter.v	(revision 177)
@@ -0,0 +1,273 @@
+module cic_filter
+	#(
+		parameter	size	=	3, // number of channels
+		parameter	width	=	12 // bit width of the input data (unsigned)
+	)
+	(
+		input	wire						clock, frame, reset,
+		input	wire	[size*width-1:0]	inp_data,
+		output	wire	[size*widthr-1:0]	out_data,
+		output	wire	[size*widthr-1:0]	out_data2,
+		output	wire	[size*widthr-1:0]	out_data3
+	);
+	
+	localparam	widthr	=	width + 16;
+	/*
+	4-bit LFSR with additional bits to keep track of previous values
+	*/
+	reg		[15:0]				int_lfsr_reg, int_lfsr_next;
+
+	reg							int_wren_reg, int_wren_next;
+	reg							int_flag_reg, int_flag_next;
+	reg		[1:0]				int_chan_reg, int_chan_next;
+	reg		[2:0]				int_case_reg, int_case_next;
+	reg		[7:0]				int_addr_reg, int_addr_next;
+
+	wire	[9:0]				int_addr_wire;
+
+	reg		[size*widthr-1:0]	acc_data_reg [3:0], acc_data_next [3:0];
+	reg		[size*widthr-1:0]	int_data_reg [12:0], int_data_next [12:0];
+
+	wire	[size*widthr-1:0]	acc_data_wire [3:0], del_data_wire [1:0];
+
+	integer i;
+	genvar j;
+
+	generate
+		for (j = 0; j < size; j = j + 1)
+		begin : INT_DATA
+			assign acc_data_wire[0][j*widthr+widthr-1:j*widthr] = {{(widthr-width){1'b0}}, inp_data[j*width+width-1:j*width]};
+
+			// -2*del_data_1 + del_data_2 + inp_data + result
+
+			assign acc_data_wire[1][j*widthr+widthr-1:j*widthr] =
+				  acc_data_reg[0][j*widthr+widthr-1:j*widthr]
+				+ del_data_wire[1][j*widthr+widthr-1:j*widthr]
+				- {del_data_wire[0][j*widthr+widthr-1],del_data_wire[0][j*widthr+widthr-3:j*widthr], 1'b0};
+
+			assign acc_data_wire[2][j*widthr+widthr-1:j*widthr] =
+				  acc_data_reg[1][j*widthr+widthr-1:j*widthr]
+				+ acc_data_reg[2][j*widthr+widthr-1:j*widthr];
+
+			assign acc_data_wire[3][j*widthr+widthr-1:j*widthr] =
+				  acc_data_reg[2][j*widthr+widthr-1:j*widthr]
+				+ acc_data_reg[3][j*widthr+widthr-1:j*widthr];
+
+		end
+	endgenerate
+
+	cic_pipeline #(
+		.width(size*widthr)) cic_pipeline_unit (
+		.clock(clock),
+		.data(acc_data_reg[0]),
+		.rdaddress_a({int_addr_wire[9:8], int_addr_wire[3:0]}),
+		.rdaddress_b({int_addr_wire[9:8], int_addr_wire[7:4]}),
+		.wraddress(int_addr_reg),
+		.wren(int_wren_reg),
+		.qa(del_data_wire[0]),
+		.qb(del_data_wire[1]));
+
+	lpm_mux #(
+		.lpm_size(4),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(10),
+		.lpm_widths(2)) mux_unit_1 (
+		.sel(int_chan_next),
+		.data({
+			2'd3, int_lfsr_reg[2*5+3:2*5], int_lfsr_reg[5+3:5],
+			2'd2, int_lfsr_reg[2*4+3:2*4], int_lfsr_reg[4+3:4],
+			2'd1, int_lfsr_reg[2*3+3:2*3], int_lfsr_reg[3+3:3],
+			2'd0, int_lfsr_reg[2*3+3:2*3], int_lfsr_reg[3+3:3]}),
+		.result(int_addr_wire));                            
+
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			int_wren_reg <= 1'b1;
+			int_flag_reg <= 1'b0;
+			int_chan_reg <= 2'd0;
+			int_case_reg <= 3'd0;
+			int_addr_reg <= 8'd0;
+			for(i = 0; i <= 3; i = i + 1)
+			begin
+				acc_data_reg[i] <= {(size*widthr){1'b0}};
+			end
+			for(i = 0; i <= 12; i = i + 1)
+			begin
+				int_data_reg[i] <= {(size*widthr){1'b0}};
+			end
+			int_lfsr_reg <= 16'd0;
+		end
+		else
+		begin
+			int_wren_reg <= int_wren_next;
+			int_flag_reg <= int_flag_next;
+			int_chan_reg <= int_chan_next;
+			int_case_reg <= int_case_next;
+			int_addr_reg <= int_addr_next;
+			for(i = 0; i <= 3; i = i + 1)
+			begin
+				acc_data_reg[i] <= acc_data_next[i];
+			end
+			for(i = 0; i <= 12; i = i + 1)
+			begin
+				int_data_reg[i] <= int_data_next[i];
+			end
+			int_lfsr_reg <= int_lfsr_next;
+		end             
+	end
+	
+	always @*
+	begin
+		int_wren_next = int_wren_reg;
+		int_flag_next = int_flag_reg;
+		int_chan_next = int_chan_reg;
+		int_case_next = int_case_reg;
+		int_addr_next = int_addr_reg;
+		for(i = 0; i <= 3; i = i + 1)
+		begin
+			acc_data_next[i] = acc_data_reg[i];
+		end
+		for(i = 0; i <= 12; i = i + 1)
+		begin
+			int_data_next[i] = int_data_reg[i];
+		end
+		int_lfsr_next = int_lfsr_reg;
+
+		case (int_case_reg)		
+			0:
+			begin
+				// write zeros
+				int_wren_next = 1'b1;
+				int_addr_next = 8'd0;
+				for(i = 0; i <= 3; i = i + 1)
+				begin
+					acc_data_next[i] = {(size*widthr){1'b0}};
+				end
+				for(i = 0; i <= 12; i = i + 1)
+				begin
+					int_data_next[i] = {(size*widthr){1'b0}};
+				end
+				int_case_next = 3'd1;
+			end	
+			1:
+			begin
+				// write zeros
+				int_addr_next = int_addr_reg + 8'd1;
+				if (&int_addr_reg)
+				begin
+					int_wren_next = 1'b0;
+					int_flag_next = 1'b0;
+					int_chan_next = 2'd0;
+					int_lfsr_next = 16'h7650;
+					int_case_next = 3'd2;
+				end
+			end	
+			2: // frame
+			begin
+				int_flag_next = 1'b0;
+				if (frame)
+				begin
+					int_wren_next = 1'b1;
+
+					int_addr_next = {4'd0, int_lfsr_reg[3:0]};
+					
+					// set read addr for 2nd pipeline
+					int_chan_next = 2'd1;
+                    
+					// prepare registers for 1st sum					
+					acc_data_next[0] = acc_data_wire[0];
+					acc_data_next[1] = int_data_reg[0];
+					acc_data_next[2] = int_data_reg[1];
+					acc_data_next[3] = int_data_reg[2];
+					
+					int_case_next = 3'd3;
+				end
+				if (int_flag_reg) // register 4th sum
+				begin
+					// register 4th sum
+					int_data_next[9] = acc_data_wire[1];
+					int_data_next[10] = acc_data_wire[2];
+					int_data_next[11] = acc_data_wire[3];
+				end
+			end
+			3:  // 1st sum
+			begin				
+				int_addr_next = {4'd1, int_lfsr_reg[3:0]};
+
+				// set read addr for 3rd pipeline
+				int_chan_next = 2'd2;
+
+				// prepare registers for 2nd sum	
+				acc_data_next[0] = int_data_reg[2];
+				acc_data_next[1] = int_data_reg[3];
+				acc_data_next[2] = int_data_reg[4];
+				acc_data_next[3] = int_data_reg[5];
+
+				// register 1st sum
+				int_data_next[0] = acc_data_wire[1];
+				int_data_next[1] = acc_data_wire[2];
+				int_data_next[2] = acc_data_wire[3];
+
+				int_case_next = 3'd4;
+			end
+			4: // 2nd sum
+			begin
+				int_addr_next = {4'd2, int_lfsr_reg[3:0]};
+
+				// set read addr for 4th pipeline
+				int_chan_next = 2'd3;
+
+				// prepare registers for 3rd sum	
+				acc_data_next[0] = int_data_reg[5];
+				acc_data_next[1] = int_data_reg[6];
+				acc_data_next[2] = int_data_reg[7];
+				acc_data_next[3] = int_data_reg[8];
+
+				// register 2nd sum
+				int_data_next[3] = acc_data_wire[1];
+				int_data_next[4] = acc_data_wire[2];
+				int_data_next[5] = acc_data_wire[3];
+				
+				int_lfsr_next = {int_lfsr_reg[14:0], int_lfsr_reg[2] ~^ int_lfsr_reg[3]};
+
+				int_case_next = 3'd5;
+			end
+			5:  // 3rd sum
+			begin				
+				int_flag_next = 1'b1;
+
+				int_addr_next = {4'd3, int_lfsr_reg[4:1]};
+
+				// set read addr for 1st pipeline
+				int_chan_next = 2'd0;
+
+				// prepare registers for 4th sum	
+				acc_data_next[0] = int_data_reg[8];
+				acc_data_next[1] = int_data_reg[9];
+				acc_data_next[2] = int_data_reg[10];
+				acc_data_next[3] = int_data_reg[11];
+
+				// register 3rd sum
+				int_data_next[6] = acc_data_wire[1];
+				int_data_next[7] = acc_data_wire[2];
+				int_data_next[8] = acc_data_wire[3];
+				
+				// register 4th output
+				int_data_next[12] = int_data_reg[11];
+
+				int_case_next = 3'd2;
+			end
+			default:
+			begin
+				int_case_next = 3'd0;
+			end
+		endcase
+	end
+
+	assign out_data = int_data_reg[5];
+	assign out_data2 = int_data_reg[8];
+	assign out_data3 = int_data_reg[12];
+
+endmodule
Index: /trunk/3DEES/cic_pipeline.v
===================================================================
--- /trunk/3DEES/cic_pipeline.v	(revision 177)
+++ /trunk/3DEES/cic_pipeline.v	(revision 177)
@@ -0,0 +1,104 @@
+module cic_pipeline
+	#(
+		parameter	width	=	192
+	)
+	(
+		input	wire				clock,
+		input	wire	[width-1:0]	data,
+		input	wire	[7:0]		rdaddress_a,
+		input	wire	[7:0]		rdaddress_b,
+		input	wire	[7:0]		wraddress,
+		input	wire				wren,
+		output	wire	[width-1:0]	qa,
+		output	wire	[width-1:0]	qb
+	);
+	
+	altsyncram #(
+		.address_aclr_b("NONE"),
+		.address_reg_b("CLOCK0"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_input_b("BYPASS"),
+		.clock_enable_output_b("BYPASS"),
+		.intended_device_family("Cyclone III"),
+		.lpm_type("altsyncram"),
+		.numwords_a(256),
+		.numwords_b(256),
+		.operation_mode("DUAL_PORT"),
+		.outdata_aclr_b("NONE"),
+		.outdata_reg_b("CLOCK0"),
+		.power_up_uninitialized("FALSE"),
+		.read_during_write_mode_mixed_ports("DONT_CARE"),
+		.widthad_a(8),
+		.widthad_b(8),
+		.width_a(width),
+		.width_b(width),
+		.width_byteena_a(1)) ram_unit_a(
+		.wren_a(wren),
+		.clock0(clock),
+		.address_a(wraddress),
+		.address_b(rdaddress_a),
+		.data_a(data),
+		.q_b(qa),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.data_b({width{1'b1}}),
+		.eccstatus(),
+		.q_a(),
+		.rden_a(1'b1),
+		.rden_b(1'b1),
+		.wren_b(1'b0));
+
+	altsyncram #(
+		.address_aclr_b("NONE"),
+		.address_reg_b("CLOCK0"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_input_b("BYPASS"),
+		.clock_enable_output_b("BYPASS"),
+		.intended_device_family("Cyclone III"),
+		.lpm_type("altsyncram"),
+		.numwords_a(256),
+		.numwords_b(256),
+		.operation_mode("DUAL_PORT"),
+		.outdata_aclr_b("NONE"),
+		.outdata_reg_b("CLOCK0"),
+		.power_up_uninitialized("FALSE"),
+		.read_during_write_mode_mixed_ports("DONT_CARE"),
+		.widthad_a(8),
+		.widthad_b(8),
+		.width_a(width),
+		.width_b(width),
+		.width_byteena_a(1)) ram_unit_b(
+		.wren_a(wren),
+		.clock0(clock),
+		.address_a(wraddress),
+		.address_b(rdaddress_b),
+		.data_a(data),
+		.q_b(qb),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.data_b({width{1'b1}}),
+		.eccstatus(),
+		.q_a(),
+		.rden_a(1'b1),
+		.rden_b(1'b1),
+		.wren_b(1'b0));
+
+endmodule
Index: /trunk/3DEES/clip.v
===================================================================
--- /trunk/3DEES/clip.v	(revision 177)
+++ /trunk/3DEES/clip.v	(revision 177)
@@ -0,0 +1,349 @@
+module clip
+	#(
+		parameter	shift	=	24, // right shift of the result
+		parameter	width	=	27, // bit width of the input data
+		parameter	widthr	=	12 // bit width of the output data
+	)
+	(
+		input	wire					clock, frame, reset,
+		input	wire	[4*6-1:0]		del_data,
+		input	wire	[4*6-1:0]		amp_data,
+		input	wire	[4*16-1:0]		tau_data,
+		input	wire	[4*width-1:0]	inp_data,
+		output	wire	[4*widthr-1:0]	out_data
+	);
+
+	localparam	width1	=	width + 16;
+	localparam	width2	=	width + 6;
+	localparam	width3	=	width1 + 2;
+
+	reg						int_wren_reg, int_wren_next;
+	reg						int_flag_reg, int_flag_next;
+	reg		[1:0]			int_chan_reg, int_chan_next;
+	reg		[2:0]			int_case_reg, int_case_next;
+	reg		[7:0]			int_addr_reg, int_addr_next;
+
+	reg		[5:0]			del_addr_reg, del_addr_next;
+	wire	[5:0]			del_addr_wire;
+	wire	[7:0]			int_addr_wire;
+
+	reg		[widthr-1:0]	out_data_reg [4:0], out_data_next [4:0];
+	wire	[widthr-1:0]	out_data_wire;
+
+	wire	[width3-1:0]	add_data_wire;
+
+	wire	[width1-1:0]	mul_data_wire1;
+	wire	[width2-1:0]	mul_data_wire2;
+
+	reg		[width-1:0]		inp_data_reg [3:0], inp_data_next [3:0];
+	wire	[width-1:0]		inp_data_wire [4:0];
+
+	reg		[5:0]			amp_data_reg, amp_data_next;
+	wire	[5:0]			amp_data_wire [3:0];
+
+	reg		[15:0]			tau_data_reg, tau_data_next;
+	wire	[15:0]			tau_data_wire [3:0];
+
+	integer i;
+	genvar j; 
+
+	generate
+		for (j = 0; j < 4; j = j + 1)
+		begin : INT_DATA 
+			assign inp_data_wire[j] = inp_data[j*width+width-1:j*width];
+			assign amp_data_wire[j] = amp_data[j*6+6-1:j*6];
+			assign tau_data_wire[j] = tau_data[j*16+16-1:j*16];
+		end
+	endgenerate
+																				 
+	lpm_mux #(
+		.lpm_size(4),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(8),
+		.lpm_widths(2)) mux_unit_1 (
+		.sel(int_chan_next),
+		.data({
+			2'd3, del_data[3*6+6-1:3*6],
+			2'd2, del_data[2*6+6-1:2*6],
+			2'd1, del_data[1*6+6-1:1*6],
+			2'd0, del_data[0*6+6-1:0*6]}),
+		.result(int_addr_wire));
+
+	assign del_addr_wire = del_addr_reg - int_addr_wire[5:0];
+
+	lpm_mult #(
+		.lpm_hint("MAXIMIZE_SPEED=9"),
+		.lpm_representation("UNSIGNED"),
+		.lpm_type("LPM_MULT"),
+		.lpm_pipeline(3),
+		.lpm_widtha(width),
+		.lpm_widthb(16),
+		.lpm_widthp(width1)) mult_unit_1 (
+		.clock(clock),
+		.clken(int_wren_reg),
+		.dataa(inp_data_wire[4]),
+		.datab(tau_data_reg),
+		.result(mul_data_wire1));
+
+	lpm_mult #(
+		.lpm_hint("MAXIMIZE_SPEED=9"),
+		.lpm_representation("UNSIGNED"),
+		.lpm_type("LPM_MULT"),
+		.lpm_pipeline(3),
+		.lpm_widtha(width),
+		.lpm_widthb(6),
+		.lpm_widthp(width2)) mult_unit_2 (
+		.clock(clock),
+		.clken(int_wren_reg),
+		.dataa(inp_data_reg[0]),
+		.datab(amp_data_reg),
+		.result(mul_data_wire2));
+
+	assign add_data_wire = 
+		  {2'b0, mul_data_wire2, {(width1-width2){1'b0}}}
+		- {2'b0, mul_data_wire1};
+
+	assign out_data_wire = add_data_wire[width3-1] ? {(widthr){1'b0}} :
+		  add_data_wire[shift+widthr-1:shift]
+		+ {{(widthr-1){add_data_wire[width3-1]}}, add_data_wire[shift-1]};
+
+
+	altsyncram #(
+		.address_aclr_b("NONE"),
+		.address_reg_b("CLOCK0"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_input_b("BYPASS"),
+		.clock_enable_output_b("BYPASS"),
+		.intended_device_family("Cyclone III"),
+		.lpm_type("altsyncram"),
+		.numwords_a(256),
+		.numwords_b(256),
+		.operation_mode("DUAL_PORT"),
+		.outdata_aclr_b("NONE"),
+		.outdata_reg_b("CLOCK0"),
+		.power_up_uninitialized("FALSE"),
+		.read_during_write_mode_mixed_ports("DONT_CARE"),
+		.widthad_a(8),
+		.widthad_b(8),
+		.width_a(width),
+		.width_b(width),
+		.width_byteena_a(1)) ram_unit_1 (
+		.wren_a(int_wren_reg),
+		.clock0(clock),
+		.address_a(int_addr_reg),
+		.address_b({int_addr_wire[7:6], del_addr_wire}),
+		.data_a(inp_data_reg[0]),
+		.q_b(inp_data_wire[4]),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.data_b({(width){1'b1}}),
+		.eccstatus(),
+		.q_a(),
+		.rden_a(1'b1),
+		.rden_b(1'b1),
+		.wren_b(1'b0));
+
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			int_wren_reg <= 1'b1;
+			int_flag_reg <= 1'b0;
+			int_chan_reg <= 2'd0;
+			int_case_reg <= 3'd0;
+			del_addr_reg <= 6'd0;
+			int_addr_reg <= 8'd0;
+			amp_data_reg <= 6'd0;
+			tau_data_reg <= 16'd0;
+			for(i = 0; i <= 3; i = i + 1)
+			begin
+				inp_data_reg[i] <= {(width){1'b0}};
+			end
+			for(i = 0; i <= 4; i = i + 1)
+			begin
+				out_data_reg[i] <= {(widthr){1'b0}};
+			end
+		end
+		else
+		begin
+			int_wren_reg <= int_wren_next;
+			int_flag_reg <= int_flag_next;
+			int_chan_reg <= int_chan_next;
+			int_case_reg <= int_case_next;
+			del_addr_reg <= del_addr_next;
+			int_addr_reg <= int_addr_next;
+			amp_data_reg <= amp_data_next;
+			tau_data_reg <= tau_data_next;
+			for(i = 0; i <= 3; i = i + 1)
+			begin
+				inp_data_reg[i] <= inp_data_next[i];
+			end                  
+			for(i = 0; i <= 4; i = i + 1)
+			begin
+				out_data_reg[i] <= out_data_next[i];
+			end                  
+		end             
+	end
+	
+	always @*
+	begin
+		int_wren_next = int_wren_reg;
+		int_flag_next = int_flag_reg;
+		int_chan_next = int_chan_reg;
+		int_case_next = int_case_reg;
+		del_addr_next = del_addr_reg;
+		int_addr_next = int_addr_reg;
+		amp_data_next = amp_data_reg;
+		tau_data_next = tau_data_reg;
+		for(i = 0; i <= 3; i = i + 1)
+		begin
+			inp_data_next[i] = inp_data_reg[i];
+		end                  
+		for(i = 0; i <= 4; i = i + 1)
+		begin
+			out_data_next[i] = out_data_reg[i];
+		end                  
+
+		case (int_case_reg)		
+			0:
+			begin
+				// write zeros
+				int_wren_next = 1'b1;
+				del_addr_next = 6'd0;
+				int_addr_next = 8'd0;
+				amp_data_next = 6'd0;
+				tau_data_next = 16'd0;
+				for(i = 0; i <= 3; i = i + 1)
+				begin
+					inp_data_next[i] = {(width){1'b0}};
+				end                  
+				for(i = 0; i <= 4; i = i + 1)
+				begin
+					out_data_next[i] = {(widthr){1'b0}};
+				end                  
+
+				int_case_next = 3'd1;
+			end	
+			1:
+			begin
+				// write zeros
+				int_addr_next = int_addr_reg + 8'd1;
+				if (&int_addr_reg)
+				begin
+					int_wren_next = 1'b0;
+					int_flag_next = 1'b0;
+					int_chan_next = 2'd0;
+					int_case_next = 3'd2;
+				end
+			end	
+			2: // frame
+			begin
+				int_flag_next = 1'b0;
+				int_wren_next = frame;
+				if (frame)
+				begin
+					int_addr_next[7:6] = 2'd0;
+					
+					// set read addr for 2nd pipeline
+					int_chan_next = 2'd1;
+
+					// register input data for 2nd, 3rd and 4th sums
+					inp_data_next[1] = inp_data_wire[1];
+					inp_data_next[2] = inp_data_wire[2];
+					inp_data_next[3] = inp_data_wire[3];
+
+					// prepare registers for 1st sum					
+					inp_data_next[0] = inp_data_wire[0];
+
+					tau_data_next = tau_data_wire[0];
+					amp_data_next = amp_data_wire[0];
+					
+					int_case_next = 3'd3;
+				end
+				if (int_flag_reg) // register 4th sum
+				begin
+					int_addr_next[5:0] = del_addr_reg;
+					// register 1st product
+					out_data_next[0] = out_data_wire;
+				end
+			end
+			3:  // 1st sum
+			begin				
+				int_addr_next[7:6] = 2'd1;
+
+				// set read addr for 3rd pipeline
+				int_chan_next = 2'd2;
+
+				// prepare registers for 2nd sum
+				inp_data_next[0] = inp_data_reg[1];
+				
+				tau_data_next = tau_data_wire[1];
+				amp_data_next = amp_data_wire[1];
+
+				// register 2nd product
+				out_data_next[1] = out_data_wire;
+
+				int_case_next = 3'd4;
+			end
+			4: // 2nd sum
+			begin
+				int_addr_next[7:6] = 2'd2;
+
+				// set read addr for 4th pipeline
+				int_chan_next = 2'd3;
+
+				// prepare registers for 3rd sum	
+				inp_data_next[0] = inp_data_reg[2];
+
+				tau_data_next = tau_data_wire[2];
+				amp_data_next = amp_data_wire[2];
+				
+				// register 3rd product
+				out_data_next[2] = out_data_wire;
+				
+				del_addr_next = del_addr_reg + 6'd1;
+
+				int_case_next = 3'd5;
+			end
+			5:  // 3rd sum
+			begin				
+				int_flag_next = 1'b1;
+
+				int_addr_next[7:6] = 2'd3;
+					
+				// set read addr for 1st pipeline
+				int_chan_next = 2'd0;
+
+				// prepare registers for 4th sum	
+				inp_data_next[0] = inp_data_reg[3];
+
+				tau_data_next = tau_data_wire[3];
+				amp_data_next = amp_data_wire[3];
+				
+				// register 4th product
+				out_data_next[3] = out_data_wire;
+                                             
+				// register 4th output
+				out_data_next[4] = out_data_reg[0];
+
+				int_case_next = 3'd2;
+			end
+			default:
+			begin
+				int_case_next = 3'd0;
+			end
+		endcase
+	end
+
+	assign out_data = {out_data_reg[3], out_data_reg[2], out_data_reg[1], out_data_reg[4]};
+
+endmodule
Index: /trunk/3DEES/coincidence.v
===================================================================
--- /trunk/3DEES/coincidence.v	(revision 177)
+++ /trunk/3DEES/coincidence.v	(revision 177)
@@ -0,0 +1,79 @@
+module coincidence
+	#(
+		parameter	input_width		=	4,
+		parameter	window_size		=	10,
+		parameter	output_width	=	3
+	)
+	(
+		input	wire						clock, frame, reset,
+		input	wire	[output_width-1:0]	cfg_data,
+		input	wire	[input_width-1:0]	trg_data,
+		output	wire	[output_width-1:0]	coi_data,
+		output	wire						coi_flag
+	);
+	
+	reg		[window_size-1:0]	coi_pipe_reg [input_width-1:0];
+	reg							coi_flag_reg;
+
+	wire	[output_width-1:0]	coi_data_wire;
+	wire	[input_width-1:0]	int_data_wire;
+	
+	integer i;
+	genvar j;
+
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			coi_flag_reg <= 1'b0;
+			for(i = 0; i <= 3; i = i + 1)
+			begin
+				coi_pipe_reg[i] <= 0;
+			end
+        end
+        else if (frame)
+		begin
+			if (coi_data_wire >= cfg_data)
+			begin
+				coi_flag_reg <= 1'b1;
+				for(i = 0; i < input_width; i = i + 1)
+				begin
+					coi_pipe_reg[i] <= 0;
+				end
+			end
+			else
+			begin
+				coi_flag_reg <= 1'b0;
+				for(i = 0; i < input_width; i = i + 1)
+				begin
+					coi_pipe_reg[i] <= {coi_pipe_reg[i][window_size-2:0], trg_data[i]};
+				end
+			end
+		end
+	end
+
+	generate
+		for (j = 0; j < input_width; j = j + 1)
+		begin : INT_DATA
+			assign int_data_wire[j] = (|coi_pipe_reg[j]);
+		end
+	endgenerate
+
+	parallel_add #(
+		.msw_subtract("NO"),
+		.representation("UNSIGNED"),
+		.result_alignment("LSB"),
+		.pipeline(1),
+		.shift(0),
+		.size(input_width),
+		.width(1),
+		.widthr(output_width)) parallel_add_unit (
+		.clock(clock),
+		.data(int_data_wire),
+		.result(coi_data_wire));
+
+
+	assign coi_data = coi_data_wire;
+	assign coi_flag = coi_flag_reg;
+
+endmodule
Index: /trunk/3DEES/configuration.v
===================================================================
--- /trunk/3DEES/configuration.v	(revision 177)
+++ /trunk/3DEES/configuration.v	(revision 177)
@@ -0,0 +1,82 @@
+module configuration
+	(
+		input	wire			clock, reset,
+
+		input	wire			bus_ssel, bus_wren,
+		input	wire	[5:0]	bus_addr,
+		input	wire	[15:0]	bus_mosi,
+
+		output	wire	[15:0]	bus_miso,
+		output	wire			bus_busy,
+		
+		output  wire	[1023:0]	cfg_bits
+	);
+
+	wire 	[63:0]	int_ssel_wire;
+	wire	[15:0]	int_miso_wire;
+	reg		[15:0]	int_miso_reg;
+
+	wire 	[1023:0]	int_bits_wire;
+
+	integer i;
+	genvar j;
+
+	generate
+		for (j = 0; j < 64; j = j + 1)
+		begin : BUS_OUTPUT
+			lpm_ff #(
+				.lpm_fftype("DFF"),
+				.lpm_type("LPM_FF"),
+				.lpm_width(16)) cfg_reg_unit (
+				.enable(int_ssel_wire[j] & bus_ssel & bus_wren),
+				.sclr(reset),
+				.clock(clock),
+				.data(bus_mosi),
+				.q(int_bits_wire[j*16+15:j*16]),
+				.aclr(),
+				.aload(),
+				.aset(),
+				.sload(),
+				.sset());
+				end
+	endgenerate
+
+	lpm_mux #(
+		.lpm_size(64),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(16),
+		.lpm_widths(6)) bus_miso_mux_unit (
+		.sel(bus_addr),
+		.data(int_bits_wire),
+		.result(int_miso_wire));
+
+
+	lpm_decode #(
+		.lpm_decodes(64),
+		.lpm_type("LPM_DECODE"),
+		.lpm_width(6)) lpm_decode_unit (
+		.data(bus_addr),
+		.eq(int_ssel_wire),
+		.aclr(),
+		.clken(),
+		.clock(),
+		.enable());
+
+	always @(posedge clock)
+	begin
+		if (reset)
+		begin
+			int_miso_reg <= 16'd0;
+		end
+		else
+		begin
+			int_miso_reg <= int_miso_wire;
+		end
+	end
+
+	// output logic
+	assign	bus_miso = int_miso_reg;
+	assign	bus_busy = 1'b0;
+	assign	cfg_bits = int_bits_wire;
+
+endmodule
Index: /trunk/3DEES/control.v
===================================================================
--- /trunk/3DEES/control.v	(revision 177)
+++ /trunk/3DEES/control.v	(revision 177)
@@ -0,0 +1,260 @@
+module control
+	(
+		input	wire			clock, reset,
+
+		input	wire			rx_empty, tx_full,
+		input	wire	[7:0]	rx_data,
+
+		output	wire			rx_rdreq, tx_wrreq,
+		output	wire	[7:0]	tx_data,
+
+		output	wire			bus_wren,
+		output	wire	[31:0]	bus_addr,
+		output	wire	[15:0]	bus_mosi,
+
+		input	wire	[15:0]	bus_miso,
+		input	wire			bus_busy,
+
+		output	wire			led
+	);
+
+	reg		[23:0]	led_counter;
+
+	reg 			int_bus_wren;
+	reg 	[31:0]	int_bus_addr;
+	reg 	[31:0]	int_bus_cntr;
+	reg 	[15:0]	int_bus_mosi;
+
+	reg				int_rdreq, int_wrreq;
+	reg		[7:0]	int_data;
+	reg				int_led;
+
+	reg		[1:0]	byte_counter;
+	reg		[4:0]	idle_counter;
+
+	reg		[4:0]	state;
+
+	reg		[31:0]	address, counter;
+
+	reg		[15:0]	prefix;
+
+	wire	[15:0]	dest, data;
+
+	reg		[7:0]	buffer [3:0];
+
+	assign	dest = {buffer[0], buffer[1]};
+	assign	data = {buffer[2], buffer[3]};
+
+	always @(posedge clock)
+	begin
+		if (~rx_empty)
+		begin
+			int_led <= 1'b0;
+			led_counter <= 24'd0;
+		end
+		else
+		begin
+			if (&led_counter)
+			begin
+				int_led <= 1'b1;
+			end
+			else
+			begin
+				led_counter <= led_counter + 24'd1;
+			end
+		end
+
+		case(state)
+			0:
+			begin
+				int_rdreq <= 1'b1;
+				int_wrreq <= 1'b0;
+				idle_counter <= 5'd0;
+				byte_counter <= 2'd0;
+				state <= 5'd1;
+			end
+
+			1: 
+			begin
+				// read 4 bytes
+				if (~rx_empty)
+				begin
+					idle_counter <= 5'd0;
+					byte_counter <= byte_counter + 2'd1;
+					buffer[byte_counter] <= rx_data;
+					if (&byte_counter)
+					begin
+						int_rdreq <= 1'b0;
+						state <= 5'd2;
+					end
+				end
+				else if(|byte_counter)
+				begin
+					idle_counter <= idle_counter + 5'd1;
+					if (&idle_counter)
+					begin
+						int_rdreq <= 1'b0;
+						state <= 5'd0;
+					end
+				end
+			end
+			
+			2: 
+			begin
+				case (dest)
+					16'h0000:
+					begin
+						// reset
+						prefix <= 16'd0;
+						state <= 5'd0;
+					end
+
+
+					16'h0001:
+					begin
+						// prefix register
+						prefix <= data;
+						state <= 5'd0;
+					end
+
+
+					16'h0002:
+					begin
+						// address register
+						address <= {prefix, data};
+						prefix <= 16'd0;
+						state <= 5'd0;
+					end
+
+					16'h0003:
+					begin
+						// counter register
+						counter <= {prefix, data};
+						prefix <= 16'd0;
+						state <= 5'd0;
+					end
+
+					16'h0004:
+					begin
+						// single write
+						int_bus_addr <= address;
+						int_bus_mosi <= data;
+						int_bus_wren <= 1'b1;
+						prefix <= 16'd0;
+						state <= 5'd3;
+					end
+
+					16'h0005:
+					begin
+						// multi read
+						int_bus_addr <= address;
+						int_bus_cntr <= counter;
+						int_bus_wren <= 1'b0;
+						prefix <= 16'd0;
+						state <= 5'd4;
+					end
+
+					default:
+					begin
+						prefix <= 16'd0;
+						state <= 5'd0;
+					end
+				endcase
+			end
+
+			// single write
+			3:
+			begin
+				if (~bus_busy)
+				begin
+					int_bus_addr <= 32'd0;
+					int_bus_mosi <= 16'd0;
+					int_bus_wren <= 1'b0;
+					state <= 5'd0;
+				end
+			end
+
+			// multi read
+			4:
+			begin
+				if (bus_busy)
+				begin
+					buffer[0] <= 8'd1;
+					buffer[1] <= 8'd0;
+					int_bus_cntr <= 32'd0;
+				end
+				else
+				begin
+					buffer[0] <= 8'd0;
+					buffer[1] <= 8'd0;
+				end
+				state <= 5'd7;
+			end
+
+			5:
+			begin
+				buffer[0] <= bus_miso[7:0];
+				buffer[1] <= bus_miso[15:8];
+				int_bus_addr <= int_bus_addr + 32'd1;
+				int_bus_cntr <= int_bus_cntr - 32'd1;
+				state <= 5'd6;
+			end
+
+			6:
+			begin
+				state <= 5'd7;
+			end
+
+			7:
+			begin
+				int_data <= buffer[0];
+				int_wrreq <= 1'b1;
+				state <= 5'd8;
+			end
+
+			8:
+			begin
+				if (~tx_full)
+				begin
+					int_data <= buffer[1];
+					state <= 5'd9;
+				end
+			end
+
+			9:
+			begin
+				if (~tx_full)
+				begin
+					int_wrreq <= 1'b0;
+					state <= 5'd10;
+				end
+			end
+
+			10:
+			begin
+				if (|int_bus_cntr)
+				begin
+					state <= 5'd5;
+				end
+				else
+				begin
+					state <= 5'd0;
+				end
+			end
+
+			default:
+			begin
+				state <= 5'd0;
+			end
+		endcase
+	end
+
+	assign	bus_wren = int_bus_wren;
+	assign	bus_addr = int_bus_addr;
+	assign	bus_mosi = int_bus_mosi;
+	assign	rx_rdreq = int_rdreq & (~rx_empty);
+	assign	tx_wrreq = int_wrreq & (~tx_full);
+	assign	tx_data = int_data;
+	assign	led = int_led;
+
+endmodule
Index: /trunk/3DEES/counter.v
===================================================================
--- /trunk/3DEES/counter.v	(revision 177)
+++ /trunk/3DEES/counter.v	(revision 177)
@@ -0,0 +1,96 @@
+module counter
+	(
+		input	wire			clock, frame,
+
+		input	wire			reset, setup, count,
+
+		input	wire			bus_ssel, bus_wren,
+		input	wire	[1:0]	bus_addr,
+		input	wire	[15:0]	bus_mosi,
+
+		output	wire	[15:0]	bus_miso,
+		output	wire			bus_busy,
+		
+		output  wire			cnt_good
+	);
+
+	wire 	[3:0]	int_ssel_wire;
+	wire	[15:0]	int_miso_wire;
+
+	reg				cnt_good_reg;
+	reg		[15:0]	int_miso_reg;
+
+	wire 	[63:0]	reg_bits_wire;
+	wire 	[63:0]	cnt_bits_wire;
+	
+	reg				int_load_reg;
+
+	integer i;
+	genvar j;
+
+	lpm_counter	#(
+		.lpm_direction("DOWN"),
+		.lpm_port_updown("PORT_UNUSED"),
+		.lpm_type("LPM_COUNTER"),
+		.lpm_width(64)) lpm_counter_component (
+		.sload(int_load_reg | setup),
+		.sclr(reset),
+		.clock(clock),
+		.data(reg_bits_wire),
+		.cnt_en((frame) & (count) & (|cnt_bits_wire)),
+		.q(cnt_bits_wire));
+
+	generate
+		for (j = 0; j < 4; j = j + 1)
+		begin : BUS_OUTPUT
+			lpm_ff #(
+				.lpm_fftype("DFF"),
+				.lpm_type("LPM_FF"),
+				.lpm_width(16)) cfg_reg_unit (
+				.enable(int_ssel_wire[j] & bus_ssel & bus_wren),
+				.sclr(reset),
+				.clock(clock),
+				.data(bus_mosi),
+				.q(reg_bits_wire[j*16+15:j*16]));
+				end
+	endgenerate
+
+	lpm_mux #(
+		.lpm_size(4),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(16),
+		.lpm_widths(2)) bus_miso_mux_unit (
+		.sel(bus_addr),
+		.data(cnt_bits_wire),
+		.result(int_miso_wire));
+
+
+	lpm_decode #(
+		.lpm_decodes(4),
+		.lpm_type("LPM_DECODE"),
+		.lpm_width(2)) lpm_decode_unit (
+		.data(bus_addr),
+		.eq(int_ssel_wire));
+
+	always @(posedge clock)
+	begin
+		if (reset)
+		begin
+			int_miso_reg <= 16'd0;
+			cnt_good_reg <= 1'b0;
+			int_load_reg <= 1'b0;
+		end
+		else
+		begin
+			int_miso_reg <= int_miso_wire;
+			cnt_good_reg <= |cnt_bits_wire;
+			int_load_reg <= bus_ssel & bus_wren;
+		end
+	end
+
+	// output logic
+	assign	bus_miso = int_miso_reg;
+	assign	bus_busy = 1'b0;
+	assign	cnt_good = cnt_good_reg;
+
+endmodule
Index: /trunk/3DEES/deconv.v
===================================================================
--- /trunk/3DEES/deconv.v	(revision 177)
+++ /trunk/3DEES/deconv.v	(revision 177)
@@ -0,0 +1,372 @@
+module deconv
+	#(
+		parameter	shift	=	24, // right shift of the result
+		parameter	width	=	27, // bit width of the input data
+		parameter	widthr	=	12 // bit width of the output data
+	)
+	(
+		input	wire						clock, frame, reset,
+		input	wire	[4*6-1:0]		del_data,
+		input	wire	[4*6-1:0]		amp_data,
+		input	wire	[4*16-1:0]		tau_data,
+		input	wire	[4*width-1:0]	inp_data,
+		output	wire	[4*widthr-1:0]	out_data
+	);
+
+	localparam	width1	=	width + 1;
+	localparam	width2	=	width + 6 + 1;
+	localparam	width3	=	width + 16 + 3;
+
+	reg						int_wren_reg, int_wren_next;
+	reg						int_flag_reg, int_flag_next;
+	reg		[1:0]			int_chan_reg, int_chan_next;
+	reg		[2:0]			int_case_reg, int_case_next;
+	reg		[7:0]			int_addr_reg, int_addr_next;
+
+	reg		[5:0]			del_addr_reg, del_addr_next;
+	wire	[5:0]			del_addr_wire;
+	wire	[7:0]			int_addr_wire;
+
+	reg		[widthr-1:0]	out_data_reg [4:0], out_data_next [4:0];
+	wire	[widthr-1:0]	out_data_wire;
+
+	wire	[width3-1:0]	add_data_wire;
+
+	wire	[width3-1:0]	mul_data_wire [1:0];
+
+	reg		[width2-1:0]	acc_data_reg [4:0], acc_data_next [4:0];
+	wire	[width2-1:0]	acc_data_wire;
+
+	wire	[width1-1:0]	sub_data_wire;
+
+	reg		[width-1:0]		inp_data_reg [3:0], inp_data_next [3:0];
+	wire	[width-1:0]		inp_data_wire [4:0];
+
+	reg		[5:0]			amp_data_reg, amp_data_next;
+	wire	[5:0]			amp_data_wire [3:0];
+
+	reg		[15:0]			tau_data_reg, tau_data_next;
+	wire	[15:0]			tau_data_wire [3:0];
+
+	integer i;
+	genvar j;
+
+	generate
+		for (j = 0; j < 4; j = j + 1)
+		begin : INT_DATA 
+			assign inp_data_wire[j] = inp_data[j*width+width-1:j*width];
+			assign amp_data_wire[j] = amp_data[j*6+6-1:j*6];
+			assign tau_data_wire[j] = tau_data[j*16+16-1:j*16];
+		end
+	endgenerate
+															   
+	lpm_mux #(
+		.lpm_size(4),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(8),
+		.lpm_widths(2)) mux_unit_1 (
+		.sel(int_chan_next),
+		.data({
+			2'd3, del_data[3*6+6-1:3*6],
+			2'd2, del_data[2*6+6-1:2*6],
+			2'd1, del_data[1*6+6-1:1*6],
+			2'd0, del_data[0*6+6-1:0*6]}),
+		.result(int_addr_wire));
+
+	assign del_addr_wire = del_addr_reg - int_addr_wire[5:0];
+
+	assign sub_data_wire =
+		  {{(width1-width){1'b0}}, inp_data_reg[0]}
+		- {{(width1-width){1'b0}}, inp_data_wire[4]};
+
+	assign acc_data_wire =
+		  {{(width2-width1+1){sub_data_wire[width1-1]}}, sub_data_wire[width1-2:0]}
+		+ acc_data_reg[0];
+	
+	lpm_mult #(
+		.lpm_hint("MAXIMIZE_SPEED=9"),
+		.lpm_representation("SIGNED"),
+		.lpm_type("LPM_MULT"),
+		.lpm_pipeline(3),
+		.lpm_widtha(width1),
+		.lpm_widthb(17),
+		.lpm_widthp(width3)) mult_unit_1 (
+		.clock(clock),
+		.clken(int_wren_reg),
+		.dataa(sub_data_wire),
+		.datab({1'b0, tau_data_reg}),
+		.result(mul_data_wire[0]));
+
+	lpm_mult #(
+		.lpm_hint("MAXIMIZE_SPEED=9"),
+		.lpm_representation("UNSIGNED"),
+		.lpm_type("LPM_MULT"),
+		.lpm_pipeline(3),
+		.lpm_widtha(width2),
+		.lpm_widthb(6),
+		.lpm_widthp(width3)) mult_unit_2 (
+		.clock(clock),
+		.clken(int_wren_reg),
+		.dataa(acc_data_reg[0]),
+		.datab(amp_data_reg),
+		.result(mul_data_wire[1]));
+
+	assign add_data_wire = 
+		  mul_data_wire[0]
+		+ mul_data_wire[1];
+
+	assign out_data_wire = 
+		  add_data_wire[shift+widthr-1:shift]
+		+ {{(widthr-1){add_data_wire[width3-1]}}, add_data_wire[shift-1]};
+
+	altsyncram #(
+		.address_aclr_b("NONE"),
+		.address_reg_b("CLOCK0"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_input_b("BYPASS"),
+		.clock_enable_output_b("BYPASS"),
+		.intended_device_family("Cyclone III"),
+		.lpm_type("altsyncram"),
+		.numwords_a(256),
+		.numwords_b(256),
+		.operation_mode("DUAL_PORT"),
+		.outdata_aclr_b("NONE"),
+		.outdata_reg_b("CLOCK0"),
+		.power_up_uninitialized("FALSE"),
+		.read_during_write_mode_mixed_ports("DONT_CARE"),
+		.widthad_a(8),
+		.widthad_b(8),
+		.width_a(width),
+		.width_b(width),
+		.width_byteena_a(1)) ram_unit_1 (
+		.wren_a(int_wren_reg),
+		.clock0(clock),
+		.address_a(int_addr_reg),
+		.address_b({int_addr_wire[7:6], del_addr_wire}),
+		.data_a(inp_data_reg[0]),
+		.q_b(inp_data_wire[4]),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.data_b({(width){1'b1}}),
+		.eccstatus(),
+		.q_a(),
+		.rden_a(1'b1),
+		.rden_b(1'b1),
+		.wren_b(1'b0));
+
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			int_wren_reg <= 1'b1;
+			int_flag_reg <= 1'b0;
+			int_chan_reg <= 2'd0;
+			int_case_reg <= 3'd0;
+			del_addr_reg <= 6'd0;
+			int_addr_reg <= 8'd0;
+			amp_data_reg <= 6'd0;
+			tau_data_reg <= 16'd0;
+			for(i = 0; i <= 3; i = i + 1)
+			begin
+				inp_data_reg[i] <= {(width){1'b0}};
+			end
+			for(i = 0; i <= 4; i = i + 1)
+			begin
+				acc_data_reg[i] <= {(width2){1'b0}};
+				out_data_reg[i] <= {(widthr){1'b0}};
+			end
+		end
+		else
+		begin
+			int_wren_reg <= int_wren_next;
+			int_flag_reg <= int_flag_next;
+			int_chan_reg <= int_chan_next;
+			int_case_reg <= int_case_next;
+			del_addr_reg <= del_addr_next;
+			int_addr_reg <= int_addr_next;
+			amp_data_reg <= amp_data_next;
+			tau_data_reg <= tau_data_next;
+			for(i = 0; i <= 3; i = i + 1)
+			begin
+				inp_data_reg[i] <= inp_data_next[i];
+			end                  
+			for(i = 0; i <= 4; i = i + 1)
+			begin
+				acc_data_reg[i] <= acc_data_next[i];
+				out_data_reg[i] <= out_data_next[i];
+			end                  
+		end             
+	end
+	
+	always @*
+	begin
+		int_wren_next = int_wren_reg;
+		int_flag_next = int_flag_reg;
+		int_chan_next = int_chan_reg;
+		int_case_next = int_case_reg;
+		del_addr_next = del_addr_reg;
+		int_addr_next = int_addr_reg;
+		amp_data_next = amp_data_reg;
+		tau_data_next = tau_data_reg;
+		for(i = 0; i <= 3; i = i + 1)
+		begin
+			inp_data_next[i] = inp_data_reg[i];
+		end                  
+		for(i = 0; i <= 4; i = i + 1)
+		begin
+			acc_data_next[i] = acc_data_reg[i];
+			out_data_next[i] = out_data_reg[i];
+		end                  
+
+		case (int_case_reg)		
+			0:
+			begin
+				// write zeros
+				int_wren_next = 1'b1;
+				del_addr_next = 6'd0;
+				int_addr_next = 8'd0;
+				amp_data_next = 6'd0;
+				tau_data_next = 16'd0;
+				for(i = 0; i <= 3; i = i + 1)
+				begin
+					inp_data_next[i] = {(width){1'b0}};
+				end                  
+				for(i = 0; i <= 4; i = i + 1)
+				begin
+					acc_data_next[i] = {(width2){1'b0}};
+					out_data_next[i] = {(widthr){1'b0}};
+				end                  
+
+				int_case_next = 3'd1;
+			end	
+			1:
+			begin
+				// write zeros
+				int_addr_next = int_addr_reg + 8'd1;
+				if (&int_addr_reg)
+				begin
+					int_wren_next = 1'b0;
+					int_flag_next = 1'b0;
+					int_chan_next = 2'd0;
+					int_case_next = 3'd2;
+				end
+			end	
+			2: // frame
+			begin
+				int_flag_next = 1'b0;
+				int_wren_next = frame;
+				if (frame)
+				begin
+					int_addr_next[7:6] = 2'd0;
+					
+					// set read addr for 2nd pipeline
+					int_chan_next = 2'd1;
+
+					// register input data for 2nd, 3rd and 4th sums
+					inp_data_next[1] = inp_data_wire[1];
+					inp_data_next[2] = inp_data_wire[2];
+					inp_data_next[3] = inp_data_wire[3];
+
+					// prepare registers for 1st sum					
+					inp_data_next[0] = inp_data_wire[0];
+					acc_data_next[0] = acc_data_reg[1];
+
+					tau_data_next = tau_data_wire[0];
+					amp_data_next = amp_data_wire[0];
+					
+					int_case_next = 3'd3;
+				end
+				if (int_flag_reg) // register 4th sum
+				begin
+					int_addr_next[5:0] = del_addr_reg;
+					// register 4th sum and 1st product
+					acc_data_next[4] = acc_data_wire;
+					out_data_next[0] = out_data_wire;
+				end
+			end
+			3:  // 1st sum
+			begin				
+				int_addr_next[7:6] = 2'd1;
+
+				// set read addr for 3rd pipeline
+				int_chan_next = 2'd2;
+
+				// prepare registers for 2nd sum
+				inp_data_next[0] = inp_data_reg[1];
+				acc_data_next[0] = acc_data_reg[2];
+				
+				tau_data_next = tau_data_wire[1];
+				amp_data_next = amp_data_wire[1];
+
+				// register 1st sum and 2nd product
+				acc_data_next[1] = acc_data_wire;
+				out_data_next[1] = out_data_wire;
+
+				int_case_next = 3'd4;
+			end
+			4: // 2nd sum
+			begin
+				int_addr_next[7:6] = 2'd2;
+
+				// set read addr for 4th pipeline
+				int_chan_next = 2'd3;
+
+				// prepare registers for 3rd sum	
+				inp_data_next[0] = inp_data_reg[2];
+				acc_data_next[0] = acc_data_reg[3];
+
+				tau_data_next = tau_data_wire[2];
+				amp_data_next = amp_data_wire[2];
+				
+				// register 2nd sum and 3rd product
+				acc_data_next[2] = acc_data_wire;
+				out_data_next[2] = out_data_wire;
+				
+				del_addr_next = del_addr_reg + 6'd1;
+
+				int_case_next = 3'd5;
+			end
+			5:  // 3rd sum
+			begin				
+				int_flag_next = 1'b1;
+
+				int_addr_next[7:6] = 2'd3;
+					
+				// set read addr for 1st pipeline
+				int_chan_next = 2'd0;
+
+				// prepare registers for 4th sum	
+				inp_data_next[0] = inp_data_reg[3];
+				acc_data_next[0] = acc_data_reg[4];
+
+				tau_data_next = tau_data_wire[3];
+				amp_data_next = amp_data_wire[3];
+				
+				// register 3rd sum and 4th product
+				acc_data_next[3] = acc_data_wire;
+				out_data_next[3] = out_data_wire;
+                                             
+				// register 4th output
+				out_data_next[4] = out_data_reg[0];
+
+				int_case_next = 3'd2;
+			end
+			default:
+			begin
+				int_case_next = 3'd0;
+			end
+		endcase
+	end
+
+	assign out_data = {out_data_reg[3], out_data_reg[2], out_data_reg[1], out_data_reg[4]};
+
+endmodule
Index: /trunk/3DEES/delay.v
===================================================================
--- /trunk/3DEES/delay.v	(revision 177)
+++ /trunk/3DEES/delay.v	(revision 177)
@@ -0,0 +1,37 @@
+module delay
+	#(
+		parameter	width	=	12,
+		parameter	length	=	32
+	)
+	(
+		input	wire				clock, frame, reset,
+		input	wire	[width-1:0]	inp_data,
+		output	wire	[width-1:0]	out_data
+	);
+	
+	reg		[width-1:0]	int_pipe_reg [length-1:0];
+	
+	integer i;
+
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			for(i = 0; i < length; i = i + 1)
+			begin
+				int_pipe_reg[i] <= 0;
+			end
+        end
+        else if (frame)
+		begin
+			for(i = 0; i <= 30; i = i + 1)
+			begin
+				int_pipe_reg[i+1] <= int_pipe_reg[i];
+			end
+			int_pipe_reg[0] <= inp_data;
+		end
+	end
+
+	assign out_data = int_pipe_reg[length-1];
+
+endmodule
Index: /trunk/3DEES/filter.v
===================================================================
--- /trunk/3DEES/filter.v	(revision 177)
+++ /trunk/3DEES/filter.v	(revision 177)
@@ -0,0 +1,242 @@
+module filter
+	#(
+		parameter	size	=	3, // number of channels
+		parameter	width	=	12 // bit width of the input data (unsigned)
+	)
+	(
+		input	wire						clock, frame, reset,
+		input	wire	[size*width-1:0]	inp_data,
+		output	wire	[size*widthr-1:0]	out_data
+	);
+	
+	localparam	widthr	=	width + 8;
+	/*
+	5-bit LFSR with additional bits to keep track of previous values
+	*/
+	reg		[31:0]				int_lfsr_reg, int_lfsr_next;
+
+	reg							int_wren_reg, int_wren_next;
+	reg							int_flag_reg, int_flag_next;
+	reg							int_chan_reg, int_chan_next;
+	reg		[1:0]				int_case_reg, int_case_next;
+	reg		[5:0]				int_addr_reg, int_addr_next;
+
+	wire	[5:0]				int_addr_wire;
+
+	reg		[size*widthr-1:0]	acc_data_reg [1:0], acc_data_next [1:0];
+	reg		[size*widthr-1:0]	int_data_reg [2:0], int_data_next [2:0];
+
+	wire	[size*widthr-1:0]	acc_data_wire [1:0], del_data_wire;
+
+	integer i;
+	genvar j;
+
+	generate
+		for (j = 0; j < size; j = j + 1)
+		begin : INT_DATA
+			assign acc_data_wire[0][j*widthr+widthr-1:j*widthr] = {{(widthr-width){1'b0}}, inp_data[j*width+width-1:j*width]};
+
+			assign acc_data_wire[1][j*widthr+widthr-1:j*widthr] =
+				  acc_data_reg[0][j*widthr+widthr-1:j*widthr]
+				- del_data_wire[j*widthr+widthr-1:j*widthr]
+				+ acc_data_reg[1][j*widthr+widthr-1:j*widthr];
+
+		end
+	endgenerate
+
+	altsyncram #(
+		.address_aclr_b("NONE"),
+		.address_reg_b("CLOCK0"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_input_b("BYPASS"),
+		.clock_enable_output_b("BYPASS"),
+		.intended_device_family("Cyclone III"),
+		.lpm_type("altsyncram"),
+		.numwords_a(64),
+		.numwords_b(64),
+		.operation_mode("DUAL_PORT"),
+		.outdata_aclr_b("NONE"),
+		.outdata_reg_b("CLOCK0"),
+		.power_up_uninitialized("FALSE"),
+		.read_during_write_mode_mixed_ports("DONT_CARE"),
+		.widthad_a(6),
+		.widthad_b(6),
+		.width_a(size*widthr),
+		.width_b(size*widthr),
+		.width_byteena_a(1)) ram_unit_1 (
+		.wren_a(int_wren_reg),
+		.clock0(clock),
+		.address_a(int_addr_reg),
+		.address_b(int_addr_wire),
+		.data_a(acc_data_reg[0]),
+		.q_b(del_data_wire),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.data_b({(size*widthr){1'b1}}),
+		.eccstatus(),
+		.q_a(),
+		.rden_a(1'b1),
+		.rden_b(1'b1),
+		.wren_b(1'b0));
+
+	lpm_mux #(
+		.lpm_size(2),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(6),
+		.lpm_widths(1)) mux_unit_1 (
+		.sel(int_chan_next),
+		.data({
+			1'b1, int_lfsr_reg[20+4:20],
+			1'b0, int_lfsr_reg[5+4:5]}),
+		.result(int_addr_wire));                            
+
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			int_wren_reg <= 1'b1;
+			int_flag_reg <= 1'b0;
+			int_chan_reg <= 1'b0;
+			int_case_reg <= 2'd0;
+			int_addr_reg <= 6'd0;
+			for(i = 0; i <= 1; i = i + 1)
+			begin
+				acc_data_reg[i] <= {(size*widthr){1'b0}};
+			end
+			for(i = 0; i <= 2; i = i + 1)
+			begin
+				int_data_reg[i] <= {(size*widthr){1'b0}};
+			end
+			int_lfsr_reg <= 32'd0;
+		end
+		else
+		begin
+			int_wren_reg <= int_wren_next;
+			int_flag_reg <= int_flag_next;
+			int_chan_reg <= int_chan_next;
+			int_case_reg <= int_case_next;
+			int_addr_reg <= int_addr_next;
+			for(i = 0; i <= 1; i = i + 1)
+			begin
+				acc_data_reg[i] <= acc_data_next[i];
+			end
+			for(i = 0; i <= 2; i = i + 1)
+			begin
+				int_data_reg[i] <= int_data_next[i];
+			end
+			int_lfsr_reg <= int_lfsr_next;
+		end             
+	end
+	
+	always @*
+	begin
+		int_wren_next = int_wren_reg;
+		int_flag_next = int_flag_reg;
+		int_chan_next = int_chan_reg;
+		int_case_next = int_case_reg;
+		int_addr_next = int_addr_reg;
+		for(i = 0; i <= 1; i = i + 1)
+		begin
+			acc_data_next[i] = acc_data_reg[i];
+		end
+		for(i = 0; i <= 2; i = i + 1)
+		begin
+			int_data_next[i] = int_data_reg[i];
+		end
+		int_lfsr_next = int_lfsr_reg;
+
+		case (int_case_reg)		
+			0:
+			begin
+				// write zeros
+				int_wren_next = 1'b1;
+				int_addr_next = 6'd0;
+				for(i = 0; i <= 1; i = i + 1)
+				begin
+					acc_data_next[i] = {(size*widthr){1'b0}};
+				end
+				for(i = 0; i <= 2; i = i + 1)
+				begin
+					int_data_next[i] = {(size*widthr){1'b0}};
+				end
+				int_case_next = 2'd1;
+			end	
+			1:
+			begin
+				// write zeros
+				int_addr_next = int_addr_reg + 6'd1;
+				if (&int_addr_reg)
+				begin
+					int_wren_next = 1'b0;
+					int_flag_next = 1'b0;
+					int_chan_next = 1'b0;
+					int_lfsr_next = 32'h0722BDA6;
+					int_case_next = 'd2;
+				end
+			end	
+			2: // frame
+			begin
+				int_flag_next = 1'b0;
+				if (frame)
+				begin
+					int_wren_next = 1'b1;
+
+					int_addr_next = {1'b0, int_lfsr_reg[4:0]};
+					
+					// set read addr for 2nd pipeline
+					int_chan_next = 1'b1;
+                    
+					// prepare registers for 1st sum					
+					acc_data_next[0] = acc_data_wire[0];
+					acc_data_next[1] = int_data_reg[0];
+					
+					int_lfsr_next = {int_lfsr_reg[30:0], int_lfsr_reg[2] ~^ int_lfsr_reg[4]};
+
+					int_case_next = 'd3;
+				end
+				if (int_flag_reg) // register 2nd sum
+				begin
+					// register 2nd sum
+					int_data_next[1] = acc_data_wire[1];
+				end
+			end
+			3:  // 2nd sum
+			begin				
+				int_flag_next = 1'b1;
+
+				int_addr_next = {1'b1, int_lfsr_reg[5:1]};
+
+				// set read addr for 1st pipeline
+				int_chan_next = 1'b0;
+
+				// prepare registers for 2nd sum	
+				acc_data_next[0] = int_data_reg[0];
+				acc_data_next[1] = int_data_reg[1];
+
+				// register 1st sum
+				int_data_next[0] = acc_data_wire[1];
+				
+				// register 2nd output
+				int_data_next[2] = int_data_reg[1];
+
+				int_case_next = 2'd2;
+			end
+			default:
+			begin
+				int_case_next = 2'd0;
+			end
+		endcase
+	end
+
+	assign out_data = int_data_reg[2];
+
+endmodule
Index: /trunk/3DEES/histogram16.v
===================================================================
--- /trunk/3DEES/histogram16.v	(revision 177)
+++ /trunk/3DEES/histogram16.v	(revision 177)
@@ -0,0 +1,199 @@
+module histogram16
+	(
+		input	wire			clock, frame, reset,
+		
+		input	wire			hst_good,
+		input	wire	[13:0]  hst_data,
+
+		input	wire			bus_ssel, bus_wren,
+		input	wire	[13:0]	bus_addr,
+		input	wire	[15:0]	bus_mosi,
+
+		output	wire	[15:0]	bus_miso,
+		output	wire			bus_busy
+	);
+	
+	// signal declaration
+	reg		[3:0]	int_case_reg, int_case_next;
+	reg				int_wren_reg, int_wren_next;
+	reg		[13:0]	int_addr_reg, int_addr_next;
+	reg		[15:0]	int_data_reg, int_data_next;
+
+	reg		[13:0]	bus_addr_reg, bus_addr_next;
+	reg		[15:0]	bus_miso_reg, bus_miso_next;
+
+	reg				bus_wren_reg, bus_wren_next;
+	reg		[15:0]	bus_mosi_reg, bus_mosi_next;
+
+	wire	[15:0]	q_a_wire;
+	wire	[15:0]	q_b_wire;
+
+	altsyncram #(
+		.address_reg_b("CLOCK0"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_input_b("BYPASS"),
+		.clock_enable_output_a("BYPASS"),
+		.clock_enable_output_b("BYPASS"),
+		.indata_reg_b("CLOCK0"),
+		.intended_device_family("Cyclone III"),
+		.lpm_type("altsyncram"),
+		.numwords_a(16384),
+		.numwords_b(16384),
+		.operation_mode("BIDIR_DUAL_PORT"),
+		.outdata_aclr_a("NONE"),
+		.outdata_aclr_b("NONE"),
+		.outdata_reg_a("CLOCK0"),
+		.outdata_reg_b("CLOCK0"),
+		.power_up_uninitialized("FALSE"),
+		.read_during_write_mode_mixed_ports("OLD_DATA"),
+		.read_during_write_mode_port_a("NEW_DATA_NO_NBE_READ"),
+		.read_during_write_mode_port_b("NEW_DATA_NO_NBE_READ"),
+		.widthad_a(14),
+		.widthad_b(14),
+		.width_a(16),
+		.width_b(16),
+		.width_byteena_a(1),
+		.width_byteena_b(1),
+		.wrcontrol_wraddress_reg_b("CLOCK0")) hst_ram_unit(
+		.wren_a(int_wren_reg),
+		.clock0(clock),
+		.wren_b(bus_wren_reg),
+		.address_a(int_addr_reg),
+		.address_b(bus_addr_reg),
+		.data_a(int_data_reg),
+		.data_b(bus_mosi_reg),
+		.q_a(q_a_wire),
+		.q_b(q_b_wire),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.eccstatus(),
+		.rden_a(1'b1),
+		.rden_b(1'b1));
+
+	// body
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			int_wren_reg <= 1'b1;
+			int_addr_reg <= 14'd0;
+			int_data_reg <= 16'd0;
+			int_case_reg <= 4'b0;
+			bus_addr_reg <= 14'd0;
+			bus_miso_reg <= 16'd0;
+			bus_wren_reg <= 1'b0;
+			bus_mosi_reg <= 16'd0;
+		end
+		else
+		begin
+			int_wren_reg <= int_wren_next;
+			int_addr_reg <= int_addr_next;
+			int_data_reg <= int_data_next;
+			int_case_reg <= int_case_next;
+			bus_addr_reg <= bus_addr_next;
+			bus_miso_reg <= bus_miso_next;
+			bus_wren_reg <= bus_wren_next;
+			bus_mosi_reg <= bus_mosi_next;
+		end             
+	end
+
+	always @*
+	begin
+		bus_addr_next = bus_addr_reg;
+		bus_miso_next = bus_miso_reg;
+
+		bus_wren_next = 1'b0;
+		bus_mosi_next = bus_mosi_reg;
+
+		if (bus_ssel)
+		begin
+			bus_miso_next = q_b_wire;	
+			bus_addr_next = bus_addr;
+			bus_wren_next = bus_wren;	
+			if (bus_wren)
+			begin
+				bus_mosi_next = bus_mosi;
+			end
+		end
+	end
+
+	always @*
+	begin
+		int_wren_next = int_wren_reg;
+		int_addr_next = int_addr_reg;
+		int_data_next = int_data_reg;
+		int_case_next = int_case_reg;
+
+		case (int_case_reg)
+						
+			0:
+			begin
+				// write zeros
+				int_addr_next = int_addr_reg + 14'd1;
+				if (&int_addr_reg)
+				begin
+					int_wren_next = 1'b0;
+					int_case_next = 4'd1;
+				end
+			end	
+
+			1:
+			begin
+				int_wren_next = 1'b0;
+/*
+				if (&int_data_reg)
+				begin
+					int_case_next = 4'd0;
+				end
+				else if (frame & hst_good)
+*/
+				if (frame & hst_good)
+				begin
+					int_addr_next = hst_data;
+					int_case_next = 4'd2;
+				end
+			end
+
+			2:
+			begin
+				int_case_next = 4'd3;
+			end
+
+			3:
+			begin
+				int_case_next = 4'd4;
+			end
+
+			4:
+			begin
+				int_case_next = 4'd1;
+				if (~&q_a_wire)
+				begin
+					int_wren_next = 1'b1;
+					int_data_next = q_a_wire + 16'd1;
+				end
+			end
+
+			default:
+			begin
+				int_wren_next = 1'b0;
+				int_addr_next = 14'd0;
+				int_data_next = 16'd0;
+				int_case_next = 4'd0;
+			end
+		endcase
+	end
+
+	// output logic
+	assign	bus_miso = bus_miso_reg;
+	assign	bus_busy = 1'b0;
+endmodule
Index: /trunk/3DEES/histogram32.v
===================================================================
--- /trunk/3DEES/histogram32.v	(revision 177)
+++ /trunk/3DEES/histogram32.v	(revision 177)
@@ -0,0 +1,199 @@
+module histogram32
+	(
+		input	wire			clock, frame, reset,
+		
+		input	wire			hst_good,
+		input	wire	[11:0]  hst_data,
+
+		input	wire			bus_ssel, bus_wren,
+		input	wire	[12:0]	bus_addr,
+		input	wire	[15:0]	bus_mosi,
+
+		output	wire	[15:0]	bus_miso,
+		output	wire			bus_busy
+	);
+	
+	// signal declaration
+	reg		[3:0]	int_case_reg, int_case_next;
+	reg				int_wren_reg, int_wren_next;
+	reg		[11:0]	int_addr_reg, int_addr_next;
+	reg		[31:0]	int_data_reg, int_data_next;
+
+	reg		[12:0]	bus_addr_reg, bus_addr_next;
+	reg		[15:0]	bus_miso_reg, bus_miso_next;
+
+	reg				bus_wren_reg, bus_wren_next;
+	reg		[15:0]	bus_mosi_reg, bus_mosi_next;
+
+	wire	[31:0]	q_a_wire;
+	wire	[15:0]	q_b_wire;
+
+	altsyncram #(
+		.address_reg_b("CLOCK0"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_input_b("BYPASS"),
+		.clock_enable_output_a("BYPASS"),
+		.clock_enable_output_b("BYPASS"),
+		.indata_reg_b("CLOCK0"),
+		.intended_device_family("Cyclone III"),
+		.lpm_type("altsyncram"),
+		.numwords_a(4096),
+		.numwords_b(8192),
+		.operation_mode("BIDIR_DUAL_PORT"),
+		.outdata_aclr_a("NONE"),
+		.outdata_aclr_b("NONE"),
+		.outdata_reg_a("CLOCK0"),
+		.outdata_reg_b("CLOCK0"),
+		.power_up_uninitialized("FALSE"),
+		.read_during_write_mode_mixed_ports("OLD_DATA"),
+		.read_during_write_mode_port_a("NEW_DATA_NO_NBE_READ"),
+		.read_during_write_mode_port_b("NEW_DATA_NO_NBE_READ"),
+		.widthad_a(12),
+		.widthad_b(13),
+		.width_a(32),
+		.width_b(16),
+		.width_byteena_a(1),
+		.width_byteena_b(1),
+		.wrcontrol_wraddress_reg_b("CLOCK0")) hst_ram_unit(
+		.wren_a(int_wren_reg),
+		.clock0(clock),
+		.wren_b(bus_wren_reg),
+		.address_a(int_addr_reg),
+		.address_b(bus_addr_reg),
+		.data_a(int_data_reg),
+		.data_b(bus_mosi_reg),
+		.q_a(q_a_wire),
+		.q_b(q_b_wire),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.eccstatus(),
+		.rden_a(1'b1),
+		.rden_b(1'b1));
+
+	// body
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			int_wren_reg <= 1'b1;
+			int_addr_reg <= 12'd0;
+			int_data_reg <= 32'd0;
+			int_case_reg <= 4'b0;
+			bus_addr_reg <= 13'd0;
+			bus_miso_reg <= 16'd0;
+			bus_wren_reg <= 1'b0;
+			bus_mosi_reg <= 16'd0;
+		end
+		else
+		begin
+			int_wren_reg <= int_wren_next;
+			int_addr_reg <= int_addr_next;
+			int_data_reg <= int_data_next;
+			int_case_reg <= int_case_next;
+			bus_addr_reg <= bus_addr_next;
+			bus_miso_reg <= bus_miso_next;
+			bus_wren_reg <= bus_wren_next;
+			bus_mosi_reg <= bus_mosi_next;
+		end             
+	end
+
+	always @*
+	begin
+		bus_addr_next = bus_addr_reg;
+		bus_miso_next = bus_miso_reg;
+
+		bus_wren_next = 1'b0;
+		bus_mosi_next = bus_mosi_reg;
+
+		if (bus_ssel)
+		begin
+			bus_miso_next = q_b_wire;	
+			bus_addr_next = bus_addr;
+			bus_wren_next = bus_wren;	
+			if (bus_wren)
+			begin
+				bus_mosi_next = bus_mosi;
+			end
+		end
+	end
+
+	always @*
+	begin
+		int_wren_next = int_wren_reg;
+		int_addr_next = int_addr_reg;
+		int_data_next = int_data_reg;
+		int_case_next = int_case_reg;
+
+		case (int_case_reg)
+						
+			0:
+			begin
+				// write zeros
+				int_addr_next = int_addr_reg + 12'd1;
+				if (&int_addr_reg)
+				begin
+					int_wren_next = 1'b0;
+					int_case_next = 4'd1;
+				end
+			end	
+
+			1:
+			begin
+				int_wren_next = 1'b0;
+/*
+				if (&int_data_reg)
+				begin
+					int_case_next = 4'd0;
+				end
+				else if (frame & hst_good)
+*/
+				if (frame & hst_good)
+				begin
+					int_addr_next = hst_data;
+					int_case_next = 4'd2;
+				end
+			end
+
+			2:
+			begin
+				int_case_next = 4'd3;
+			end
+
+			3:
+			begin
+				int_case_next = 4'd4;
+			end
+
+			4:
+			begin
+				int_case_next = 4'd1;
+				if (~&q_a_wire)
+				begin
+					int_wren_next = 1'b1;
+					int_data_next = q_a_wire + 32'd1;
+				end
+			end
+
+			default:
+			begin
+				int_wren_next = 1'b0;
+				int_addr_next = 12'd0;
+				int_data_next = 32'd0;
+				int_case_next = 4'd0;
+			end
+		endcase
+	end
+
+	// output logic
+	assign	bus_miso = bus_miso_reg;
+	assign	bus_busy = 1'b0;
+endmodule
Index: /trunk/3DEES/i2c_fifo.v
===================================================================
--- /trunk/3DEES/i2c_fifo.v	(revision 177)
+++ /trunk/3DEES/i2c_fifo.v	(revision 177)
@@ -0,0 +1,219 @@
+module i2c_fifo
+	(		
+		input	wire			clock, reset,
+
+		input	wire			bus_ssel, bus_wren,
+		input	wire	[15:0]	bus_mosi,
+
+		output	wire			bus_busy,
+
+		inout	wire			i2c_sda,
+		inout	wire			i2c_scl
+	);
+
+	wire			int_rdempty, int_wrfull, i2c_clk, start, stop;
+	wire	[15:0]	int_q;
+
+	reg				int_bus_busy;
+	reg				int_rdreq, int_wrreq, int_clken, int_sdo, int_scl, int_ack;
+	reg		[15:0]	int_bus_mosi;
+	reg		[15:0]	int_data;
+	reg		[9:0]	counter;
+	reg		[4:0]	state;
+
+	assign i2c_sda = int_sdo ? 1'bz : 1'b0;
+	assign i2c_scl = int_scl | (int_clken ? counter[9] : 1'b0);	
+
+	assign start = int_data[8];
+	assign stop = int_data[9];
+
+	scfifo #(
+		.add_ram_output_register("OFF"),
+		.intended_device_family("Cyclone III"),
+		.lpm_numwords(16),
+		.lpm_showahead("ON"),
+		.lpm_type("scfifo"),
+		.lpm_width(16),
+		.lpm_widthu(4),
+		.overflow_checking("ON"),
+		.underflow_checking("ON"),
+		.use_eab("OFF")) fifo_tx (
+		.rdreq((~int_rdempty) & (int_rdreq) & (&counter)),
+		.aclr(1'b0),
+		.clock(clock),
+		.wrreq(int_wrreq),
+		.data(int_bus_mosi),
+		.empty(int_rdempty),
+		.q(int_q),
+		.full(int_wrfull),
+		.almost_empty(),
+		.almost_full(),
+		.sclr(),
+		.usedw());
+	
+	always @ (posedge clock)
+	begin
+		int_bus_busy <= int_wrfull;
+
+		if (bus_ssel)
+		begin
+			if (~int_wrfull & bus_wren)
+			begin
+				int_bus_mosi <= bus_mosi;
+				int_wrreq <= 1'b1;
+			end
+		end
+		
+		if (~int_wrfull & int_wrreq)
+		begin
+			int_wrreq <= 1'b0;
+		end
+
+	end
+
+	always @ (posedge clock)
+	begin
+		counter <= counter + 10'd1;
+		if (&counter)
+		begin
+			case (state)
+				0:
+				begin
+					int_ack <= 1'b0;
+					int_sdo <= 1'b1;
+					int_scl <= 1'b1;
+					int_rdreq <= 1'b1;
+					state <= 5'd1;
+				end
+	
+				1: 
+				begin
+					if (~int_rdempty)
+					begin
+						int_data <= int_q;
+						int_rdreq <= 1'b0;
+						state <= 5'd2;
+					end
+				end
+	
+				2: 
+				begin
+					if (start)
+					begin
+						int_sdo <= 1'b1;
+						int_scl <= 1'b1;
+						state <= 5'd3;
+					end
+					else
+					begin
+						state <= 5'd5;
+					end
+				end
+			
+				3:
+				begin // start
+					int_sdo <= 1'b0;
+					state <= 5'd4;
+				end
+	
+				4:
+				begin
+					int_scl <= 1'b0;
+					state <= 5'd5;
+				end
+			
+				5:
+				begin // data
+					int_clken <= 1'b1;
+					int_sdo <= int_data[7];
+					state <= 5'd6;
+				end
+	
+				6:
+				begin
+					int_sdo <= int_data[6];
+					state <= 5'd7;
+				end
+	
+				7:
+				begin
+					int_sdo <= int_data[5];
+					state <= 5'd8;
+				end
+	
+				8:
+				begin
+					int_sdo <= int_data[4];
+					state <= 5'd9;
+				end
+	
+				9:
+				begin
+					int_sdo <= int_data[3];
+					state <= 5'd10;
+				end
+	
+				10:
+				begin
+					int_sdo <= int_data[2];
+					state <= 5'd11;
+				end
+	
+				11:
+				begin
+					int_sdo <= int_data[1];
+					state <= 5'd12;
+				end
+	
+				12:
+				begin
+					int_sdo <= int_data[0];
+					state <= 5'd13;
+				end
+				
+				13:
+				begin // ack
+					int_sdo <= 1'b1;
+					int_rdreq <= 1'b1;
+					state <= 5'd14;
+				end
+	
+				14:
+				begin 
+					int_ack <= i2c_sda;
+					int_rdreq <= 1'b0;
+					if (stop | int_rdempty)
+					begin
+						int_clken <= 1'b0;
+						int_sdo <= 1'b0;
+						int_scl <= 1'b0;
+						state <= 5'd15;
+					end
+					else if (~int_rdempty)
+					begin
+						int_data <= int_q;
+						int_sdo <= int_q[7];
+						state <= 5'd6;
+					end
+				end
+	
+				15:
+				begin // stop
+					int_scl <= 1'b1;
+					state <= 5'd16;
+				end
+	
+				16:
+				begin
+					int_sdo <= 1'b1;
+					state <= 5'd0;
+				end
+	
+			endcase
+		end
+	end
+
+	// output logic
+	assign	bus_busy = int_bus_busy;
+
+endmodule
Index: /trunk/3DEES/new_filter.v
===================================================================
--- /trunk/3DEES/new_filter.v	(revision 177)
+++ /trunk/3DEES/new_filter.v	(revision 177)
@@ -0,0 +1,276 @@
+module new_filter
+	#(
+		parameter	size	=	3, // number of channels
+		parameter	width	=	12 // bit width of the input data (unsigned)
+	)
+	(
+		input	wire						clock, frame, reset,
+		input	wire	[size*width-1:0]	inp_data,
+		output	wire	[size*widthr-1:0]	out_data
+	);
+	
+	localparam	widthr	=	width + 9;
+	/*
+	4-bit LFSR with additional bits to keep track of previous values
+	*/
+	reg		[15:0]				int_lfsr_reg, int_lfsr_next;
+
+	reg							int_wren_reg, int_wren_next;
+	reg							int_flag_reg, int_flag_next;
+	reg		[1:0]				int_chan_reg, int_chan_next;
+	reg		[2:0]				int_case_reg, int_case_next;
+	reg		[5:0]				int_addr_reg, int_addr_next;
+
+	wire	[5:0]				int_addr_wire;
+
+	reg		[size*widthr-1:0]	acc_data_reg [1:0], acc_data_next [1:0];
+	reg		[size*widthr-1:0]	int_data_reg [4:0], int_data_next [4:0];
+
+	wire	[size*widthr-1:0]	acc_data_wire [1:0], del_data_wire;
+
+	integer i;
+	genvar j;
+
+	generate
+		for (j = 0; j < size; j = j + 1)
+		begin : INT_DATA
+			assign acc_data_wire[0][j*widthr+widthr-1:j*widthr] = {{(widthr-width){1'b0}}, inp_data[j*width+width-1:j*width]};
+
+			assign acc_data_wire[1][j*widthr+widthr-1:j*widthr] =
+				  acc_data_reg[0][j*widthr+widthr-1:j*widthr]
+				- del_data_wire[j*widthr+widthr-1:j*widthr]
+				+ acc_data_reg[1][j*widthr+widthr-1:j*widthr];
+
+		end
+	endgenerate
+
+	altsyncram #(
+		.address_aclr_b("NONE"),
+		.address_reg_b("CLOCK0"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_input_b("BYPASS"),
+		.clock_enable_output_b("BYPASS"),
+		.intended_device_family("Cyclone III"),
+		.lpm_type("altsyncram"),
+		.numwords_a(64),
+		.numwords_b(64),
+		.operation_mode("DUAL_PORT"),
+		.outdata_aclr_b("NONE"),
+		.outdata_reg_b("CLOCK0"),
+		.power_up_uninitialized("FALSE"),
+		.read_during_write_mode_mixed_ports("DONT_CARE"),
+		.widthad_a(6),
+		.widthad_b(6),
+		.width_a(size*widthr),
+		.width_b(size*widthr),
+		.width_byteena_a(1)) ram_unit_1 (
+		.wren_a(int_wren_reg),
+		.clock0(clock),
+		.address_a(int_addr_reg),
+		.address_b(int_addr_wire),
+		.data_a(acc_data_reg[0]),
+		.q_b(del_data_wire),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.data_b({(size*widthr){1'b1}}),
+		.eccstatus(),
+		.q_a(),
+		.rden_a(1'b1),
+		.rden_b(1'b1),
+		.wren_b(1'b0));
+
+	lpm_mux #(
+		.lpm_size(4),
+		.lpm_type("LPM_MUX"),
+		.lpm_width(6),
+		.lpm_widths(2)) mux_unit_1 (
+		.sel(int_chan_next),
+		.data({
+			2'd3, int_lfsr_reg[5+3:5],
+			2'd2, int_lfsr_reg[4+3:4],
+			2'd1, int_lfsr_reg[4+3:4],
+			2'd0, int_lfsr_reg[3+3:3]}),
+		.result(int_addr_wire));                            
+
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			int_wren_reg <= 1'b1;
+			int_flag_reg <= 1'b0;
+			int_chan_reg <= 2'd0;
+			int_case_reg <= 3'd0;
+			int_addr_reg <= 6'd0;
+			for(i = 0; i <= 1; i = i + 1)
+			begin
+				acc_data_reg[i] <= {(size*widthr){1'b0}};
+			end
+			for(i = 0; i <= 4; i = i + 1)
+			begin
+				int_data_reg[i] <= {(size*widthr){1'b0}};
+			end
+			int_lfsr_reg <= 16'd0;
+		end
+		else
+		begin
+			int_wren_reg <= int_wren_next;
+			int_flag_reg <= int_flag_next;
+			int_chan_reg <= int_chan_next;
+			int_case_reg <= int_case_next;
+			int_addr_reg <= int_addr_next;
+			for(i = 0; i <= 1; i = i + 1)
+			begin
+				acc_data_reg[i] <= acc_data_next[i];
+			end
+			for(i = 0; i <= 4; i = i + 1)
+			begin
+				int_data_reg[i] <= int_data_next[i];
+			end
+			int_lfsr_reg <= int_lfsr_next;
+		end             
+	end
+	
+	always @*
+	begin
+		int_wren_next = int_wren_reg;
+		int_flag_next = int_flag_reg;
+		int_chan_next = int_chan_reg;
+		int_case_next = int_case_reg;
+		int_addr_next = int_addr_reg;
+		for(i = 0; i <= 1; i = i + 1)
+		begin
+			acc_data_next[i] = acc_data_reg[i];
+		end
+		for(i = 0; i <= 4; i = i + 1)
+		begin
+			int_data_next[i] = int_data_reg[i];
+		end
+		int_lfsr_next = int_lfsr_reg;
+
+		case (int_case_reg)		
+			0:
+			begin
+				// write zeros
+				int_wren_next = 1'b1;
+				int_addr_next = 6'd0;
+				for(i = 0; i <= 1; i = i + 1)
+				begin
+					acc_data_next[i] = {(size*widthr){1'b0}};
+				end
+				for(i = 0; i <= 4; i = i + 1)
+				begin
+					int_data_next[i] = {(size*widthr){1'b0}};
+				end
+				int_case_next = 3'd1;
+			end	
+			1:
+			begin
+				// write zeros
+				int_addr_next = int_addr_reg + 6'd1;
+				if (&int_addr_reg)
+				begin
+					int_wren_next = 1'b0;
+					int_flag_next = 1'b0;
+					int_chan_next = 2'd0;
+					int_lfsr_next = 16'h7650;
+					int_case_next = 3'd2;
+				end
+			end	
+			2: // frame
+			begin
+				int_flag_next = 1'b0;
+				if (frame)
+				begin
+					int_wren_next = 1'b1;
+
+					int_addr_next = {2'd0, int_lfsr_reg[3:0]};
+					
+					// set read addr for 2nd pipeline
+					int_chan_next = 2'd1;
+                    
+					// prepare registers for 1st sum					
+					acc_data_next[0] = acc_data_wire[0];
+					acc_data_next[1] = int_data_reg[0];
+					
+					int_case_next = 3'd3;
+				end
+				if (int_flag_reg) // register 4th sum
+				begin
+					// register 4th sum
+					int_data_next[3] = acc_data_wire[1];
+				end
+			end
+			3:  // 1st sum
+			begin				
+				int_addr_next = {2'd1, int_lfsr_reg[3:0]};
+
+				// set read addr for 3rd pipeline
+				int_chan_next = 2'd2;
+
+				// prepare registers for 2nd sum	
+				acc_data_next[0] = int_data_reg[0];
+				acc_data_next[1] = int_data_reg[1];
+
+				// register 1st sum
+				int_data_next[0] = acc_data_wire[1];
+
+				int_case_next = 3'd4;
+			end
+			4: // 2nd sum
+			begin
+				int_addr_next = {2'd2, int_lfsr_reg[3:0]};
+
+				// set read addr for 4th pipeline
+				int_chan_next = 2'd3;
+
+				// prepare registers for 3rd sum	
+				acc_data_next[0] = int_data_reg[1];
+				acc_data_next[1] = int_data_reg[2];
+
+				// register 2nd sum
+				int_data_next[1] = acc_data_wire[1];
+				
+				int_lfsr_next = {int_lfsr_reg[14:0], int_lfsr_reg[2] ~^ int_lfsr_reg[3]};
+
+				int_case_next = 3'd5;
+			end
+			5:  // 3rd sum
+			begin				
+				int_flag_next = 1'b1;
+
+				int_addr_next = {2'd3, int_lfsr_reg[4:1]};
+
+				// set read addr for 1st pipeline
+				int_chan_next = 2'd0;
+
+				// prepare registers for 4th sum	
+				acc_data_next[0] = int_data_reg[2];
+				acc_data_next[1] = int_data_reg[3];
+
+				// register 3rd sum
+				int_data_next[2] = acc_data_wire[1];
+				
+				// register 4th output
+				int_data_next[4] = int_data_reg[3];
+
+				int_case_next = 3'd2;
+			end
+			default:
+			begin
+				int_case_next = 3'd0;
+			end
+		endcase
+	end
+
+	assign out_data = int_data_reg[4];
+
+endmodule
Index: /trunk/3DEES/oscilloscope.v
===================================================================
--- /trunk/3DEES/oscilloscope.v	(revision 177)
+++ /trunk/3DEES/oscilloscope.v	(revision 177)
@@ -0,0 +1,246 @@
+module oscilloscope
+	(
+		input	wire			clock, frame, reset,
+		
+		input	wire			cfg_data,
+
+		input	wire			trg_flag,
+
+		input	wire	[63:0]	osc_data,
+
+		output	wire			ram_wren,
+		output	wire	[19:0]	ram_addr,
+		inout	wire	[17:0]	ram_data,
+
+		input	wire			bus_ssel, bus_wren,
+		input	wire	[19:0]	bus_addr,
+		input	wire	[15:0]	bus_mosi,
+
+		output	wire	[15:0]	bus_miso,
+		output	wire			bus_busy
+	);
+
+
+	reg		[63:0]	osc_data_reg, osc_data_next;
+
+	reg		[2:0]	int_case_reg, int_case_next;
+
+	reg				int_trig_reg, int_trig_next;
+	reg		[19:0]	int_trig_addr_reg, int_trig_addr_next;
+
+	reg		[19:0]	int_cntr_reg [1:0];
+	reg		[19:0]	int_cntr_next [1:0];
+
+	reg		[15:0]	bus_miso_reg, bus_miso_next;
+	reg				bus_busy_reg, bus_busy_next;
+
+	reg				ram_wren_reg [2:0];
+	reg				ram_wren_next [2:0];
+
+	reg		[17:0]	ram_data_reg [2:0];
+	reg		[17:0]	ram_data_next [2:0];
+
+	reg		[19:0]	ram_addr_reg, ram_addr_next;
+
+	wire	[17:0]	ram_wren_wire;
+
+	assign	ram_wren = ~ram_wren_reg[0];
+	assign	ram_addr = ram_addr_reg;
+
+	integer i;
+	genvar j;
+
+	generate
+		for (j = 0; j < 18; j = j + 1)
+		begin : SRAM_WREN
+			assign ram_wren_wire[j] = ram_wren_reg[2];
+			assign ram_data[j] = ram_wren_wire[j] ? ram_data_reg[2][j] : 1'bz;
+		end
+	endgenerate
+
+	always @(posedge clock)
+	begin
+		if (reset)
+		begin
+			osc_data_reg <= 64'd0;
+			ram_addr_reg <= 20'd0;
+			bus_miso_reg <= 16'd0;
+			bus_busy_reg <= 1'b0;
+			int_case_reg <= 5'd0;
+			int_cntr_reg[0] <= 20'd0;
+			int_cntr_reg[1] <= 20'd0;
+			int_trig_reg <= 1'b0;
+			int_trig_addr_reg <= 20'd0;
+			
+			for(i = 0; i <= 2; i = i + 1)
+			begin
+				ram_wren_reg[i] <= 1'b0;
+				ram_data_reg[i] <= 16'd0;
+			end
+		end
+		else
+		begin
+			osc_data_reg <= osc_data_next;
+			ram_addr_reg <= ram_addr_next;
+			bus_miso_reg <= bus_miso_next;
+			bus_busy_reg <= bus_busy_next;
+			int_case_reg <= int_case_next;
+			int_cntr_reg[0] <= int_cntr_next[0];
+			int_cntr_reg[1] <= int_cntr_next[1];
+			int_trig_reg <= int_trig_next;
+			int_trig_addr_reg <= int_trig_addr_next;
+
+			for(i = 0; i <= 2; i = i + 1)
+			begin
+				ram_wren_reg[i] <= ram_wren_next[i];
+				ram_data_reg[i] <= ram_data_next[i];
+			end
+		end
+	end
+
+	always @*
+	begin
+
+		osc_data_next = osc_data_reg;
+		ram_addr_next = ram_addr_reg;
+		bus_miso_next = bus_miso_reg;
+		bus_busy_next = bus_busy_reg;
+		int_case_next = int_case_reg;
+		int_cntr_next[0] = int_cntr_reg[0];
+		int_cntr_next[1] = int_cntr_reg[1];
+		int_trig_next = int_trig_reg;
+		int_trig_addr_next = int_trig_addr_reg;
+
+		for(i = 0; i < 2; i = i + 1)
+		begin
+			ram_wren_next[i+1] = ram_wren_reg[i];
+			ram_data_next[i+1] = ram_data_reg[i];
+		end
+		ram_wren_next[0] = 1'b0;
+		ram_data_next[0] = 18'd0;
+
+		case (int_case_reg)
+			0:
+			begin
+				bus_busy_next = 1'b0;
+				int_cntr_next[0] = 20'd0;
+				int_cntr_next[1] = 20'd0;
+				int_trig_next = 1'b0;
+
+				if (bus_ssel)
+				begin
+					bus_miso_next = ram_data[15:0];
+					ram_wren_next[0] = bus_wren;
+					if (bus_wren)
+					begin
+						ram_addr_next = bus_addr;
+						ram_data_next[0] = {bus_mosi[15:8], 1'b0, bus_mosi[7:0], 1'b0};
+					end
+					else
+					begin
+						ram_addr_next = int_trig_addr_reg + bus_addr;	
+//						ram_addr_next = bus_addr;	
+					end
+				end
+				else if (cfg_data)
+				begin
+					// start recording
+					ram_wren_next[0] = 1'b1;
+					ram_data_next[0] = 18'd0;
+					ram_addr_next = 20'd0;
+					bus_busy_next = 1'b1;
+					int_case_next = 3'd1;
+					int_trig_addr_next = 20'd0;
+//					int_cntr_next[0] = {cfg_data[7:0], 10'd0};
+					int_cntr_next[0] = 20'd262143;
+//					int_cntr_next[1] = {cfg_data[15:8], 10'd0};
+					int_cntr_next[1] = 20'd5000;
+				end
+
+			end
+
+			// write zeros
+			1:
+			begin
+				ram_wren_next[0] = 1'b1;
+				ram_data_next[0] = 18'd2;
+				if(&ram_addr_reg)
+				begin
+					int_case_next = 3'd2;
+				end
+				else
+				begin
+					ram_addr_next = ram_addr_reg + 20'd1;
+				end
+			end
+
+			// sample recording
+			2:
+			begin
+				if (frame)
+				begin
+					osc_data_next = osc_data;
+					ram_addr_next = ram_addr_reg + 20'd1;
+					ram_wren_next[0] = 1'b1;
+					ram_data_next[0] = {2'd0, osc_data[15:0]};
+		
+					int_case_next = 3'd3;
+
+					if (|int_cntr_reg[1])
+					begin
+						int_cntr_next[0] = int_cntr_reg[0] - 20'd1;
+						int_cntr_next[1] = int_cntr_reg[1] - 20'd1;
+					end
+					else if (int_trig_reg)
+					begin
+						if (|int_cntr_reg[0])
+						begin
+							int_cntr_next[0] = int_cntr_reg[0] - 20'd1;
+						end
+					end
+					else if (trg_flag)
+					begin
+						int_trig_next = 1'b1;
+						int_trig_addr_next = ram_addr_reg - 20'd19999;
+					end
+				end
+			end
+
+			3:
+			begin
+				ram_addr_next = ram_addr_reg + 20'd1;
+				ram_wren_next[0] = 1'b1;
+				ram_data_next[0] = {2'd0, osc_data_reg[31:16]};
+				int_case_next = 3'd4;
+			end
+
+			4:
+			begin
+				ram_addr_next = ram_addr_reg + 20'd1;
+				ram_wren_next[0] = 1'b1;
+				ram_data_next[0] = {2'd0, osc_data_reg[47:32]};
+				int_case_next = 3'd5;
+			end
+
+			5:
+			begin
+				ram_addr_next = ram_addr_reg + 20'd1;
+				ram_wren_next[0] = 1'b1;
+				ram_data_next[0] = {2'd0, osc_data_reg[63:48]};
+				if (|int_cntr_reg[0])
+				begin
+					int_case_next = 3'd2;
+				end
+				else
+				begin
+					int_case_next = 3'd0;
+				end
+			end
+
+		endcase
+	end
+
+	assign bus_miso = bus_miso_reg;
+	assign bus_busy = bus_busy_reg;
+
+endmodule
Index: /trunk/3DEES/pwm.v
===================================================================
--- /trunk/3DEES/pwm.v	(revision 177)
+++ /trunk/3DEES/pwm.v	(revision 177)
@@ -0,0 +1,31 @@
+module pwm
+	(
+		input	wire			clock,
+		input	wire	[47:0]	cfg_data,
+		output	wire	[3:0]	out_data
+
+	);
+
+	reg		[12:0]	int_data_reg [3:0];
+	wire	[11:0]	cfg_data_wire [3:0];
+
+	integer i;
+	genvar j;
+
+	always @ (posedge clock)
+	begin
+		for(i = 0; i <= 3; i = i + 1)
+		begin
+			int_data_reg[i] <= {1'b0, int_data_reg[i][11:0]} + {1'b0, cfg_data_wire[i]};
+		end
+	end
+
+	generate
+		for (j = 0; j <= 3; j = j + 1)
+		begin : PWM_DATA
+			assign cfg_data_wire[j] = cfg_data[j*12+11:j*12];
+			assign out_data[j] = int_data_reg[j][12] ? 1'bz : 1'b0;
+		end
+	endgenerate
+
+endmodule
Index: /trunk/3DEES/spi_fifo.v
===================================================================
--- /trunk/3DEES/spi_fifo.v	(revision 177)
+++ /trunk/3DEES/spi_fifo.v	(revision 177)
@@ -0,0 +1,128 @@
+module spi_fifo
+	(		
+		input	wire			clock, reset,
+
+		input	wire			bus_ssel, bus_wren,
+		input	wire	[15:0]	bus_mosi,
+
+		output	wire			bus_busy,
+
+		output	wire	[1:0]	spi_sel,
+		output	wire			spi_sdo,
+		output	wire			spi_clk
+	);
+
+	wire			int_rdempty, int_wrfull;
+	wire	[31:0]	int_q;
+
+	reg				int_bus_busy;
+	reg				int_rdreq, int_wrreq;
+	reg				int_clken, int_sdo;
+	reg		[1:0]	int_sel;
+	reg		[15:0]	int_bus_mosi;
+	reg		[31:0]	int_data;
+	reg		[2:0]	clk_cntr;
+	reg		[4:0]	bit_cntr;
+	reg		[1:0]	state;
+
+	dcfifo_mixed_widths #(
+		.intended_device_family("Cyclone III"),
+		.lpm_numwords(16),
+		.lpm_showahead("ON"),
+		.lpm_type("dcfifo"),
+		.lpm_width(16),
+		.lpm_widthu(4),
+		.lpm_width_r(32),
+		.lpm_widthu_r(3),
+		.rdsync_delaypipe(4),
+		.wrsync_delaypipe(4),
+		.overflow_checking("ON"),
+		.underflow_checking("ON"),
+		.use_eab("ON")) fifo_tx (
+		.data(int_bus_mosi),
+		.rdclk(clock),
+		.rdreq((~int_rdempty) & (int_rdreq) & (&clk_cntr)),
+		.wrclk(clock),
+		.wrreq(int_wrreq),
+		.q(int_q),
+		.rdempty(int_rdempty),
+		.wrfull(int_wrfull));
+	
+	always @ (posedge clock)
+	begin
+		int_bus_busy <= int_wrfull;
+
+		if (bus_ssel)
+		begin
+			if (~int_wrfull & bus_wren)
+			begin
+				int_bus_mosi <= bus_mosi;
+				int_wrreq <= 1'b1;
+			end
+		end
+		
+		if (~int_wrfull & int_wrreq)
+		begin
+			int_wrreq <= 1'b0;
+		end
+
+	end
+
+	always @ (posedge clock)
+	begin
+		clk_cntr <= clk_cntr + 3'd1;
+		if (&clk_cntr)
+		begin
+			case (state)
+				0:
+				begin
+					int_sdo <= 1'b0;
+					int_sel <= 2'b11;
+					int_clken <= 1'b0;
+					int_rdreq <= 1'b1;
+					state <= 2'd1;
+				end
+	
+				1: 
+				begin
+					if (~int_rdempty)
+					begin
+						int_rdreq <= 1'b0;
+						int_data <= {int_q[15:0], int_q[31:16]};
+						bit_cntr <= 5'd0;
+						state <= 2'd2;
+					end
+				end
+	
+
+				2:
+				begin // data
+					int_clken <= 1'b1;
+					int_sel <= int_data[25:24];
+					int_sdo <= int_data[23];
+					int_data[23:0] <= {int_data[22:0], 1'b0};
+					bit_cntr <= bit_cntr + 5'd1;
+					if (bit_cntr == 5'd23)
+					begin
+						state <= 2'd3;
+					end
+				end
+	
+				3:
+				begin
+					int_sdo <= 1'b0;
+					int_clken <= 1'b0;
+					state <= 2'd0;
+				end
+	
+			endcase
+		end
+	end
+
+	// output logic
+	assign	bus_busy = int_bus_busy;
+	assign 	spi_clk = (int_clken ? clk_cntr[2] : 1'b1);	
+	assign 	spi_sdo = int_sdo;	
+	assign 	spi_sel = int_sel;	
+
+endmodule
Index: /trunk/3DEES/sys_pll.v
===================================================================
--- /trunk/3DEES/sys_pll.v	(revision 177)
+++ /trunk/3DEES/sys_pll.v	(revision 177)
@@ -0,0 +1,145 @@
+// megafunction wizard: %ALTPLL%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altpll 
+
+// ============================================================
+// File Name: sys_pll.v
+// Megafunction Name(s):
+// 			altpll
+//
+// Simulation Library Files(s):
+// 			altera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 9.0 Build 132 02/25/2009 SJ Web Edition
+// ************************************************************
+
+
+//Copyright (C) 1991-2009 Altera Corporation
+//Your use of Altera Corporation's design tools, logic functions 
+//and other software and tools, and its AMPP partner logic 
+//functions, and any output files from any of the foregoing 
+//(including device programming or simulation files), and any 
+//associated documentation or information are expressly subject 
+//to the terms and conditions of the Altera Program License 
+//Subscription Agreement, Altera MegaCore Function License 
+//Agreement, or other applicable license agreement, including, 
+//without limitation, that your use is for the sole purpose of 
+//programming logic devices manufactured by Altera and sold by 
+//Altera or its authorized distributors.  Please refer to the 
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module sys_pll (
+	inclk0,
+	c0);
+
+	input	  inclk0;
+	output	  c0;
+
+	wire [4:0] sub_wire0;
+	wire [0:0] sub_wire4 = 1'h0;
+	wire [0:0] sub_wire1 = sub_wire0[0:0];
+	wire  c0 = sub_wire1;
+	wire  sub_wire2 = inclk0;
+	wire [1:0] sub_wire3 = {sub_wire4, sub_wire2};
+
+	altpll	altpll_component (
+				.inclk (sub_wire3),
+				.clk (sub_wire0),
+				.activeclock (),
+				.areset (1'b0),
+				.clkbad (),
+				.clkena ({6{1'b1}}),
+				.clkloss (),
+				.clkswitch (1'b0),
+				.configupdate (1'b0),
+				.enable0 (),
+				.enable1 (),
+				.extclk (),
+				.extclkena ({4{1'b1}}),
+				.fbin (1'b1),
+				.fbmimicbidir (),
+				.fbout (),
+				.locked (),
+				.pfdena (1'b1),
+				.phasecounterselect ({4{1'b1}}),
+				.phasedone (),
+				.phasestep (1'b1),
+				.phaseupdown (1'b1),
+				.pllena (1'b1),
+				.scanaclr (1'b0),
+				.scanclk (1'b0),
+				.scanclkena (1'b1),
+				.scandata (1'b0),
+				.scandataout (),
+				.scandone (),
+				.scanread (1'b0),
+				.scanwrite (1'b0),
+				.sclkout0 (),
+				.sclkout1 (),
+				.vcooverrange (),
+				.vcounderrange ());
+	defparam
+		altpll_component.bandwidth_type = "AUTO",
+		altpll_component.clk0_divide_by = 10,
+		altpll_component.clk0_duty_cycle = 50,
+		altpll_component.clk0_multiply_by = 17,
+		altpll_component.clk0_phase_shift = "0",
+		altpll_component.compensate_clock = "CLK0",
+		altpll_component.inclk0_input_frequency = 20000,
+		altpll_component.intended_device_family = "Cyclone III",
+		altpll_component.lpm_hint = "CBX_MODULE_PREFIX=pll",
+		altpll_component.lpm_type = "altpll",
+		altpll_component.operation_mode = "NORMAL",
+		altpll_component.pll_type = "AUTO",
+		altpll_component.port_activeclock = "PORT_UNUSED",
+		altpll_component.port_areset = "PORT_UNUSED",
+		altpll_component.port_clkbad0 = "PORT_UNUSED",
+		altpll_component.port_clkbad1 = "PORT_UNUSED",
+		altpll_component.port_clkloss = "PORT_UNUSED",
+		altpll_component.port_clkswitch = "PORT_UNUSED",
+		altpll_component.port_configupdate = "PORT_UNUSED",
+		altpll_component.port_fbin = "PORT_UNUSED",
+		altpll_component.port_inclk0 = "PORT_USED",
+		altpll_component.port_inclk1 = "PORT_UNUSED",
+		altpll_component.port_locked = "PORT_UNUSED",
+		altpll_component.port_pfdena = "PORT_UNUSED",
+		altpll_component.port_phasecounterselect = "PORT_UNUSED",
+		altpll_component.port_phasedone = "PORT_UNUSED",
+		altpll_component.port_phasestep = "PORT_UNUSED",
+		altpll_component.port_phaseupdown = "PORT_UNUSED",
+		altpll_component.port_pllena = "PORT_UNUSED",
+		altpll_component.port_scanaclr = "PORT_UNUSED",
+		altpll_component.port_scanclk = "PORT_UNUSED",
+		altpll_component.port_scanclkena = "PORT_UNUSED",
+		altpll_component.port_scandata = "PORT_UNUSED",
+		altpll_component.port_scandataout = "PORT_UNUSED",
+		altpll_component.port_scandone = "PORT_UNUSED",
+		altpll_component.port_scanread = "PORT_UNUSED",
+		altpll_component.port_scanwrite = "PORT_UNUSED",
+		altpll_component.port_clk0 = "PORT_USED",
+		altpll_component.port_clk1 = "PORT_UNUSED",
+		altpll_component.port_clk2 = "PORT_UNUSED",
+		altpll_component.port_clk3 = "PORT_UNUSED",
+		altpll_component.port_clk4 = "PORT_UNUSED",
+		altpll_component.port_clk5 = "PORT_UNUSED",
+		altpll_component.port_clkena0 = "PORT_UNUSED",
+		altpll_component.port_clkena1 = "PORT_UNUSED",
+		altpll_component.port_clkena2 = "PORT_UNUSED",
+		altpll_component.port_clkena3 = "PORT_UNUSED",
+		altpll_component.port_clkena4 = "PORT_UNUSED",
+		altpll_component.port_clkena5 = "PORT_UNUSED",
+		altpll_component.port_extclk0 = "PORT_UNUSED",
+		altpll_component.port_extclk1 = "PORT_UNUSED",
+		altpll_component.port_extclk2 = "PORT_UNUSED",
+		altpll_component.port_extclk3 = "PORT_UNUSED",
+		altpll_component.width_clock = 5;
+
+endmodule
Index: /trunk/3DEES/test.mif
===================================================================
--- /trunk/3DEES/test.mif	(revision 177)
+++ /trunk/3DEES/test.mif	(revision 177)
@@ -0,0 +1,2584 @@
+-- Copyright (C) 1991-2010 Altera Corporation
+-- Your use of Altera Corporation's design tools, logic functions 
+-- and other software and tools, and its AMPP partner logic 
+-- functions, and any output files from any of the foregoing 
+-- (including device programming or simulation files), and any 
+-- associated documentation or information are expressly subject 
+-- to the terms and conditions of the Altera Program License 
+-- Subscription Agreement, Altera MegaCore Function License 
+-- Agreement, or other applicable license agreement, including, 
+-- without limitation, that your use is for the sole purpose of 
+-- programming logic devices manufactured by Altera and sold by 
+-- Altera or its authorized distributors.  Please refer to the 
+-- applicable agreement for further details.
+
+-- Quartus II generated Memory Initialization File (.mif)
+
+WIDTH=12;
+DEPTH=2560;
+
+ADDRESS_RADIX=HEX;
+DATA_RADIX=UNS;
+
+CONTENT BEGIN
+0000 : 1176;
+0001 : 1178;
+0002 : 1178;
+0003 : 1177;
+0004 : 1177;
+0005 : 1176;
+0006 : 1177;
+0007 : 1179;
+0008 : 1178;
+0009 : 1178;
+000A : 1178;
+000B : 1177;
+000C : 1179;
+000D : 1178;
+000E : 1178;
+000F : 1176;
+0010 : 1177;
+0011 : 1178;
+0012 : 1177;
+0013 : 1177;
+0014 : 1176;
+0015 : 1177;
+0016 : 1177;
+0017 : 1177;
+0018 : 1177;
+0019 : 1177;
+001A : 1178;
+001B : 1178;
+001C : 1178;
+001D : 1178;
+001E : 1178;
+001F : 1178;
+0020 : 1178;
+0021 : 1178;
+0022 : 1177;
+0023 : 1177;
+0024 : 1178;
+0025 : 1178;
+0026 : 1179;
+0027 : 1177;
+0028 : 1177;
+0029 : 1177;
+002A : 1178;
+002B : 1178;
+002C : 1176;
+002D : 1177;
+002E : 1178;
+002F : 1179;
+0030 : 1179;
+0031 : 1178;
+0032 : 1177;
+0033 : 1176;
+0034 : 1179;
+0035 : 1178;
+0036 : 1177;
+0037 : 1177;
+0038 : 1177;
+0039 : 1177;
+003A : 1178;
+003B : 1178;
+003C : 1177;
+003D : 1177;
+003E : 1178;
+003F : 1178;
+0040 : 1179;
+0041 : 1177;
+0042 : 1177;
+0043 : 1179;
+0044 : 1179;
+0045 : 1179;
+0046 : 1179;
+0047 : 1178;
+0048 : 1178;
+0049 : 1179;
+004A : 1178;
+004B : 1178;
+004C : 1178;
+004D : 1178;
+004E : 1178;
+004F : 1178;
+0050 : 1178;
+0051 : 1177;
+0052 : 1178;
+0053 : 1179;
+0054 : 1178;
+0055 : 1178;
+0056 : 1177;
+0057 : 1178;
+0058 : 1178;
+0059 : 1178;
+005A : 1177;
+005B : 1177;
+005C : 1177;
+005D : 1272;
+005E : 1649;
+005F : 1845;
+0060 : 1893;
+0061 : 1903;
+0062 : 1905;
+0063 : 1904;
+0064 : 1899;
+0065 : 1897;
+0066 : 1895;
+0067 : 1896;
+0068 : 1894;
+0069 : 1893;
+006A : 1891;
+006B : 1891;
+006C : 1890;
+006D : 1889;
+006E : 1888;
+006F : 1887;
+0070 : 1887;
+0071 : 1887;
+0072 : 1886;
+0073 : 1885;
+0074 : 1884;
+0075 : 1883;
+0076 : 1884;
+0077 : 1883;
+0078 : 1881;
+0079 : 1880;
+007A : 1880;
+007B : 1880;
+007C : 1876;
+007D : 1873;
+007E : 1874;
+007F : 1875;
+0080 : 1874;
+0081 : 1875;
+0082 : 1873;
+0083 : 1873;
+0084 : 1874;
+0085 : 1872;
+0086 : 1871;
+0087 : 1870;
+0088 : 1870;
+0089 : 1869;
+008A : 1869;
+008B : 1868;
+008C : 1866;
+008D : 1865;
+008E : 1866;
+008F : 1865;
+0090 : 1864;
+0091 : 1863;
+0092 : 1861;
+0093 : 1861;
+0094 : 1861;
+0095 : 1860;
+0096 : 1858;
+0097 : 1857;
+0098 : 1856;
+0099 : 1858;
+009A : 1857;
+009B : 1856;
+009C : 1855;
+009D : 1855;
+009E : 1854;
+009F : 1854;
+00A0 : 1852;
+00A1 : 1851;
+00A2 : 1851;
+00A3 : 1852;
+00A4 : 1850;
+00A5 : 1849;
+00A6 : 1847;
+00A7 : 1847;
+00A8 : 1847;
+00A9 : 1847;
+00AA : 1845;
+00AB : 1844;
+00AC : 1843;
+00AD : 1844;
+00AE : 1843;
+00AF : 1842;
+00B0 : 1840;
+00B1 : 1840;
+00B2 : 1841;
+00B3 : 1840;
+00B4 : 1838;
+00B5 : 1837;
+00B6 : 1837;
+00B7 : 1837;
+00B8 : 1836;
+00B9 : 1835;
+00BA : 1834;
+00BB : 1833;
+00BC : 1832;
+00BD : 1833;
+00BE : 1832;
+00BF : 1831;
+00C0 : 1830;
+00C1 : 1830;
+00C2 : 1829;
+00C3 : 1828;
+00C4 : 1826;
+00C5 : 1827;
+00C6 : 1827;
+00C7 : 1826;
+00C8 : 1825;
+00C9 : 1823;
+00CA : 1823;
+00CB : 1823;
+00CC : 1823;
+00CD : 1821;
+00CE : 1820;
+00CF : 1820;
+00D0 : 1820;
+00D1 : 1820;
+00D2 : 1819;
+00D3 : 1818;
+00D4 : 1816;
+00D5 : 1817;
+00D6 : 1816;
+00D7 : 1815;
+00D8 : 1813;
+00D9 : 1813;
+00DA : 1813;
+00DB : 1812;
+00DC : 1811;
+00DD : 1810;
+00DE : 1810;
+00DF : 1810;
+00E0 : 1810;
+00E1 : 1808;
+00E2 : 1807;
+00E3 : 1805;
+00E4 : 1806;
+00E5 : 1807;
+00E6 : 1806;
+00E7 : 1803;
+00E8 : 1802;
+00E9 : 1803;
+00EA : 1803;
+00EB : 1802;
+00EC : 1799;
+00ED : 1799;
+00EE : 1799;
+00EF : 1799;
+00F0 : 1797;
+00F1 : 1796;
+00F2 : 1796;
+00F3 : 1796;
+00F4 : 1796;
+00F5 : 1795;
+00F6 : 1794;
+00F7 : 1792;
+00F8 : 1793;
+00F9 : 1792;
+00FA : 1792;
+00FB : 1791;
+00FC : 1789;
+00FD : 1789;
+00FE : 1789;
+00FF : 1788;
+0100 : 1787;
+0101 : 1787;
+0102 : 1787;
+0103 : 1786;
+0104 : 1785;
+0105 : 1783;
+0106 : 1782;
+0107 : 1782;
+0108 : 1783;
+0109 : 1782;
+010A : 1781;
+010B : 1779;
+010C : 1779;
+010D : 1779;
+010E : 1778;
+010F : 1777;
+0110 : 1777;
+0111 : 1777;
+0112 : 1776;
+0113 : 1775;
+0114 : 1774;
+0115 : 1774;
+0116 : 1773;
+0117 : 1773;
+0118 : 1772;
+0119 : 1772;
+011A : 1771;
+011B : 1770;
+011C : 1769;
+011D : 1769;
+011E : 1768;
+011F : 1767;
+0120 : 1767;
+0121 : 1766;
+0122 : 1766;
+0123 : 1765;
+0124 : 1764;
+0125 : 1763;
+0126 : 1763;
+0127 : 1762;
+0128 : 1761;
+0129 : 1760;
+012A : 1761;
+012B : 1760;
+012C : 1760;
+012D : 1759;
+012E : 1757;
+012F : 1757;
+0130 : 1758;
+0131 : 1757;
+0132 : 1755;
+0133 : 1753;
+0134 : 1754;
+0135 : 1753;
+0136 : 1754;
+0137 : 1752;
+0138 : 1752;
+0139 : 1751;
+013A : 1752;
+013B : 1751;
+013C : 1750;
+013D : 1749;
+013E : 1749;
+013F : 1748;
+0140 : 1748;
+0141 : 1747;
+0142 : 1746;
+0143 : 1745;
+0144 : 1745;
+0145 : 1745;
+0146 : 1743;
+0147 : 1742;
+0148 : 1742;
+0149 : 1742;
+014A : 1741;
+014B : 1740;
+014C : 1740;
+014D : 1740;
+014E : 1739;
+014F : 1739;
+0150 : 1737;
+0151 : 1736;
+0152 : 1736;
+0153 : 1736;
+0154 : 1735;
+0155 : 1734;
+0156 : 1732;
+0157 : 1732;
+0158 : 1733;
+0159 : 1732;
+015A : 1732;
+015B : 1730;
+015C : 1730;
+015D : 1730;
+015E : 1729;
+015F : 1728;
+0160 : 1727;
+0161 : 1727;
+0162 : 1726;
+0163 : 1726;
+0164 : 1725;
+0165 : 1723;
+0166 : 1723;
+0167 : 1724;
+0168 : 1723;
+0169 : 1722;
+016A : 1720;
+016B : 1720;
+016C : 1721;
+016D : 1721;
+016E : 1719;
+016F : 1718;
+0170 : 1716;
+0171 : 1718;
+0172 : 1718;
+0173 : 1716;
+0174 : 1716;
+0175 : 1714;
+0176 : 1715;
+0177 : 1715;
+0178 : 1714;
+0179 : 1711;
+017A : 1710;
+017B : 1711;
+017C : 1710;
+017D : 1710;
+017E : 1710;
+017F : 1708;
+0180 : 1708;
+0181 : 1708;
+0182 : 1708;
+0183 : 1707;
+0184 : 1705;
+0185 : 1705;
+0186 : 1705;
+0187 : 1704;
+0188 : 1703;
+0189 : 1703;
+018A : 1702;
+018B : 1702;
+018C : 1702;
+018D : 1701;
+018E : 1700;
+018F : 1700;
+0190 : 1700;
+0191 : 1699;
+0192 : 1697;
+0193 : 1697;
+0194 : 1697;
+0195 : 1697;
+0196 : 1696;
+0197 : 1696;
+0198 : 1693;
+0199 : 1695;
+019A : 1694;
+019B : 1694;
+019C : 1691;
+019D : 1691;
+019E : 1691;
+019F : 1690;
+01A0 : 1691;
+01A1 : 1690;
+01A2 : 1689;
+01A3 : 1688;
+01A4 : 1688;
+01A5 : 1688;
+01A6 : 1687;
+01A7 : 1685;
+01A8 : 1686;
+01A9 : 1686;
+01AA : 1686;
+01AB : 1684;
+01AC : 1684;
+01AD : 1684;
+01AE : 1683;
+01AF : 1683;
+01B0 : 1682;
+01B1 : 1681;
+01B2 : 1681;
+01B3 : 1681;
+01B4 : 1680;
+01B5 : 1679;
+01B6 : 1678;
+01B7 : 1676;
+01B8 : 1677;
+01B9 : 1677;
+01BA : 1676;
+01BB : 1675;
+01BC : 1675;
+01BD : 1674;
+01BE : 1674;
+01BF : 1673;
+01C0 : 1672;
+01C1 : 1673;
+01C2 : 1672;
+01C3 : 1672;
+01C4 : 1670;
+01C5 : 1669;
+01C6 : 1668;
+01C7 : 1669;
+01C8 : 1669;
+01C9 : 1668;
+01CA : 1667;
+01CB : 1667;
+01CC : 1666;
+01CD : 1666;
+01CE : 1665;
+01CF : 1664;
+01D0 : 1664;
+01D1 : 1665;
+01D2 : 1663;
+01D3 : 1663;
+01D4 : 1661;
+01D5 : 1661;
+01D6 : 1660;
+01D7 : 1661;
+01D8 : 1660;
+01D9 : 1657;
+01DA : 1657;
+01DB : 1659;
+01DC : 1658;
+01DD : 1657;
+01DE : 1656;
+01DF : 1656;
+01E0 : 1656;
+01E1 : 1656;
+01E2 : 1654;
+01E3 : 1653;
+01E4 : 1653;
+01E5 : 1654;
+01E6 : 1653;
+01E7 : 1651;
+01E8 : 1650;
+01E9 : 1650;
+01EA : 1651;
+01EB : 1651;
+01EC : 1649;
+01ED : 1648;
+01EE : 1648;
+01EF : 1648;
+01F0 : 1648;
+01F1 : 1647;
+01F2 : 1646;
+01F3 : 1645;
+01F4 : 1645;
+01F5 : 1645;
+01F6 : 1644;
+01F7 : 1643;
+01F8 : 1643;
+01F9 : 1643;
+01FA : 1642;
+01FB : 1642;
+01FC : 1640;
+01FD : 1640;
+01FE : 1640;
+01FF : 1640;
+0200 : 1639;
+0201 : 1637;
+0202 : 1637;
+0203 : 1637;
+0204 : 1638;
+0205 : 1636;
+0206 : 1635;
+0207 : 1634;
+0208 : 1634;
+0209 : 1634;
+020A : 1634;
+020B : 1633;
+020C : 1632;
+020D : 1631;
+020E : 1631;
+020F : 1631;
+0210 : 1631;
+0211 : 1630;
+0212 : 1630;
+0213 : 1629;
+0214 : 1629;
+0215 : 1627;
+0216 : 1627;
+0217 : 1628;
+0218 : 1628;
+0219 : 1627;
+021A : 1626;
+021B : 1626;
+021C : 1625;
+021D : 1625;
+021E : 1625;
+021F : 1622;
+0220 : 1622;
+0221 : 1621;
+0222 : 1622;
+0223 : 1622;
+0224 : 1621;
+0225 : 1620;
+0226 : 1620;
+0227 : 1620;
+0228 : 1620;
+0229 : 1618;
+022A : 1616;
+022B : 1617;
+022C : 1617;
+022D : 1618;
+022E : 1617;
+022F : 1615;
+0230 : 1615;
+0231 : 1615;
+0232 : 1615;
+0233 : 1613;
+0234 : 1613;
+0235 : 1611;
+0236 : 1613;
+0237 : 1613;
+0238 : 1611;
+0239 : 1609;
+023A : 1610;
+023B : 1610;
+023C : 1610;
+023D : 1609;
+023E : 1608;
+023F : 1607;
+0240 : 1607;
+0241 : 1608;
+0242 : 1606;
+0243 : 1606;
+0244 : 1606;
+0245 : 1605;
+0246 : 1605;
+0247 : 1604;
+0248 : 1602;
+0249 : 1602;
+024A : 1602;
+024B : 1602;
+024C : 1602;
+024D : 1601;
+024E : 1599;
+024F : 1599;
+0250 : 1600;
+0251 : 1598;
+0252 : 1596;
+0253 : 1596;
+0254 : 1598;
+0255 : 1597;
+0256 : 1596;
+0257 : 1595;
+0258 : 1595;
+0259 : 1595;
+025A : 1595;
+025B : 1593;
+025C : 1592;
+025D : 1593;
+025E : 1592;
+025F : 1592;
+0260 : 1592;
+0261 : 1590;
+0262 : 1590;
+0263 : 1591;
+0264 : 1590;
+0265 : 1589;
+0266 : 1588;
+0267 : 1587;
+0268 : 1588;
+0269 : 1587;
+026A : 1587;
+026B : 1586;
+026C : 1585;
+026D : 1586;
+026E : 1586;
+026F : 1584;
+0270 : 1584;
+0271 : 1582;
+0272 : 1583;
+0273 : 1583;
+0274 : 1583;
+0275 : 1581;
+0276 : 1580;
+0277 : 1581;
+0278 : 1581;
+0279 : 1580;
+027A : 1579;
+027B : 1579;
+027C : 1579;
+027D : 1580;
+027E : 1578;
+027F : 1577;
+0280 : 1576;
+0281 : 1577;
+0282 : 1576;
+0283 : 1575;
+0284 : 1573;
+0285 : 1574;
+0286 : 1575;
+0287 : 1575;
+0288 : 1573;
+0289 : 1572;
+028A : 1572;
+028B : 1573;
+028C : 1572;
+028D : 1572;
+028E : 1570;
+028F : 1569;
+0290 : 1569;
+0291 : 1570;
+0292 : 1569;
+0293 : 1568;
+0294 : 1568;
+0295 : 1568;
+0296 : 1569;
+0297 : 1568;
+0298 : 1565;
+0299 : 1565;
+029A : 1565;
+029B : 1565;
+029C : 1566;
+029D : 1565;
+029E : 1563;
+029F : 1562;
+02A0 : 1563;
+02A1 : 1563;
+02A2 : 1562;
+02A3 : 1561;
+02A4 : 1562;
+02A5 : 1561;
+02A6 : 1560;
+02A7 : 1559;
+02A8 : 1558;
+02A9 : 1558;
+02AA : 1558;
+02AB : 1557;
+02AC : 1556;
+02AD : 1555;
+02AE : 1557;
+02AF : 1556;
+02B0 : 1557;
+02B1 : 1554;
+02B2 : 1554;
+02B3 : 1554;
+02B4 : 1554;
+02B5 : 1553;
+02B6 : 1552;
+02B7 : 1552;
+02B8 : 1552;
+02B9 : 1552;
+02BA : 1551;
+02BB : 1551;
+02BC : 1549;
+02BD : 1550;
+02BE : 1550;
+02BF : 1549;
+02C0 : 1548;
+02C1 : 1548;
+02C2 : 1547;
+02C3 : 1548;
+02C4 : 1548;
+02C5 : 1547;
+02C6 : 1546;
+02C7 : 1545;
+02C8 : 1546;
+02C9 : 1546;
+02CA : 1544;
+02CB : 1543;
+02CC : 1543;
+02CD : 1543;
+02CE : 1543;
+02CF : 1542;
+02D0 : 1541;
+02D1 : 1541;
+02D2 : 1542;
+02D3 : 1541;
+02D4 : 1540;
+02D5 : 1538;
+02D6 : 1539;
+02D7 : 1540;
+02D8 : 1539;
+02D9 : 1538;
+02DA : 1536;
+02DB : 1537;
+02DC : 1537;
+02DD : 1537;
+02DE : 1536;
+02DF : 1535;
+02E0 : 1535;
+02E1 : 1536;
+02E2 : 1535;
+02E3 : 1533;
+02E4 : 1532;
+02E5 : 1533;
+02E6 : 1532;
+02E7 : 1532;
+02E8 : 1532;
+02E9 : 1531;
+02EA : 1530;
+02EB : 1531;
+02EC : 1532;
+02ED : 1530;
+02EE : 1529;
+02EF : 1529;
+02F0 : 1529;
+02F1 : 1529;
+02F2 : 1528;
+02F3 : 1527;
+02F4 : 1527;
+02F5 : 1528;
+02F6 : 1527;
+02F7 : 1526;
+02F8 : 1525;
+02F9 : 1525;
+02FA : 1526;
+02FB : 1526;
+02FC : 1525;
+02FD : 1523;
+02FE : 1522;
+02FF : 1523;
+0300 : 1523;
+0301 : 1522;
+0302 : 1521;
+0303 : 1520;
+0304 : 1520;
+0305 : 1521;
+0306 : 1520;
+0307 : 1519;
+0308 : 1519;
+0309 : 1519;
+030A : 1518;
+030B : 1518;
+030C : 1517;
+030D : 1516;
+030E : 1518;
+030F : 1516;
+0310 : 1516;
+0311 : 1515;
+0312 : 1515;
+0313 : 1515;
+0314 : 1516;
+0315 : 1515;
+0316 : 1514;
+0317 : 1512;
+0318 : 1513;
+0319 : 1513;
+031A : 1512;
+031B : 1510;
+031C : 1510;
+031D : 1509;
+031E : 1511;
+031F : 1510;
+0320 : 1509;
+0321 : 1510;
+0322 : 1508;
+0323 : 1509;
+0324 : 1508;
+0325 : 1507;
+0326 : 1507;
+0327 : 1506;
+0328 : 1507;
+0329 : 1506;
+032A : 1505;
+032B : 1504;
+032C : 1504;
+032D : 1504;
+032E : 1504;
+032F : 1503;
+0330 : 1503;
+0331 : 1503;
+0332 : 1504;
+0333 : 1502;
+0334 : 1500;
+0335 : 1499;
+0336 : 1501;
+0337 : 1501;
+0338 : 1501;
+0339 : 1500;
+033A : 1499;
+033B : 1499;
+033C : 1499;
+033D : 1499;
+033E : 1499;
+033F : 1498;
+0340 : 1497;
+0341 : 1498;
+0342 : 1497;
+0343 : 1496;
+0344 : 1496;
+0345 : 1495;
+0346 : 1495;
+0347 : 1495;
+0348 : 1494;
+0349 : 1493;
+034A : 1494;
+034B : 1494;
+034C : 1494;
+034D : 1492;
+034E : 1491;
+034F : 1492;
+0350 : 1492;
+0351 : 1492;
+0352 : 1491;
+0353 : 1490;
+0354 : 1490;
+0355 : 1490;
+0356 : 1490;
+0357 : 1489;
+0358 : 1488;
+0359 : 1487;
+035A : 1488;
+035B : 1489;
+035C : 1487;
+035D : 1486;
+035E : 1486;
+035F : 1486;
+0360 : 1487;
+0361 : 1485;
+0362 : 1484;
+0363 : 1485;
+0364 : 1485;
+0365 : 1485;
+0366 : 1483;
+0367 : 1482;
+0368 : 1482;
+0369 : 1482;
+036A : 1482;
+036B : 1482;
+036C : 1481;
+036D : 1480;
+036E : 1480;
+036F : 1480;
+0370 : 1479;
+0371 : 1479;
+0372 : 1478;
+0373 : 1479;
+0374 : 1479;
+0375 : 1478;
+0376 : 1477;
+0377 : 1477;
+0378 : 1477;
+0379 : 1477;
+037A : 1476;
+037B : 1475;
+037C : 1475;
+037D : 1476;
+037E : 1475;
+037F : 1474;
+0380 : 1473;
+0381 : 1472;
+0382 : 1473;
+0383 : 1473;
+0384 : 1472;
+0385 : 1471;
+0386 : 1471;
+0387 : 1471;
+0388 : 1471;
+0389 : 1470;
+038A : 1470;
+038B : 1468;
+038C : 1469;
+038D : 1471;
+038E : 1469;
+038F : 1468;
+0390 : 1467;
+0391 : 1467;
+0392 : 1467;
+0393 : 1468;
+0394 : 1466;
+0395 : 1466;
+0396 : 1466;
+0397 : 1466;
+0398 : 1466;
+0399 : 1464;
+039A : 1464;
+039B : 1464;
+039C : 1464;
+039D : 1463;
+039E : 1462;
+039F : 1462;
+03A0 : 1461;
+03A1 : 1462;
+03A2 : 1462;
+03A3 : 1461;
+03A4 : 1460;
+03A5 : 1461;
+03A6 : 1462;
+03A7 : 1461;
+03A8 : 1459;
+03A9 : 1459;
+03AA : 1459;
+03AB : 1459;
+03AC : 1458;
+03AD : 1458;
+03AE : 1457;
+03AF : 1457;
+03B0 : 1458;
+03B1 : 1457;
+03B2 : 1455;
+03B3 : 1456;
+03B4 : 1456;
+03B5 : 1457;
+03B6 : 1455;
+03B7 : 1454;
+03B8 : 1454;
+03B9 : 1454;
+03BA : 1454;
+03BB : 1454;
+03BC : 1452;
+03BD : 1451;
+03BE : 1451;
+03BF : 1452;
+03C0 : 1451;
+03C1 : 1451;
+03C2 : 1450;
+03C3 : 1450;
+03C4 : 1450;
+03C5 : 1450;
+03C6 : 1448;
+03C7 : 1447;
+03C8 : 1448;
+03C9 : 1449;
+03CA : 1449;
+03CB : 1447;
+03CC : 1446;
+03CD : 1447;
+03CE : 1447;
+03CF : 1447;
+03D0 : 1447;
+03D1 : 1446;
+03D2 : 1445;
+03D3 : 1445;
+03D4 : 1445;
+03D5 : 1444;
+03D6 : 1444;
+03D7 : 1444;
+03D8 : 1444;
+03D9 : 1444;
+03DA : 1442;
+03DB : 1442;
+03DC : 1442;
+03DD : 1442;
+03DE : 1442;
+03DF : 1441;
+03E0 : 1440;
+03E1 : 1441;
+03E2 : 1441;
+03E3 : 1440;
+03E4 : 1439;
+03E5 : 1439;
+03E6 : 1439;
+03E7 : 1439;
+03E8 : 1439;
+03E9 : 1438;
+03EA : 1437;
+03EB : 1437;
+03EC : 1438;
+03ED : 1438;
+03EE : 1437;
+03EF : 1436;
+03F0 : 1435;
+03F1 : 1436;
+03F2 : 1435;
+03F3 : 1435;
+03F4 : 1434;
+03F5 : 1434;
+03F6 : 1435;
+03F7 : 1435;
+03F8 : 1433;
+03F9 : 1432;
+03FA : 1432;
+03FB : 1433;
+03FC : 1433;
+03FD : 1431;
+03FE : 1431;
+03FF : 1431;
+0400 : 1431;
+0401 : 1433;
+0402 : 1431;
+0403 : 1430;
+0404 : 1429;
+0405 : 1429;
+0406 : 1430;
+0407 : 1429;
+0408 : 1428;
+0409 : 1427;
+040A : 1428;
+040B : 1428;
+040C : 1427;
+040D : 1426;
+040E : 1427;
+040F : 1427;
+0410 : 1427;
+0411 : 1426;
+0412 : 1425;
+0413 : 1425;
+0414 : 1425;
+0415 : 1425;
+0416 : 1424;
+0417 : 1423;
+0418 : 1423;
+0419 : 1423;
+041A : 1424;
+041B : 1422;
+041C : 1422;
+041D : 1422;
+041E : 1421;
+041F : 1421;
+0420 : 1420;
+0421 : 1420;
+0422 : 1419;
+0423 : 1420;
+0424 : 1420;
+0425 : 1420;
+0426 : 1419;
+0427 : 1418;
+0428 : 1418;
+0429 : 1418;
+042A : 1418;
+042B : 1417;
+042C : 1416;
+042D : 1417;
+042E : 1417;
+042F : 1417;
+0430 : 1416;
+0431 : 1415;
+0432 : 1416;
+0433 : 1416;
+0434 : 1416;
+0435 : 1415;
+0436 : 1413;
+0437 : 1414;
+0438 : 1414;
+0439 : 1414;
+043A : 1414;
+043B : 1413;
+043C : 1413;
+043D : 1414;
+043E : 1413;
+043F : 1411;
+0440 : 1411;
+0441 : 1411;
+0442 : 1411;
+0443 : 1412;
+0444 : 1410;
+0445 : 1409;
+0446 : 1409;
+0447 : 1409;
+0448 : 1410;
+0449 : 1409;
+044A : 1408;
+044B : 1408;
+044C : 1408;
+044D : 1408;
+044E : 1407;
+044F : 1406;
+0450 : 1406;
+0451 : 1407;
+0452 : 1407;
+0453 : 1406;
+0454 : 1405;
+0455 : 1406;
+0456 : 1406;
+0457 : 1405;
+0458 : 1405;
+0459 : 1403;
+045A : 1404;
+045B : 1403;
+045C : 1403;
+045D : 1403;
+045E : 1402;
+045F : 1402;
+0460 : 1403;
+0461 : 1403;
+0462 : 1401;
+0463 : 1400;
+0464 : 1401;
+0465 : 1401;
+0466 : 1401;
+0467 : 1400;
+0468 : 1398;
+0469 : 1399;
+046A : 1400;
+046B : 1400;
+046C : 1398;
+046D : 1398;
+046E : 1398;
+046F : 1398;
+0470 : 1398;
+0471 : 1398;
+0472 : 1396;
+0473 : 1396;
+0474 : 1397;
+0475 : 1398;
+0476 : 1395;
+0477 : 1394;
+0478 : 1395;
+0479 : 1394;
+047A : 1396;
+047B : 1395;
+047C : 1394;
+047D : 1393;
+047E : 1394;
+047F : 1395;
+0480 : 1393;
+0481 : 1392;
+0482 : 1392;
+0483 : 1392;
+0484 : 1393;
+0485 : 1393;
+0486 : 1392;
+0487 : 1390;
+0488 : 1391;
+0489 : 1391;
+048A : 1391;
+048B : 1389;
+048C : 1389;
+048D : 1390;
+048E : 1390;
+048F : 1389;
+0490 : 1388;
+0491 : 1387;
+0492 : 1389;
+0493 : 1389;
+0494 : 1389;
+0495 : 1387;
+0496 : 1386;
+0497 : 1387;
+0498 : 1387;
+0499 : 1387;
+049A : 1386;
+049B : 1385;
+049C : 1387;
+049D : 1387;
+049E : 1386;
+049F : 1384;
+04A0 : 1384;
+04A1 : 1385;
+04A2 : 1385;
+04A3 : 1385;
+04A4 : 1383;
+04A5 : 1383;
+04A6 : 1383;
+04A7 : 1384;
+04A8 : 1383;
+04A9 : 1381;
+04AA : 1380;
+04AB : 1381;
+04AC : 1382;
+04AD : 1381;
+04AE : 1380;
+04AF : 1381;
+04B0 : 1381;
+04B1 : 1381;
+04B2 : 1380;
+04B3 : 1378;
+04B4 : 1379;
+04B5 : 1379;
+04B6 : 1379;
+04B7 : 1379;
+04B8 : 1379;
+04B9 : 1378;
+04BA : 1378;
+04BB : 1377;
+04BC : 1377;
+04BD : 1377;
+04BE : 1376;
+04BF : 1376;
+04C0 : 1377;
+04C1 : 1377;
+04C2 : 1375;
+04C3 : 1375;
+04C4 : 1375;
+04C5 : 1376;
+04C6 : 1376;
+04C7 : 1375;
+04C8 : 1374;
+04C9 : 1374;
+04CA : 1374;
+04CB : 1373;
+04CC : 1372;
+04CD : 1372;
+04CE : 1372;
+04CF : 1373;
+04D0 : 1373;
+04D1 : 1371;
+04D2 : 1371;
+04D3 : 1372;
+04D4 : 1371;
+04D5 : 1372;
+04D6 : 1370;
+04D7 : 1370;
+04D8 : 1371;
+04D9 : 1371;
+04DA : 1370;
+04DB : 1369;
+04DC : 1368;
+04DD : 1368;
+04DE : 1369;
+04DF : 1368;
+04E0 : 1369;
+04E1 : 1367;
+04E2 : 1367;
+04E3 : 1368;
+04E4 : 1367;
+04E5 : 1366;
+04E6 : 1366;
+04E7 : 1365;
+04E8 : 1367;
+04E9 : 1366;
+04EA : 1365;
+04EB : 1365;
+04EC : 1365;
+04ED : 1366;
+04EE : 1365;
+04EF : 1365;
+04F0 : 1363;
+04F1 : 1363;
+04F2 : 1364;
+04F3 : 1363;
+04F4 : 1363;
+04F5 : 1361;
+04F6 : 1362;
+04F7 : 1362;
+04F8 : 1362;
+04F9 : 1362;
+04FA : 1360;
+04FB : 1361;
+04FC : 1361;
+04FD : 1361;
+04FE : 1359;
+04FF : 1359;
+0500 : 1359;
+0501 : 1360;
+0502 : 1360;
+0503 : 1358;
+0504 : 1358;
+0505 : 1359;
+0506 : 1359;
+0507 : 1358;
+0508 : 1357;
+0509 : 1357;
+050A : 1358;
+050B : 1357;
+050C : 1358;
+050D : 1357;
+050E : 1355;
+050F : 1356;
+0510 : 1355;
+0511 : 1357;
+0512 : 1356;
+0513 : 1355;
+0514 : 1355;
+0515 : 1355;
+0516 : 1355;
+0517 : 1354;
+0518 : 1352;
+0519 : 1353;
+051A : 1354;
+051B : 1354;
+051C : 1353;
+051D : 1352;
+051E : 1352;
+051F : 1353;
+0520 : 1353;
+0521 : 1351;
+0522 : 1351;
+0523 : 1351;
+0524 : 1351;
+0525 : 1351;
+0526 : 1351;
+0527 : 1349;
+0528 : 1349;
+0529 : 1349;
+052A : 1349;
+052B : 1349;
+052C : 1348;
+052D : 1348;
+052E : 1349;
+052F : 1349;
+0530 : 1348;
+0531 : 1346;
+0532 : 1346;
+0533 : 1347;
+0534 : 1346;
+0535 : 1346;
+0536 : 1346;
+0537 : 1345;
+0538 : 1345;
+0539 : 1346;
+053A : 1345;
+053B : 1344;
+053C : 1343;
+053D : 1344;
+053E : 1344;
+053F : 1343;
+0540 : 1343;
+0541 : 1342;
+0542 : 1342;
+0543 : 1343;
+0544 : 1342;
+0545 : 1341;
+0546 : 1342;
+0547 : 1342;
+0548 : 1341;
+0549 : 1341;
+054A : 1341;
+054B : 1341;
+054C : 1340;
+054D : 1341;
+054E : 1341;
+054F : 1339;
+0550 : 1339;
+0551 : 1339;
+0552 : 1340;
+0553 : 1339;
+0554 : 1338;
+0555 : 1337;
+0556 : 1338;
+0557 : 1339;
+0558 : 1338;
+0559 : 1337;
+055A : 1337;
+055B : 1337;
+055C : 1338;
+055D : 1337;
+055E : 1336;
+055F : 1335;
+0560 : 1337;
+0561 : 1336;
+0562 : 1336;
+0563 : 1335;
+0564 : 1334;
+0565 : 1334;
+0566 : 1335;
+0567 : 1335;
+0568 : 1334;
+0569 : 1334;
+056A : 1333;
+056B : 1334;
+056C : 1334;
+056D : 1333;
+056E : 1332;
+056F : 1332;
+0570 : 1332;
+0571 : 1333;
+0572 : 1332;
+0573 : 1331;
+0574 : 1331;
+0575 : 1332;
+0576 : 1332;
+0577 : 1331;
+0578 : 1330;
+0579 : 1331;
+057A : 1331;
+057B : 1330;
+057C : 1329;
+057D : 1328;
+057E : 1328;
+057F : 1329;
+0580 : 1330;
+0581 : 1329;
+0582 : 1328;
+0583 : 1327;
+0584 : 1328;
+0585 : 1328;
+0586 : 1328;
+0587 : 1328;
+0588 : 1327;
+0589 : 1328;
+058A : 1327;
+058B : 1326;
+058C : 1326;
+058D : 1326;
+058E : 1327;
+058F : 1326;
+0590 : 1325;
+0591 : 1325;
+0592 : 1324;
+0593 : 1325;
+0594 : 1324;
+0595 : 1324;
+0596 : 1323;
+0597 : 1322;
+0598 : 1323;
+0599 : 1323;
+059A : 1322;
+059B : 1321;
+059C : 1322;
+059D : 1322;
+059E : 1323;
+059F : 1321;
+05A0 : 1322;
+05A1 : 1320;
+05A2 : 1321;
+05A3 : 1320;
+05A4 : 1322;
+05A5 : 1320;
+05A6 : 1320;
+05A7 : 1320;
+05A8 : 1321;
+05A9 : 1319;
+05AA : 1319;
+05AB : 1318;
+05AC : 1319;
+05AD : 1320;
+05AE : 1319;
+05AF : 1318;
+05B0 : 1318;
+05B1 : 1318;
+05B2 : 1318;
+05B3 : 1317;
+05B4 : 1317;
+05B5 : 1318;
+05B6 : 1317;
+05B7 : 1317;
+05B8 : 1318;
+05B9 : 1316;
+05BA : 1316;
+05BB : 1317;
+05BC : 1317;
+05BD : 1316;
+05BE : 1315;
+05BF : 1314;
+05C0 : 1315;
+05C1 : 1315;
+05C2 : 1315;
+05C3 : 1314;
+05C4 : 1313;
+05C5 : 1313;
+05C6 : 1315;
+05C7 : 1314;
+05C8 : 1314;
+05C9 : 1313;
+05CA : 1312;
+05CB : 1313;
+05CC : 1313;
+05CD : 1312;
+05CE : 1313;
+05CF : 1312;
+05D0 : 1313;
+05D1 : 1312;
+05D2 : 1312;
+05D3 : 1311;
+05D4 : 1312;
+05D5 : 1312;
+05D6 : 1312;
+05D7 : 1311;
+05D8 : 1310;
+05D9 : 1310;
+05DA : 1311;
+05DB : 1310;
+05DC : 1309;
+05DD : 1309;
+05DE : 1309;
+05DF : 1310;
+05E0 : 1310;
+05E1 : 1309;
+05E2 : 1308;
+05E3 : 1308;
+05E4 : 1308;
+05E5 : 1308;
+05E6 : 1307;
+05E7 : 1306;
+05E8 : 1307;
+05E9 : 1307;
+05EA : 1308;
+05EB : 1306;
+05EC : 1306;
+05ED : 1306;
+05EE : 1307;
+05EF : 1306;
+05F0 : 1305;
+05F1 : 1305;
+05F2 : 1304;
+05F3 : 1305;
+05F4 : 1305;
+05F5 : 1305;
+05F6 : 1304;
+05F7 : 1305;
+05F8 : 1304;
+05F9 : 1304;
+05FA : 1304;
+05FB : 1302;
+05FC : 1304;
+05FD : 1304;
+05FE : 1303;
+05FF : 1302;
+0600 : 1302;
+0601 : 1302;
+0602 : 1302;
+0603 : 1303;
+0604 : 1303;
+0605 : 1302;
+0606 : 1302;
+0607 : 1302;
+0608 : 1302;
+0609 : 1301;
+060A : 1301;
+060B : 1301;
+060C : 1301;
+060D : 1301;
+060E : 1300;
+060F : 1300;
+0610 : 1300;
+0611 : 1300;
+0612 : 1300;
+0613 : 1300;
+0614 : 1297;
+0615 : 1299;
+0616 : 1299;
+0617 : 1299;
+0618 : 1299;
+0619 : 1298;
+061A : 1298;
+061B : 1298;
+061C : 1299;
+061D : 1298;
+061E : 1297;
+061F : 1297;
+0620 : 1296;
+0621 : 1298;
+0622 : 1297;
+0623 : 1296;
+0624 : 1295;
+0625 : 1297;
+0626 : 1296;
+0627 : 1296;
+0628 : 1294;
+0629 : 1296;
+062A : 1295;
+062B : 1295;
+062C : 1294;
+062D : 1294;
+062E : 1294;
+062F : 1294;
+0630 : 1294;
+0631 : 1294;
+0632 : 1293;
+0633 : 1293;
+0634 : 1292;
+0635 : 1294;
+0636 : 1294;
+0637 : 1291;
+0638 : 1292;
+0639 : 1293;
+063A : 1293;
+063B : 1292;
+063C : 1291;
+063D : 1291;
+063E : 1292;
+063F : 1292;
+0640 : 1291;
+0641 : 1290;
+0642 : 1290;
+0643 : 1290;
+0644 : 1291;
+0645 : 1291;
+0646 : 1290;
+0647 : 1290;
+0648 : 1290;
+0649 : 1290;
+064A : 1290;
+064B : 1289;
+064C : 1287;
+064D : 1289;
+064E : 1289;
+064F : 1289;
+0650 : 1288;
+0651 : 1288;
+0652 : 1287;
+0653 : 1288;
+0654 : 1289;
+0655 : 1288;
+0656 : 1287;
+0657 : 1286;
+0658 : 1287;
+0659 : 1287;
+065A : 1286;
+065B : 1286;
+065C : 1286;
+065D : 1287;
+065E : 1286;
+065F : 1286;
+0660 : 1284;
+0661 : 1285;
+0662 : 1285;
+0663 : 1287;
+0664 : 1284;
+0665 : 1284;
+0666 : 1285;
+0667 : 1285;
+0668 : 1285;
+0669 : 1283;
+066A : 1283;
+066B : 1283;
+066C : 1284;
+066D : 1284;
+066E : 1282;
+066F : 1282;
+0670 : 1281;
+0671 : 1283;
+0672 : 1283;
+0673 : 1282;
+0674 : 1282;
+0675 : 1281;
+0676 : 1282;
+0677 : 1282;
+0678 : 1281;
+0679 : 1281;
+067A : 1281;
+067B : 1280;
+067C : 1282;
+067D : 1281;
+067E : 1281;
+067F : 1281;
+0680 : 1281;
+0681 : 1280;
+0682 : 1280;
+0683 : 1280;
+0684 : 1280;
+0685 : 1279;
+0686 : 1280;
+0687 : 1278;
+0688 : 1278;
+0689 : 1280;
+068A : 1279;
+068B : 1279;
+068C : 1279;
+068D : 1278;
+068E : 1278;
+068F : 1278;
+0690 : 1278;
+0691 : 1278;
+0692 : 1277;
+0693 : 1277;
+0694 : 1277;
+0695 : 1277;
+0696 : 1277;
+0697 : 1276;
+0698 : 1275;
+0699 : 1276;
+069A : 1276;
+069B : 1276;
+069C : 1275;
+069D : 1275;
+069E : 1275;
+069F : 1276;
+06A0 : 1275;
+06A1 : 1275;
+06A2 : 1275;
+06A3 : 1276;
+06A4 : 1276;
+06A5 : 1275;
+06A6 : 1273;
+06A7 : 1274;
+06A8 : 1275;
+06A9 : 1275;
+06AA : 1274;
+06AB : 1273;
+06AC : 1272;
+06AD : 1274;
+06AE : 1273;
+06AF : 1272;
+06B0 : 1272;
+06B1 : 1271;
+06B2 : 1273;
+06B3 : 1273;
+06B4 : 1272;
+06B5 : 1272;
+06B6 : 1272;
+06B7 : 1272;
+06B8 : 1272;
+06B9 : 1271;
+06BA : 1271;
+06BB : 1271;
+06BC : 1270;
+06BD : 1271;
+06BE : 1271;
+06BF : 1271;
+06C0 : 1269;
+06C1 : 1270;
+06C2 : 1270;
+06C3 : 1269;
+06C4 : 1268;
+06C5 : 1268;
+06C6 : 1269;
+06C7 : 1270;
+06C8 : 1269;
+06C9 : 1268;
+06CA : 1267;
+06CB : 1268;
+06CC : 1268;
+06CD : 1269;
+06CE : 1268;
+06CF : 1267;
+06D0 : 1268;
+06D1 : 1267;
+06D2 : 1267;
+06D3 : 1267;
+06D4 : 1267;
+06D5 : 1267;
+06D6 : 1268;
+06D7 : 1268;
+06D8 : 1266;
+06D9 : 1266;
+06DA : 1266;
+06DB : 1266;
+06DC : 1266;
+06DD : 1266;
+06DE : 1266;
+06DF : 1266;
+06E0 : 1266;
+06E1 : 1266;
+06E2 : 1265;
+06E3 : 1263;
+06E4 : 1265;
+06E5 : 1266;
+06E6 : 1265;
+06E7 : 1265;
+06E8 : 1264;
+06E9 : 1264;
+06EA : 1265;
+06EB : 1264;
+06EC : 1263;
+06ED : 1263;
+06EE : 1263;
+06EF : 1263;
+06F0 : 1263;
+06F1 : 1262;
+06F2 : 1262;
+06F3 : 1263;
+06F4 : 1263;
+06F5 : 1263;
+06F6 : 1261;
+06F7 : 1261;
+06F8 : 1261;
+06F9 : 1261;
+06FA : 1261;
+06FB : 1262;
+06FC : 1260;
+06FD : 1260;
+06FE : 1260;
+06FF : 1261;
+0700 : 1260;
+0701 : 1260;
+0702 : 1259;
+0703 : 1261;
+0704 : 1261;
+0705 : 1259;
+0706 : 1258;
+0707 : 1259;
+0708 : 1259;
+0709 : 1260;
+070A : 1257;
+070B : 1257;
+070C : 1258;
+070D : 1258;
+070E : 1258;
+070F : 1258;
+0710 : 1257;
+0711 : 1257;
+0712 : 1259;
+0713 : 1258;
+0714 : 1257;
+0715 : 1257;
+0716 : 1257;
+0717 : 1258;
+0718 : 1257;
+0719 : 1256;
+071A : 1256;
+071B : 1255;
+071C : 1256;
+071D : 1257;
+071E : 1255;
+071F : 1255;
+0720 : 1255;
+0721 : 1256;
+0722 : 1256;
+0723 : 1256;
+0724 : 1254;
+0725 : 1254;
+0726 : 1256;
+0727 : 1255;
+0728 : 1254;
+0729 : 1253;
+072A : 1254;
+072B : 1254;
+072C : 1255;
+072D : 1253;
+072E : 1253;
+072F : 1253;
+0730 : 1253;
+0731 : 1254;
+0732 : 1253;
+0733 : 1252;
+0734 : 1251;
+0735 : 1252;
+0736 : 1253;
+0737 : 1252;
+0738 : 1251;
+0739 : 1251;
+073A : 1252;
+073B : 1253;
+073C : 1252;
+073D : 1251;
+073E : 1250;
+073F : 1251;
+0740 : 1251;
+0741 : 1251;
+0742 : 1250;
+0743 : 1249;
+0744 : 1251;
+0745 : 1252;
+0746 : 1250;
+0747 : 1249;
+0748 : 1250;
+0749 : 1250;
+074A : 1250;
+074B : 1249;
+074C : 1249;
+074D : 1248;
+074E : 1249;
+074F : 1249;
+0750 : 1249;
+0751 : 1248;
+0752 : 1248;
+0753 : 1248;
+0754 : 1248;
+0755 : 1248;
+0756 : 1247;
+0757 : 1247;
+0758 : 1247;
+0759 : 1248;
+075A : 1248;
+075B : 1247;
+075C : 1247;
+075D : 1247;
+075E : 1246;
+075F : 1247;
+0760 : 1246;
+0761 : 1246;
+0762 : 1246;
+0763 : 1246;
+0764 : 1247;
+0765 : 1246;
+0766 : 1245;
+0767 : 1245;
+0768 : 1246;
+0769 : 1246;
+076A : 1246;
+076B : 1244;
+076C : 1245;
+076D : 1245;
+076E : 1246;
+076F : 1245;
+0770 : 1244;
+0771 : 1244;
+0772 : 1244;
+0773 : 1245;
+0774 : 1244;
+0775 : 1243;
+0776 : 1243;
+0777 : 1244;
+0778 : 1244;
+0779 : 1243;
+077A : 1242;
+077B : 1243;
+077C : 1243;
+077D : 1243;
+077E : 1242;
+077F : 1242;
+0780 : 1243;
+0781 : 1243;
+0782 : 1243;
+0783 : 1242;
+0784 : 1241;
+0785 : 1242;
+0786 : 1242;
+0787 : 1241;
+0788 : 1241;
+0789 : 1241;
+078A : 1241;
+078B : 1241;
+078C : 1241;
+078D : 1241;
+078E : 1240;
+078F : 1240;
+0790 : 1241;
+0791 : 1240;
+0792 : 1241;
+0793 : 1239;
+0794 : 1239;
+0795 : 1240;
+0796 : 1240;
+0797 : 1239;
+0798 : 1239;
+0799 : 1239;
+079A : 1238;
+079B : 1239;
+079C : 1238;
+079D : 1238;
+079E : 1239;
+079F : 1238;
+07A0 : 1239;
+07A1 : 1237;
+07A2 : 1236;
+07A3 : 1237;
+07A4 : 1237;
+07A5 : 1238;
+07A6 : 1238;
+07A7 : 1236;
+07A8 : 1237;
+07A9 : 1237;
+07AA : 1237;
+07AB : 1237;
+07AC : 1235;
+07AD : 1236;
+07AE : 1237;
+07AF : 1236;
+07B0 : 1236;
+07B1 : 1236;
+07B2 : 1235;
+07B3 : 1236;
+07B4 : 1236;
+07B5 : 1236;
+07B6 : 1234;
+07B7 : 1235;
+07B8 : 1235;
+07B9 : 1235;
+07BA : 1235;
+07BB : 1235;
+07BC : 1234;
+07BD : 1234;
+07BE : 1235;
+07BF : 1234;
+07C0 : 1234;
+07C1 : 1234;
+07C2 : 1233;
+07C3 : 1235;
+07C4 : 1234;
+07C5 : 1234;
+07C6 : 1233;
+07C7 : 1234;
+07C8 : 1234;
+07C9 : 1234;
+07CA : 1232;
+07CB : 1232;
+07CC : 1233;
+07CD : 1233;
+07CE : 1232;
+07CF : 1231;
+07D0 : 1231;
+07D1 : 1232;
+07D2 : 1232;
+07D3 : 1231;
+07D4 : 1231;
+07D5 : 1231;
+07D6 : 1231;
+07D7 : 1231;
+07D8 : 1231;
+07D9 : 1230;
+07DA : 1230;
+07DB : 1230;
+07DC : 1230;
+07DD : 1230;
+07DE : 1229;
+07DF : 1229;
+07E0 : 1229;
+07E1 : 1231;
+07E2 : 1231;
+07E3 : 1229;
+07E4 : 1227;
+07E5 : 1229;
+07E6 : 1228;
+07E7 : 1229;
+07E8 : 1229;
+07E9 : 1229;
+07EA : 1229;
+07EB : 1229;
+07EC : 1228;
+07ED : 1227;
+07EE : 1227;
+07EF : 1228;
+07F0 : 1228;
+07F1 : 1228;
+07F2 : 1227;
+07F3 : 1227;
+07F4 : 1227;
+07F5 : 1228;
+07F6 : 1228;
+07F7 : 1227;
+07F8 : 1227;
+07F9 : 1227;
+07FA : 1228;
+07FB : 1227;
+07FC : 1226;
+07FD : 1226;
+07FE : 1226;
+07FF : 1227;
+0800 : 1227;
+0801 : 1225;
+0802 : 1226;
+0803 : 1226;
+0804 : 1225;
+0805 : 1226;
+0806 : 1226;
+0807 : 1225;
+0808 : 1225;
+0809 : 1225;
+080A : 1226;
+080B : 1225;
+080C : 1224;
+080D : 1225;
+080E : 1225;
+080F : 1225;
+0810 : 1224;
+0811 : 1224;
+0812 : 1225;
+0813 : 1224;
+0814 : 1224;
+0815 : 1223;
+0816 : 1224;
+0817 : 1223;
+0818 : 1224;
+0819 : 1224;
+081A : 1223;
+081B : 1222;
+081C : 1222;
+081D : 1223;
+081E : 1223;
+081F : 1222;
+0820 : 1222;
+0821 : 1222;
+0822 : 1223;
+0823 : 1223;
+0824 : 1222;
+0825 : 1221;
+0826 : 1222;
+0827 : 1223;
+0828 : 1222;
+0829 : 1222;
+082A : 1221;
+082B : 1221;
+082C : 1220;
+082D : 1221;
+082E : 1221;
+082F : 1220;
+0830 : 1220;
+0831 : 1221;
+0832 : 1222;
+0833 : 1220;
+0834 : 1220;
+0835 : 1220;
+0836 : 1220;
+0837 : 1221;
+0838 : 1221;
+0839 : 1220;
+083A : 1219;
+083B : 1219;
+083C : 1220;
+083D : 1219;
+083E : 1219;
+083F : 1218;
+0840 : 1219;
+0841 : 1221;
+0842 : 1220;
+0843 : 1218;
+0844 : 1218;
+0845 : 1219;
+0846 : 1219;
+0847 : 1219;
+0848 : 1217;
+0849 : 1217;
+084A : 1217;
+084B : 1218;
+084C : 1218;
+084D : 1217;
+084E : 1217;
+084F : 1219;
+0850 : 1218;
+0851 : 1218;
+0852 : 1217;
+0853 : 1217;
+0854 : 1217;
+0855 : 1218;
+0856 : 1216;
+0857 : 1216;
+0858 : 1215;
+0859 : 1216;
+085A : 1217;
+085B : 1217;
+085C : 1216;
+085D : 1215;
+085E : 1215;
+085F : 1216;
+0860 : 1216;
+0861 : 1215;
+0862 : 1215;
+0863 : 1215;
+0864 : 1216;
+0865 : 1216;
+0866 : 1215;
+0867 : 1214;
+0868 : 1216;
+0869 : 1216;
+086A : 1215;
+086B : 1215;
+086C : 1215;
+086D : 1215;
+086E : 1215;
+086F : 1215;
+0870 : 1213;
+0871 : 1214;
+0872 : 1214;
+0873 : 1214;
+0874 : 1215;
+0875 : 1214;
+0876 : 1213;
+0877 : 1213;
+0878 : 1214;
+0879 : 1214;
+087A : 1214;
+087B : 1212;
+087C : 1212;
+087D : 1215;
+087E : 1214;
+087F : 1212;
+0880 : 1212;
+0881 : 1212;
+0882 : 1212;
+0883 : 1213;
+0884 : 1212;
+0885 : 1211;
+0886 : 1211;
+0887 : 1212;
+0888 : 1212;
+0889 : 1211;
+088A : 1211;
+088B : 1211;
+088C : 1211;
+088D : 1211;
+088E : 1211;
+088F : 1210;
+0890 : 1211;
+0891 : 1212;
+0892 : 1212;
+0893 : 1211;
+0894 : 1210;
+0895 : 1210;
+0896 : 1210;
+0897 : 1211;
+0898 : 1210;
+0899 : 1209;
+089A : 1209;
+089B : 1210;
+089C : 1211;
+089D : 1210;
+089E : 1208;
+089F : 1209;
+08A0 : 1210;
+08A1 : 1211;
+08A2 : 1210;
+08A3 : 1208;
+08A4 : 1208;
+08A5 : 1208;
+08A6 : 1209;
+08A7 : 1207;
+08A8 : 1207;
+08A9 : 1208;
+08AA : 1208;
+08AB : 1209;
+08AC : 1209;
+08AD : 1208;
+08AE : 1207;
+08AF : 1208;
+08B0 : 1209;
+08B1 : 1207;
+08B2 : 1206;
+08B3 : 1208;
+08B4 : 1208;
+08B5 : 1208;
+08B6 : 1208;
+08B7 : 1207;
+08B8 : 1207;
+08B9 : 1207;
+08BA : 1208;
+08BB : 1207;
+08BC : 1206;
+08BD : 1206;
+08BE : 1206;
+08BF : 1207;
+08C0 : 1207;
+08C1 : 1205;
+08C2 : 1205;
+08C3 : 1205;
+08C4 : 1206;
+08C5 : 1205;
+08C6 : 1205;
+08C7 : 1205;
+08C8 : 1206;
+08C9 : 1206;
+08CA : 1207;
+08CB : 1205;
+08CC : 1205;
+08CD : 1205;
+08CE : 1206;
+08CF : 1205;
+08D0 : 1205;
+08D1 : 1203;
+08D2 : 1205;
+08D3 : 1206;
+08D4 : 1204;
+08D5 : 1204;
+08D6 : 1204;
+08D7 : 1204;
+08D8 : 1205;
+08D9 : 1205;
+08DA : 1203;
+08DB : 1203;
+08DC : 1203;
+08DD : 1204;
+08DE : 1204;
+08DF : 1203;
+08E0 : 1202;
+08E1 : 1203;
+08E2 : 1205;
+08E3 : 1204;
+08E4 : 1203;
+08E5 : 1202;
+08E6 : 1203;
+08E7 : 1203;
+08E8 : 1202;
+08E9 : 1201;
+08EA : 1201;
+08EB : 1202;
+08EC : 1203;
+08ED : 1203;
+08EE : 1202;
+08EF : 1201;
+08F0 : 1203;
+08F1 : 1203;
+08F2 : 1201;
+08F3 : 1201;
+08F4 : 1201;
+08F5 : 1201;
+08F6 : 1202;
+08F7 : 1202;
+08F8 : 1201;
+08F9 : 1201;
+08FA : 1200;
+08FB : 1202;
+08FC : 1202;
+08FD : 1200;
+08FE : 1200;
+08FF : 1200;
+0900 : 1200;
+0901 : 1201;
+0902 : 1200;
+0903 : 1199;
+0904 : 1200;
+0905 : 1200;
+0906 : 1200;
+0907 : 1200;
+0908 : 1199;
+0909 : 1200;
+090A : 1200;
+090B : 1200;
+090C : 1199;
+090D : 1199;
+090E : 1199;
+090F : 1200;
+0910 : 1200;
+0911 : 1199;
+0912 : 1198;
+0913 : 1197;
+0914 : 1198;
+0915 : 1200;
+0916 : 1198;
+0917 : 1198;
+0918 : 1199;
+0919 : 1198;
+091A : 1198;
+091B : 1198;
+091C : 1197;
+091D : 1197;
+091E : 1198;
+091F : 1198;
+0920 : 1197;
+0921 : 1196;
+0922 : 1196;
+0923 : 1197;
+0924 : 1197;
+0925 : 1196;
+0926 : 1196;
+0927 : 1196;
+0928 : 1197;
+0929 : 1197;
+092A : 1196;
+092B : 1196;
+092C : 1196;
+092D : 1197;
+092E : 1197;
+092F : 1196;
+0930 : 1195;
+0931 : 1196;
+0932 : 1197;
+0933 : 1197;
+0934 : 1196;
+0935 : 1195;
+0936 : 1194;
+0937 : 1197;
+0938 : 1196;
+0939 : 1195;
+093A : 1194;
+093B : 1195;
+093C : 1195;
+093D : 1195;
+093E : 1195;
+093F : 1193;
+0940 : 1194;
+0941 : 1195;
+0942 : 1196;
+0943 : 1195;
+0944 : 1195;
+0945 : 1194;
+0946 : 1194;
+0947 : 1195;
+0948 : 1194;
+0949 : 1194;
+094A : 1194;
+094B : 1194;
+094C : 1194;
+094D : 1194;
+094E : 1194;
+094F : 1192;
+0950 : 1193;
+0951 : 1194;
+0952 : 1194;
+0953 : 1192;
+0954 : 1193;
+0955 : 1194;
+0956 : 1193;
+0957 : 1193;
+0958 : 1192;
+0959 : 1192;
+095A : 1192;
+095B : 1194;
+095C : 1193;
+095D : 1192;
+095E : 1192;
+095F : 1192;
+0960 : 1192;
+0961 : 1192;
+0962 : 1192;
+0963 : 1191;
+0964 : 1192;
+0965 : 1193;
+0966 : 1192;
+0967 : 1191;
+0968 : 1190;
+0969 : 1191;
+096A : 1191;
+096B : 1192;
+096C : 1191;
+096D : 1190;
+096E : 1190;
+096F : 1191;
+0970 : 1191;
+0971 : 1190;
+0972 : 1189;
+0973 : 1191;
+0974 : 1191;
+0975 : 1190;
+0976 : 1190;
+0977 : 1190;
+0978 : 1189;
+0979 : 1190;
+097A : 1189;
+097B : 1189;
+097C : 1189;
+097D : 1190;
+097E : 1190;
+097F : 1189;
+0980 : 1189;
+0981 : 1188;
+0982 : 1189;
+0983 : 1190;
+0984 : 1189;
+0985 : 1189;
+0986 : 1188;
+0987 : 1189;
+0988 : 1189;
+0989 : 1188;
+098A : 1188;
+098B : 1189;
+098C : 1188;
+098D : 1189;
+098E : 1188;
+098F : 1188;
+0990 : 1187;
+0991 : 1188;
+0992 : 1188;
+0993 : 1188;
+0994 : 1188;
+0995 : 1187;
+0996 : 1188;
+0997 : 1188;
+0998 : 1188;
+0999 : 1187;
+099A : 1187;
+099B : 1187;
+099C : 1187;
+099D : 1187;
+099E : 1187;
+099F : 1186;
+09A0 : 1186;
+09A1 : 1188;
+09A2 : 1188;
+09A3 : 1186;
+09A4 : 1186;
+09A5 : 1186;
+09A6 : 1187;
+09A7 : 1187;
+09A8 : 1187;
+09A9 : 1185;
+09AA : 1185;
+09AB : 1186;
+09AC : 1186;
+09AD : 1186;
+09AE : 1185;
+09AF : 1185;
+09B0 : 1186;
+09B1 : 1186;
+09B2 : 1186;
+09B3 : 1186;
+09B4 : 1185;
+09B5 : 1186;
+09B6 : 1186;
+09B7 : 1185;
+09B8 : 1184;
+09B9 : 1185;
+09BA : 1185;
+09BB : 1186;
+09BC : 1185;
+09BD : 1185;
+09BE : 1185;
+09BF : 1185;
+09C0 : 1185;
+09C1 : 1184;
+09C2 : 1184;
+09C3 : 1184;
+09C4 : 1184;
+09C5 : 1185;
+09C6 : 1184;
+09C7 : 1184;
+09C8 : 1183;
+09C9 : 1184;
+09CA : 1185;
+09CB : 1184;
+09CC : 1183;
+09CD : 1184;
+09CE : 1183;
+09CF : 1184;
+09D0 : 1183;
+09D1 : 1183;
+09D2 : 1183;
+09D3 : 1183;
+09D4 : 1183;
+09D5 : 1183;
+09D6 : 1182;
+09D7 : 1182;
+09D8 : 1182;
+09D9 : 1183;
+09DA : 1183;
+09DB : 1182;
+09DC : 1182;
+09DD : 1182;
+09DE : 1183;
+09DF : 1182;
+09E0 : 1181;
+09E1 : 1181;
+09E2 : 1182;
+09E3 : 1183;
+09E4 : 1182;
+09E5 : 1181;
+09E6 : 1181;
+09E7 : 1181;
+09E8 : 1182;
+09E9 : 1182;
+09EA : 1180;
+09EB : 1181;
+09EC : 1182;
+09ED : 1181;
+09EE : 1181;
+09EF : 1181;
+09F0 : 1181;
+09F1 : 1181;
+09F2 : 1181;
+09F3 : 1181;
+09F4 : 1181;
+09F5 : 1180;
+09F6 : 1181;
+09F7 : 1182;
+09F8 : 1181;
+09F9 : 1180;
+09FA : 1180;
+09FB : 1181;
+09FC : 1181;
+09FD : 1182;
+09FE : 1179;
+09FF : 1180;
+END;
Index: /trunk/3DEES/test.v
===================================================================
--- /trunk/3DEES/test.v	(revision 177)
+++ /trunk/3DEES/test.v	(revision 177)
@@ -0,0 +1,61 @@
+module test
+	(
+		input	wire			clock,
+		output	wire	[11:0]	data
+	);
+
+	reg 	[11:0]	int_addr;
+
+	always @(posedge clock)
+	begin
+		if (int_addr == 12'd2559)
+		begin
+			int_addr <= 12'd0;
+		end
+		else
+		begin
+			int_addr <= int_addr + 12'd1;
+		end
+
+	end
+
+	altsyncram #(
+		.address_aclr_a("NONE"),
+		.clock_enable_input_a("BYPASS"),
+		.clock_enable_output_a("BYPASS"),
+		.init_file("test.mif"),
+		.intended_device_family("Cyclone III"),
+		.lpm_hint("ENABLE_RUNTIME_MOD=NO"),
+		.lpm_type("altsyncram"),
+		.numwords_a(2560),
+		.operation_mode("ROM"),
+		.outdata_aclr_a("NONE"),
+		.outdata_reg_a("CLOCK0"),
+		.widthad_a(12),
+		.width_a(12),
+		.width_byteena_a(1)) test_rom_unit (
+		.clock0(clock),
+		.address_a(int_addr),
+		.q_a(data),
+		.aclr0(1'b0),
+		.aclr1(1'b0),
+		.address_b(1'b1),
+		.addressstall_a(1'b0),
+		.addressstall_b(1'b0),
+		.byteena_a(1'b1),
+		.byteena_b(1'b1),
+		.clock1(1'b1),
+		.clocken0(1'b1),
+		.clocken1(1'b1),
+		.clocken2(1'b1),
+		.clocken3(1'b1),
+		.data_a({12{1'b1}}),
+		.data_b(1'b1),
+		.eccstatus(),
+		.q_b(),
+		.rden_a(1'b1),
+		.rden_b(1'b1),
+		.wren_a(1'b0),
+		.wren_b(1'b0));
+
+endmodule
Index: /trunk/3DEES/trigger.v
===================================================================
--- /trunk/3DEES/trigger.v	(revision 177)
+++ /trunk/3DEES/trigger.v	(revision 177)
@@ -0,0 +1,32 @@
+module trigger
+	(
+		input	wire			clock, frame, reset,
+		input	wire	[11:0]  cfg_data,
+		input	wire	[11:0]  trg_data,
+		output	wire			trg_flag
+	);
+	
+	reg				trg_flag_reg;
+	reg		[11:0]	cfg_data_reg;
+	reg		[11:0]	trg_data_reg;
+
+	always @(posedge clock)
+	begin
+		if (reset)
+        begin
+			trg_flag_reg <= 1'b0;
+        end
+        else 
+		begin
+			if (frame)
+			begin
+				cfg_data_reg <= cfg_data;
+				trg_data_reg <= trg_data;
+			end
+			trg_flag_reg <= (trg_data_reg >= cfg_data_reg);
+		end
+	end
+	
+	assign trg_flag = trg_flag_reg;
+
+endmodule
Index: /trunk/3DEES/usb_fifo.v
===================================================================
--- /trunk/3DEES/usb_fifo.v	(revision 177)
+++ /trunk/3DEES/usb_fifo.v	(revision 177)
@@ -0,0 +1,121 @@
+module usb_fifo
+	(
+		input	wire			usb_clock,
+		inout	wire	[7:0]	usb_data,
+		input	wire			usb_full, usb_empty,
+		output	wire			usb_wrreq, usb_rdreq, usb_rden, usb_pktend,
+		output	wire			usb_addr,
+		
+		input	wire			clock,
+		input	wire			tx_wrreq, rx_rdreq,
+		input	wire	[7:0]	tx_data,
+		output	wire			tx_full, rx_empty,
+		output	wire	[7:0]	rx_q
+	);
+
+	wire			int_rx_full, int_tx_empty;
+	wire			rx_ready, tx_ready;
+	wire			int_rdreq, int_wrreq, int_pktend;
+	reg				is_rx_addr_ok;
+	reg		[8:0]	byte_counter;
+	reg		[4:0]	idle_counter;
+
+	wire	[7:0]	int_rx_data = usb_data;
+	wire	[7:0]	int_tx_q;
+
+	dcfifo #(
+		.intended_device_family("Cyclone III"),
+		.lpm_numwords(16),
+		.lpm_showahead("ON"),
+		.lpm_type("dcfifo"),
+		.lpm_width(8),
+		.lpm_widthu(4),
+		.rdsync_delaypipe(4),
+		.wrsync_delaypipe(4),
+		.overflow_checking("ON"),
+		.underflow_checking("ON"),
+		.use_eab("OFF"),
+		.write_aclr_synch("OFF")) fifo_tx (
+		.aclr(1'b0),
+		.data(tx_data),
+		.rdclk(usb_clock),
+		.rdreq(int_wrreq),
+		.wrclk(clock),
+		.wrreq(tx_wrreq),
+		.q(int_tx_q),
+		.rdempty(int_tx_empty),
+		.wrfull(tx_full),
+		.rdfull(),
+		.rdusedw(),
+		.wrempty(),
+		.wrusedw());
+
+	dcfifo #(
+		.intended_device_family("Cyclone III"),
+		.lpm_numwords(16),
+		.lpm_showahead("ON"),
+		.lpm_type("dcfifo"),
+		.lpm_width(8),
+		.lpm_widthu(4),
+		.rdsync_delaypipe(4),
+		.wrsync_delaypipe(4),
+		.overflow_checking("ON"),
+		.underflow_checking("ON"),
+		.use_eab("OFF"),
+		.write_aclr_synch("OFF")) fifo_rx (
+		.aclr(1'b0),
+		.data(int_rx_data),
+		.rdclk(clock),
+		.rdreq(rx_rdreq),
+		.wrclk(usb_clock),
+		.wrreq(int_rdreq),
+		.q(rx_q),
+		.rdempty(rx_empty),
+		.wrfull(int_rx_full),
+		.rdfull(),
+		.rdusedw(),
+		.wrempty(),
+		.wrusedw());
+	
+	assign	rx_ready = (~usb_empty) & (~int_rx_full) & (~int_pktend);
+	assign	tx_ready = (~rx_ready) & (~usb_full) & (~int_tx_empty) & (~int_pktend);
+
+	assign	int_rdreq = (rx_ready) & (is_rx_addr_ok);
+	assign	int_wrreq = (tx_ready) & (~is_rx_addr_ok);
+	
+	assign	int_pktend = (&idle_counter);
+
+	always @ (posedge usb_clock)
+	begin
+		// respect 1 clock delay between fifo selection
+		// and data transfer operations
+		is_rx_addr_ok <= rx_ready;
+
+		// assert pktend if buffer contains unsent data
+		// and fifo_tx_unit stays empty for more than 30 clocks
+		if (int_pktend)
+		begin
+			byte_counter <= 9'd0;
+			idle_counter <= 5'd0;
+		end
+		else if (int_wrreq)
+		begin
+			byte_counter <= byte_counter + 9'd1;
+			idle_counter <= 5'd0;
+		end
+		else if ((|byte_counter) & (int_tx_empty) & (~rx_ready))
+		begin
+			byte_counter <= byte_counter;
+			idle_counter <= idle_counter + 5'd1;
+		end
+
+	end
+
+	assign	usb_pktend = int_pktend;
+	assign	usb_rdreq = int_rdreq;
+	assign	usb_wrreq = int_wrreq;
+	assign	usb_rden = int_rdreq;
+	assign	usb_addr = rx_ready;
+	assign	usb_data = int_wrreq ? int_tx_q : 8'bz;
+
+endmodule
Index: /trunk/3DEES/uwt_bior31.v
===================================================================
--- /trunk/3DEES/uwt_bior31.v	(revision 177)
+++ /trunk/3DEES/uwt_bior31.v	(revision 177)
@@ -0,0 +1,111 @@
+module uwt_bior31
+	#(
+		parameter	level	=	1, // transform level
+		parameter	width	=	12 // bit width of the input data (unsigned)
+
+	)
+	(
+		input	wire					clock, frame, reset,
+		input	wire	[width-1:0]		inp_data,
+		output	wire	[widthr-1:0]	out_data,
+		output	wire	[1:0]			out_flag
+	);
+
+	localparam	widthr = width + 3;
+
+	localparam	index1 = 1 << (level - 1);
+	localparam	index2 = 2 << (level - 1);
+	localparam	index3 = 3 << (level - 1);
+	
+	// Tapped delay line
+	reg		[width-1:0]		tap_data_reg [index3:0], tap_data_next [index3:0];
+	
+	wire	[1:0]			int_comp_wire;
+	reg		[1:0]			int_comp_reg, int_comp_next;
+
+	reg		[1:0]			out_flag_reg, out_flag_next;
+	
+	wire	[widthr-1:0]	add_data_wire [1:0];
+	reg		[widthr-1:0]	add_data_reg [1:0], add_data_next [1:0];
+
+	reg		[widthr-1:0]	out_data_reg, out_data_next;
+
+	integer i;
+	
+	assign add_data_wire[0] = tap_data_reg[index3] + {tap_data_reg[index2][width-2:0], 1'b0} + tap_data_reg[index2];
+	assign add_data_wire[1] = {tap_data_reg[index1][width-2:0], 1'b0} + tap_data_reg[index1] + tap_data_reg[0];
+	assign int_comp_wire[0] = (add_data_reg[0] > add_data_reg[1]);
+	assign int_comp_wire[1] = (add_data_reg[0] < add_data_reg[1]);
+
+	always @(posedge clock)
+	begin
+		if (reset)
+		begin
+			add_data_reg[0] <= {(widthr){1'b0}};
+			add_data_reg[1] <= {(widthr){1'b0}};
+			out_data_reg <= {(widthr){1'b0}};
+			int_comp_reg <= 2'd0;
+			out_flag_reg <= 2'd0;
+
+			for(i = 0; i <= index3; i = i + 1)
+			begin
+				tap_data_reg[i] <= {(width){1'b0}};
+			end
+		end
+		else
+		begin
+			add_data_reg[0] <= add_data_next[0];
+			add_data_reg[1] <= add_data_next[1];
+			out_data_reg <= out_data_next;
+			int_comp_reg <= int_comp_next;
+			out_flag_reg <= out_flag_next;
+
+			for(i = 0; i <= index3; i = i + 1)
+			begin
+				tap_data_reg[i] <= tap_data_next[i];
+			end			
+		end
+	end
+	
+	always @*
+	begin
+		add_data_next[0] = add_data_reg[0];
+		add_data_next[1] = add_data_reg[1];
+		out_data_next = out_data_reg;
+		int_comp_next = int_comp_reg;
+		out_flag_next = out_flag_reg;
+
+		for(i = 0; i <= index3; i = i + 1)
+		begin
+			tap_data_next[i] = tap_data_reg[i];
+		end
+
+		if (frame)
+		begin		
+			// Tapped delay line: shift one
+			for(i = 0; i < index3; i = i + 1)
+			begin
+				tap_data_next[i+1] = tap_data_reg[i];
+			end
+			
+			// Input in register 0
+			tap_data_next[0] = inp_data;
+
+			add_data_next[0] = add_data_wire[0];
+			add_data_next[1] = add_data_wire[1];
+			
+			out_data_next = add_data_next[0] + add_data_next[1];
+	
+			int_comp_next = int_comp_wire;
+			out_flag_next[0] = (~int_comp_reg[0]) & (int_comp_wire[0]);
+			out_flag_next[1] = (~int_comp_reg[1]) & (int_comp_wire[1]);
+
+		end
+
+	end
+
+	// output logic
+	assign	out_data = out_data_reg;
+	assign	out_flag = out_flag_reg;
+
+endmodule
