<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://cmbr.phas.ubc.ca/mcewiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=174.6.181.2</id>
	<title>MCEWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://cmbr.phas.ubc.ca/mcewiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=174.6.181.2"/>
	<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php/Special:Contributions/174.6.181.2"/>
	<updated>2026-09-17T00:15:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MCE_script&amp;diff=3871</id>
		<title>MCE script</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MCE_script&amp;diff=3871"/>
		<updated>2010-08-27T20:53:38Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Auto-tuning system&lt;br /&gt;
** [[ Auto-setup (python) ]] - an integrated tool set for dealing with SQUID data.&lt;br /&gt;
** [[ Auto-setup (IDL) ]] - IDL-based auto-tuning code&lt;br /&gt;
** [[ mce_config_template system ]]&lt;br /&gt;
** [[ place_sq1.pro ]] for row selection for the purposes of sq1servo&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Rectangle_Mode_Data&amp;diff=3848</id>
		<title>Rectangle Mode Data</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Rectangle_Mode_Data&amp;diff=3848"/>
		<updated>2010-08-02T17:28:59Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Checking MCE configuration using rect_check.py */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;quot;Rectangle Mode&amp;quot; refers to the sampling of a subset of the full array, typically at high rate.  The data from the Readout Cards is packed into output frames efficiently to minimize overhead.  Rectangle mode is available in MCE firmware starting with RC 5.0.1 and CC 5.0.0.&lt;br /&gt;
&lt;br /&gt;
= Description of capabilities =&lt;br /&gt;
&lt;br /&gt;
Rectangle mode eliminates strain on the acquisition system during fast acquisitions by eliminating read-out overhead.  This means that the 'difficulty' of read-out is a fairly linear function of (sampling frequency) x (number of detectors read out) rather than depending on each. &lt;br /&gt;
&lt;br /&gt;
The hardware limit on readout is roughly 4 MB/s.  Since MCE data are 32-bit words, this permits 1e6 detector-samples to be read out per second.&lt;br /&gt;
&lt;br /&gt;
So the maximum number of detectors that can be sampled at some frequency F is&lt;br /&gt;
  D = (1 MHz) / F&lt;br /&gt;
&lt;br /&gt;
You can't sample at 1 MHz.  (Do your squids settle in 1us?  Didn't think so.)  But you could probably do a detector or two at 250 kHz.&lt;br /&gt;
&lt;br /&gt;
= Firmware =&lt;br /&gt;
&lt;br /&gt;
Rectangle mode requires &amp;quot;version 5&amp;quot; firmware on all cards, and at least RC 5.0.2.  Here are links to the recommended SOFs at time of writing:&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/ac_v05000000_22dec2008.sof&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/bc_v05000000_22dec2008.sof&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/cc_v05000002_16jun2009.sof&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/rc_v05000002_16jun2009.sof&lt;br /&gt;
&lt;br /&gt;
= Script Differences Between v4.x.x and v5.x.x =&lt;br /&gt;
The differences between basic frame setup in v4.x.x and v5.x.x are described here.  The data frame structure has been made more flexible.  A user can read out an arbitrarily rectangular patch of the array.  The patch-size is specified using new commands.&lt;br /&gt;
&lt;br /&gt;
*In v4.x.x: The array patch-size is flexible in terms of the number of rows, and the row start index.&lt;br /&gt;
  wb cc num_rows_reported 41     //power-on default = 41&lt;br /&gt;
  wb rcs readout_row_index 0     //power-on default = 0&lt;br /&gt;
&lt;br /&gt;
*In v5.x.x: The array patch-size is now also flexible in terms of the number of columns, and the column start index.  Note that matching parameters on the Readout Cards and the Clock Card must be consistent.&lt;br /&gt;
  wb cc num_rows_reported 41     //power-on default as above&lt;br /&gt;
  wb cc num_cols_reported 8      //power-on default = 8&lt;br /&gt;
  wb rcs num_rows_reported 41    //power-on default = 41&lt;br /&gt;
  wb rcs num_cols_reported 8     //power-on default = 8&lt;br /&gt;
  wb rcs readout_row_index 0     //power-on default as above&lt;br /&gt;
  wb rcs readout_col_index 0     //power-on default = 0&lt;br /&gt;
&lt;br /&gt;
= Configuration =&lt;br /&gt;
&lt;br /&gt;
The steps for configuring a rectangle mode acquisition are:&lt;br /&gt;
# Set the multiplexing rate using num_rows and row_len&lt;br /&gt;
# If necessary, adjust row_order to mux the channels of interest (you can only read out rows you are multiplexing...).  If you do not intend to re-tune the array with the adjusted num_rows / row_order, you must also change the first entries of rc* adc_offset* to correspond to the desired rows and, for fast SQ2 switching, change row_order on the BAC/BC2.&lt;br /&gt;
# Identify a rectangle of detectors on the readout card to read out by setting the RC parameters&lt;br /&gt;
#* num_rows_reported, num_cols_reported, readout_row_index, readout_col_index&lt;br /&gt;
# Set the size of the readout frame by setting the CC parameters&lt;br /&gt;
#* num_rows_reported, num_cols_reported&lt;br /&gt;
# Set the CC decimation factor 'data_rate' so that the RC rectangles will stack perfectly into the CC readout frame.&lt;br /&gt;
#* e.g. suppose&lt;br /&gt;
#** RC num_rows_reported x num_cols_reported =  1x4 &lt;br /&gt;
#** CC num_rows_reported x num_cols_reported = 33x8&lt;br /&gt;
#* then we set &lt;br /&gt;
#** CC data_rate = (33 x 8) / (1 x 4) = 66&lt;br /&gt;
&lt;br /&gt;
= Readout limitations =&lt;br /&gt;
&lt;br /&gt;
Rectangle mode configuration should respect the following hardware limits:&lt;br /&gt;
* Total data rate must not exceed 4 MB/s&lt;br /&gt;
* Read-out frequency must not exceed 20 kHz&lt;br /&gt;
* The multiplexing frame rate must not be set so fast that the MCE cannot communicate with the readout cards.  This limit is probably in the 100s of kHz.&lt;br /&gt;
&lt;br /&gt;
Other things to remember:&lt;br /&gt;
* num_rows &amp;gt;= 2 is encouraged.&lt;br /&gt;
* you can't sample a detector faster than it is being visited in the multiplexing cycle.&lt;br /&gt;
&lt;br /&gt;
= Checking MCE configuration using rect_check.py =&lt;br /&gt;
&lt;br /&gt;
Use the utility @rect_check.py@ to verify that data will be / were acquired reasonably.&lt;br /&gt;
&lt;br /&gt;
e.g. To check the state of the MCE (requires python MCE bindings), run&lt;br /&gt;
 rect_check.py --mce&lt;br /&gt;
&lt;br /&gt;
To analyze the data framing in a runfile:&lt;br /&gt;
 rect_check.py my_data.run&lt;br /&gt;
&lt;br /&gt;
(Depending on stuff, you might need to invoke rect_check as:&lt;br /&gt;
 $MAS_PYTHON/rect_check.py&lt;br /&gt;
or even&lt;br /&gt;
 python $MAS_PYTHON/rect_check.py&lt;br /&gt;
Sorry.)&lt;br /&gt;
&lt;br /&gt;
The output looks like this:&lt;br /&gt;
&lt;br /&gt;
 MCE configuration:&lt;br /&gt;
  cc_rcs   ( cc, rcs_to_report_data ):     60&lt;br /&gt;
  cc_dec   ( cc, data_rate ):             256&lt;br /&gt;
  cc_nmux  ( cc, num_rows ):               33&lt;br /&gt;
  cc_cmux  ( cc, row_len ):               100&lt;br /&gt;
  cc_nr    ( cc, num_rows_reported ):      32&lt;br /&gt;
  cc_nc    ( cc, num_cols_reported ):       8&lt;br /&gt;
  rc_nmux  ( rca, num_rows ):              33&lt;br /&gt;
  rc_cmux  ( rca, row_len ):              100&lt;br /&gt;
  rc_nr    ( rca, num_rows_reported ):      1&lt;br /&gt;
  rc_nc    ( rca, num_cols_reported ):      1&lt;br /&gt;
  rc_r0    ( rca, readout_row_index ):      0&lt;br /&gt;
  rc_c0    ( rca, readout_col_index ):      0&lt;br /&gt;
 Framing:&lt;br /&gt;
  RC storage per mux cycle:                 1&lt;br /&gt;
  CC read-out per frame:                  256&lt;br /&gt;
  CC decimation:                          256&lt;br /&gt;
  Contiguous?                             yes&lt;br /&gt;
  Complete?                                no&lt;br /&gt;
  Bizarro?                                 no&lt;br /&gt;
  Bounded?                                yes&lt;br /&gt;
 Timing:&lt;br /&gt;
  Mux freq:                          15151.00&lt;br /&gt;
  Mean sampling freq:                15104.00&lt;br /&gt;
  Read-out freq:                        59.00&lt;br /&gt;
 Data volume:&lt;br /&gt;
  Frame size (bytes/RC):                 1200&lt;br /&gt;
  Data rate (MB/s/RC):                   0.07&lt;br /&gt;
&lt;br /&gt;
The program has notions of what is &amp;quot;reasonable&amp;quot;, and these are expressed in the lines &amp;quot;Contiguous?&amp;quot;, &amp;quot;Complete?&amp;quot;, &amp;quot;Bizarro?&amp;quot;, and &amp;quot;Bounded?&amp;quot;:&lt;br /&gt;
* 'Contiguous': all detectors that are read out will be read out at each multiplexing cycle&lt;br /&gt;
** When acquiring fast data from a subset of the detectors, at the multiplexing rate, you want &amp;quot;Contiguous = yes&amp;quot;.&lt;br /&gt;
* 'Complete': all detectors that are multiplexed will be read out&lt;br /&gt;
** When acquiring normal data, you probably want &amp;quot;Complete = yes&amp;quot;.&lt;br /&gt;
* 'Bizarro': the rectangle defined in the RC does not fit evenly into the readout frame.&lt;br /&gt;
** e.g. you have set up an 8x8 rectangle but you're reading CC frames that are 33x8.  Don't do this.  I'm not even sure what you'd get out.&lt;br /&gt;
* 'Bounded': the rectangle defined in the RC corresponds to detectors that are actually getting read/servoed.  This basically just checks that rc? readout_row_index makes any sense at all given num_rows and num_rows_reported.&lt;br /&gt;
** This must be &amp;quot;yes&amp;quot; or your data could be weird.&lt;br /&gt;
&lt;br /&gt;
Note that it is possible to be none of Complete, Contiguous, or Bizarro.  For example, you could read out the first 33 of every 66 multiplexing cycles for 8 detectors, packing them efficiently into a 33 x 8 read-out frame.  Maybe that should be called Bizarro.  But right now, it isn't.&lt;br /&gt;
&lt;br /&gt;
It is unlikely, but possible, to be both Contiguous and Complete.&lt;br /&gt;
&lt;br /&gt;
If you are Bizarro, you are neither Contiguous nor Complete.  See Venn diagram below.&lt;br /&gt;
&lt;br /&gt;
[[Image:reasonable_rectangles.png]]&lt;br /&gt;
&lt;br /&gt;
= Data acquisition =&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;mce_run&amp;quot; in the usual way to acquire data.  Note that the argument specifying the number of frames is always the number of 'read-out' frames, so for packed data the number of samples per detector will be higher.&lt;br /&gt;
&lt;br /&gt;
e.g. for the above configuration&lt;br /&gt;
 mce_run my_data 100 1&lt;br /&gt;
&lt;br /&gt;
would acquire 100 read-out frames.  Since the read-out frequency is 59 Hz, this would take about 2 seconds.  Each readout frame contains 8 x 32 = 256 data from a single detector.  So the resulting data stream contains 25600 samples.&lt;br /&gt;
&lt;br /&gt;
= Data file loading =&lt;br /&gt;
&lt;br /&gt;
Recent versions of mce_data.py can extract rectangle mode data from the packed frame structure.  E.g. for the above case, extracting the data is as easy as&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = MCEFile('my_data').Read()&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data.shape&lt;br /&gt;
 (1, 25600)&lt;br /&gt;
&lt;br /&gt;
= Rather long explanation and justification of structure, from an e-mail =&lt;br /&gt;
&lt;br /&gt;
Yesterday Bryce and I were talking about paths towards a new rectangle readout mode.  The following is a recommendation for the rough structure of the system that I think will be easy to manage and provide a maximum flexibility for backwards compatibility and future expansion.&lt;br /&gt;
&lt;br /&gt;
The current rectangle mode is simpler than the planned one because the clock card and readout card need only agree on the number of data to readout, and no addditional waiting/synchronization is required between the clock card and readout card.  The readout frame data sizes, internally and externally, are the same for everyone.  The new mode is much more complex, because now the readout card has to accumulate several samples from each pixel into its internal buffer before sending the data to the clock card, and the clock card needs to ask for the right amount of data, which is probably some multiple of the rectangle size and is not necessarily a multiple of 8 or the number of multiplexing rows.&lt;br /&gt;
&lt;br /&gt;
Anyway, the point is that here is a simple and flexible way to parametrize the new mode parameters and manage synchronization, and to provide flexibility and backwards compatibility.&lt;br /&gt;
&lt;br /&gt;
1.  The meaning of num_rows remains unchanged.  It will always be a multiplexing parameter that all cards need to agree on.&lt;br /&gt;
&lt;br /&gt;
2.  The readout card has parameters (prepend &amp;quot;readout_&amp;quot; to all of these, if you want) &amp;quot;row_index&amp;quot;, &amp;quot;num_rows&amp;quot;, &amp;quot;col_index&amp;quot;, &amp;quot;num_cols&amp;quot; that describe the rectangle of interest.&lt;br /&gt;
&lt;br /&gt;
3. The clock card is programmed with a pair of numbers &amp;quot;readout_mult1&amp;quot; and &amp;quot;readout_mult2&amp;quot;, that it uses to determine how many words of data to query the RCs for:&lt;br /&gt;
   N_data = readout_mult1 * readout_mult2.&lt;br /&gt;
These numbers are analagous to &amp;quot;num_rows_reported&amp;quot; and &amp;quot;num_cols_reported&amp;quot;, but the idea is to kill the idea of &amp;quot;rows&amp;quot; and &amp;quot;columns&amp;quot; in the readout frames because the payload size is not a simple product of n_rows * n_cols.  The clock card continues to support &amp;quot;data rate&amp;quot;, which indicates the period at which data queries are sent to the RCs.  Software will handle the details of getting these factors right.  Eventually we will only use one of mult?; the other is for backwards compat.&lt;br /&gt;
&lt;br /&gt;
4. In the RC: at each mux frame, data from the desired rectangle is copied into a large buffer.  The RC continues filling the buffer until the CC asks for data.  When RC receives a request for N data from the CC, it returns the first N data in the buffer, and resets its write index to the start of the buffer.  If the CC doesn't ask for data, and the RC buffer write index increments all the way past the end, the RC takes _no storage action_ in subsequent steps (i.e. it writes all new data to &amp;quot;/dev/null&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Setting up rectangle mode then proceeds as follows.  Suppose the RC buffer size is 1600 and I want to readout a 4 x 33 patch of the array:&lt;br /&gt;
&lt;br /&gt;
1.  Software computes that 4x33 = 132 words fits into 1600 about 12 times.  So it sets &amp;quot;cc data_rate&amp;quot; to 12, and the product of &amp;quot;mult1&amp;quot; and &amp;quot;mult2&amp;quot; to 12 * 132 = 1584.  It also sets the readout card row and col rectangle parameters.&lt;br /&gt;
&lt;br /&gt;
2.  Software triggers frame acquisition.  For the _first_ frame read out, the clock card and readout card may not be synchronized; i.e. the readout card's buffer almost certainly contains ancient, stale data.  So the first frame is discarded.  But since the first frame query sent the the buffer write index to 0, the data from subsequent frames is fresh and ordered.  Because the clock card is asking for N data at the same rate that the RC can N-fill the buffer, this results in a contiguous data stream.&lt;br /&gt;
&lt;br /&gt;
This scheme is simple because:&lt;br /&gt;
1. CC has only enough information to ask the readout cards for the right amount of data at the right times.&lt;br /&gt;
2. RC only needs to know the rectangle of interest, and it basically lets the CC manage the resetting of the buffer.&lt;br /&gt;
3. It is backwards-compatible with existing firmware; mult1 and mult2 can masquerade as num_rows_reported and &amp;quot;8&amp;quot; (num_cols_reported).&lt;br /&gt;
&lt;br /&gt;
The scheme minimizes the amount of information that must be shared between the RC and CC, which provides flexiblity.  With &amp;quot;mult&amp;quot; approach, the CC can remain truly ignorant as to what the RC is doing.  In this scheme I have emphasized the rectangle mode features, but I also envision it being useful in raw mode firmware, since a lot of the features (such as a large, flexible RAM block in the RC) would seem useful in that context.  (For raw mode you would need to add a lock to the buffer so that it could be read out with multiple queries.)&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Rectangle_Mode_Data&amp;diff=3847</id>
		<title>Rectangle Mode Data</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Rectangle_Mode_Data&amp;diff=3847"/>
		<updated>2010-08-02T17:23:20Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;quot;Rectangle Mode&amp;quot; refers to the sampling of a subset of the full array, typically at high rate.  The data from the Readout Cards is packed into output frames efficiently to minimize overhead.  Rectangle mode is available in MCE firmware starting with RC 5.0.1 and CC 5.0.0.&lt;br /&gt;
&lt;br /&gt;
= Description of capabilities =&lt;br /&gt;
&lt;br /&gt;
Rectangle mode eliminates strain on the acquisition system during fast acquisitions by eliminating read-out overhead.  This means that the 'difficulty' of read-out is a fairly linear function of (sampling frequency) x (number of detectors read out) rather than depending on each. &lt;br /&gt;
&lt;br /&gt;
The hardware limit on readout is roughly 4 MB/s.  Since MCE data are 32-bit words, this permits 1e6 detector-samples to be read out per second.&lt;br /&gt;
&lt;br /&gt;
So the maximum number of detectors that can be sampled at some frequency F is&lt;br /&gt;
  D = (1 MHz) / F&lt;br /&gt;
&lt;br /&gt;
You can't sample at 1 MHz.  (Do your squids settle in 1us?  Didn't think so.)  But you could probably do a detector or two at 250 kHz.&lt;br /&gt;
&lt;br /&gt;
= Firmware =&lt;br /&gt;
&lt;br /&gt;
Rectangle mode requires &amp;quot;version 5&amp;quot; firmware on all cards, and at least RC 5.0.2.  Here are links to the recommended SOFs at time of writing:&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/ac_v05000000_22dec2008.sof&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/bc_v05000000_22dec2008.sof&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/cc_v05000002_16jun2009.sof&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/rc_v05000002_16jun2009.sof&lt;br /&gt;
&lt;br /&gt;
= Script Differences Between v4.x.x and v5.x.x =&lt;br /&gt;
The differences between basic frame setup in v4.x.x and v5.x.x are described here.  The data frame structure has been made more flexible.  A user can read out an arbitrarily rectangular patch of the array.  The patch-size is specified using new commands.&lt;br /&gt;
&lt;br /&gt;
*In v4.x.x: The array patch-size is flexible in terms of the number of rows, and the row start index.&lt;br /&gt;
  wb cc num_rows_reported 41     //power-on default = 41&lt;br /&gt;
  wb rcs readout_row_index 0     //power-on default = 0&lt;br /&gt;
&lt;br /&gt;
*In v5.x.x: The array patch-size is now also flexible in terms of the number of columns, and the column start index.  Note that matching parameters on the Readout Cards and the Clock Card must be consistent.&lt;br /&gt;
  wb cc num_rows_reported 41     //power-on default as above&lt;br /&gt;
  wb cc num_cols_reported 8      //power-on default = 8&lt;br /&gt;
  wb rcs num_rows_reported 41    //power-on default = 41&lt;br /&gt;
  wb rcs num_cols_reported 8     //power-on default = 8&lt;br /&gt;
  wb rcs readout_row_index 0     //power-on default as above&lt;br /&gt;
  wb rcs readout_col_index 0     //power-on default = 0&lt;br /&gt;
&lt;br /&gt;
= Configuration =&lt;br /&gt;
&lt;br /&gt;
The steps for configuring a rectangle mode acquisition are:&lt;br /&gt;
# Set the multiplexing rate using num_rows and row_len&lt;br /&gt;
# If necessary, adjust row_order to mux the channels of interest (you can only read out rows you are multiplexing...).  If you do not intend to re-tune the array with the adjusted num_rows / row_order, you must also change the first entries of rc* adc_offset* to correspond to the desired rows and, for fast SQ2 switching, change row_order on the BAC/BC2.&lt;br /&gt;
# Identify a rectangle of detectors on the readout card to read out by setting the RC parameters&lt;br /&gt;
#* num_rows_reported, num_cols_reported, readout_row_index, readout_col_index&lt;br /&gt;
# Set the size of the readout frame by setting the CC parameters&lt;br /&gt;
#* num_rows_reported, num_cols_reported&lt;br /&gt;
# Set the CC decimation factor 'data_rate' so that the RC rectangles will stack perfectly into the CC readout frame.&lt;br /&gt;
#* e.g. suppose&lt;br /&gt;
#** RC num_rows_reported x num_cols_reported =  1x4 &lt;br /&gt;
#** CC num_rows_reported x num_cols_reported = 33x8&lt;br /&gt;
#* then we set &lt;br /&gt;
#** CC data_rate = (33 x 8) / (1 x 4) = 66&lt;br /&gt;
&lt;br /&gt;
= Readout limitations =&lt;br /&gt;
&lt;br /&gt;
Rectangle mode configuration should respect the following hardware limits:&lt;br /&gt;
* Total data rate must not exceed 4 MB/s&lt;br /&gt;
* Read-out frequency must not exceed 20 kHz&lt;br /&gt;
* The multiplexing frame rate must not be set so fast that the MCE cannot communicate with the readout cards.  This limit is probably in the 100s of kHz.&lt;br /&gt;
&lt;br /&gt;
Other things to remember:&lt;br /&gt;
* num_rows &amp;gt;= 2 is encouraged.&lt;br /&gt;
* you can't sample a detector faster than it is being visited in the multiplexing cycle.&lt;br /&gt;
&lt;br /&gt;
= Checking MCE configuration using rect_check.py =&lt;br /&gt;
&lt;br /&gt;
Use the utility @rect_check.py@ to verify that data will be / were acquired reasonably.&lt;br /&gt;
&lt;br /&gt;
e.g. To check the state of the MCE (requires python MCE bindings), run&lt;br /&gt;
 rect_check.py --mce&lt;br /&gt;
&lt;br /&gt;
To analyze the data framing in a runfile:&lt;br /&gt;
 rect_check.py my_data.run&lt;br /&gt;
&lt;br /&gt;
(Depending on stuff, you might need to invoke rect_check as:&lt;br /&gt;
 $MAS_PYTHON/rect_check.py&lt;br /&gt;
or even&lt;br /&gt;
 python $MAS_PYTHON/rect_check.py&lt;br /&gt;
Sorry.)&lt;br /&gt;
&lt;br /&gt;
The output looks like this:&lt;br /&gt;
&lt;br /&gt;
 MCE configuration:&lt;br /&gt;
  cc_rcs   ( cc, rcs_to_report_data ):     60&lt;br /&gt;
  cc_dec   ( cc, data_rate ):             256&lt;br /&gt;
  cc_nmux  ( cc, num_rows ):               33&lt;br /&gt;
  cc_cmux  ( cc, row_len ):               100&lt;br /&gt;
  cc_nr    ( cc, num_rows_reported ):      32&lt;br /&gt;
  cc_nc    ( cc, num_cols_reported ):       8&lt;br /&gt;
  rc_nmux  ( rca, num_rows ):              33&lt;br /&gt;
  rc_cmux  ( rca, row_len ):              100&lt;br /&gt;
  rc_nr    ( rca, num_rows_reported ):      1&lt;br /&gt;
  rc_nc    ( rca, num_cols_reported ):      1&lt;br /&gt;
  rc_r0    ( rca, readout_row_index ):      0&lt;br /&gt;
  rc_c0    ( rca, readout_col_index ):      0&lt;br /&gt;
 Framing:&lt;br /&gt;
  RC storage per mux cycle:                 1&lt;br /&gt;
  CC read-out per frame:                  256&lt;br /&gt;
  CC decimation:                          256&lt;br /&gt;
  Contiguous?                             yes&lt;br /&gt;
  Complete?                                no&lt;br /&gt;
  Bizarro?                                 no&lt;br /&gt;
 Timing:&lt;br /&gt;
  Mux freq:                          15151.00&lt;br /&gt;
  Mean sampling freq:                15104.00&lt;br /&gt;
  Read-out freq:                        59.00&lt;br /&gt;
 Data volume:&lt;br /&gt;
  Frame size (bytes/RC):                 1200&lt;br /&gt;
  Data rate (MB/s/RC):                   0.07&lt;br /&gt;
&lt;br /&gt;
The program has notions of what is &amp;quot;reasonable&amp;quot;, and these are expressed in the lines &amp;quot;Contiguous?&amp;quot;, &amp;quot;Complete?&amp;quot;, and &amp;quot;Bizarro?&amp;quot;:&lt;br /&gt;
* 'Contiguous': all detectors that are read out will be read out at each multiplexing cycle&lt;br /&gt;
** When acquiring fast data from a subset of the detectors, at the multiplexing rate, you want &amp;quot;Contiguous = yes&amp;quot;.&lt;br /&gt;
* 'Complete': all detectors that are multiplexed will be read out&lt;br /&gt;
** When acquiring normal data, you probably want &amp;quot;Complete = yes&amp;quot;.&lt;br /&gt;
* 'Bizarro': the rectangle defined in the RC does not fit evenly into the readout frame.&lt;br /&gt;
** e.g. you have set up an 8x8 rectangle but you're reading CC frames that are 33x8.  Don't do this.  I'm not even sure what you'd get out. &lt;br /&gt;
&lt;br /&gt;
Note that it is possible to be none of Complete, Contiguous, or Bizarro.  For example, you could read out the first 33 of every 66 multiplexing cycles for 8 detectors, packing them efficiently into a 33 x 8 read-out frame.  Maybe that should be called Bizarro.  But right now, it isn't.&lt;br /&gt;
&lt;br /&gt;
It is unlikely, but possible, to be both Contiguous and Complete.&lt;br /&gt;
&lt;br /&gt;
If you are Bizarro, you are neither Contiguous nor Complete.  See Venn diagram below.&lt;br /&gt;
&lt;br /&gt;
[[Image:reasonable_rectangles.png]]&lt;br /&gt;
&lt;br /&gt;
= Data acquisition =&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;mce_run&amp;quot; in the usual way to acquire data.  Note that the argument specifying the number of frames is always the number of 'read-out' frames, so for packed data the number of samples per detector will be higher.&lt;br /&gt;
&lt;br /&gt;
e.g. for the above configuration&lt;br /&gt;
 mce_run my_data 100 1&lt;br /&gt;
&lt;br /&gt;
would acquire 100 read-out frames.  Since the read-out frequency is 59 Hz, this would take about 2 seconds.  Each readout frame contains 8 x 32 = 256 data from a single detector.  So the resulting data stream contains 25600 samples.&lt;br /&gt;
&lt;br /&gt;
= Data file loading =&lt;br /&gt;
&lt;br /&gt;
Recent versions of mce_data.py can extract rectangle mode data from the packed frame structure.  E.g. for the above case, extracting the data is as easy as&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = MCEFile('my_data').Read()&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data.shape&lt;br /&gt;
 (1, 25600)&lt;br /&gt;
&lt;br /&gt;
= Rather long explanation and justification of structure, from an e-mail =&lt;br /&gt;
&lt;br /&gt;
Yesterday Bryce and I were talking about paths towards a new rectangle readout mode.  The following is a recommendation for the rough structure of the system that I think will be easy to manage and provide a maximum flexibility for backwards compatibility and future expansion.&lt;br /&gt;
&lt;br /&gt;
The current rectangle mode is simpler than the planned one because the clock card and readout card need only agree on the number of data to readout, and no addditional waiting/synchronization is required between the clock card and readout card.  The readout frame data sizes, internally and externally, are the same for everyone.  The new mode is much more complex, because now the readout card has to accumulate several samples from each pixel into its internal buffer before sending the data to the clock card, and the clock card needs to ask for the right amount of data, which is probably some multiple of the rectangle size and is not necessarily a multiple of 8 or the number of multiplexing rows.&lt;br /&gt;
&lt;br /&gt;
Anyway, the point is that here is a simple and flexible way to parametrize the new mode parameters and manage synchronization, and to provide flexibility and backwards compatibility.&lt;br /&gt;
&lt;br /&gt;
1.  The meaning of num_rows remains unchanged.  It will always be a multiplexing parameter that all cards need to agree on.&lt;br /&gt;
&lt;br /&gt;
2.  The readout card has parameters (prepend &amp;quot;readout_&amp;quot; to all of these, if you want) &amp;quot;row_index&amp;quot;, &amp;quot;num_rows&amp;quot;, &amp;quot;col_index&amp;quot;, &amp;quot;num_cols&amp;quot; that describe the rectangle of interest.&lt;br /&gt;
&lt;br /&gt;
3. The clock card is programmed with a pair of numbers &amp;quot;readout_mult1&amp;quot; and &amp;quot;readout_mult2&amp;quot;, that it uses to determine how many words of data to query the RCs for:&lt;br /&gt;
   N_data = readout_mult1 * readout_mult2.&lt;br /&gt;
These numbers are analagous to &amp;quot;num_rows_reported&amp;quot; and &amp;quot;num_cols_reported&amp;quot;, but the idea is to kill the idea of &amp;quot;rows&amp;quot; and &amp;quot;columns&amp;quot; in the readout frames because the payload size is not a simple product of n_rows * n_cols.  The clock card continues to support &amp;quot;data rate&amp;quot;, which indicates the period at which data queries are sent to the RCs.  Software will handle the details of getting these factors right.  Eventually we will only use one of mult?; the other is for backwards compat.&lt;br /&gt;
&lt;br /&gt;
4. In the RC: at each mux frame, data from the desired rectangle is copied into a large buffer.  The RC continues filling the buffer until the CC asks for data.  When RC receives a request for N data from the CC, it returns the first N data in the buffer, and resets its write index to the start of the buffer.  If the CC doesn't ask for data, and the RC buffer write index increments all the way past the end, the RC takes _no storage action_ in subsequent steps (i.e. it writes all new data to &amp;quot;/dev/null&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Setting up rectangle mode then proceeds as follows.  Suppose the RC buffer size is 1600 and I want to readout a 4 x 33 patch of the array:&lt;br /&gt;
&lt;br /&gt;
1.  Software computes that 4x33 = 132 words fits into 1600 about 12 times.  So it sets &amp;quot;cc data_rate&amp;quot; to 12, and the product of &amp;quot;mult1&amp;quot; and &amp;quot;mult2&amp;quot; to 12 * 132 = 1584.  It also sets the readout card row and col rectangle parameters.&lt;br /&gt;
&lt;br /&gt;
2.  Software triggers frame acquisition.  For the _first_ frame read out, the clock card and readout card may not be synchronized; i.e. the readout card's buffer almost certainly contains ancient, stale data.  So the first frame is discarded.  But since the first frame query sent the the buffer write index to 0, the data from subsequent frames is fresh and ordered.  Because the clock card is asking for N data at the same rate that the RC can N-fill the buffer, this results in a contiguous data stream.&lt;br /&gt;
&lt;br /&gt;
This scheme is simple because:&lt;br /&gt;
1. CC has only enough information to ask the readout cards for the right amount of data at the right times.&lt;br /&gt;
2. RC only needs to know the rectangle of interest, and it basically lets the CC manage the resetting of the buffer.&lt;br /&gt;
3. It is backwards-compatible with existing firmware; mult1 and mult2 can masquerade as num_rows_reported and &amp;quot;8&amp;quot; (num_cols_reported).&lt;br /&gt;
&lt;br /&gt;
The scheme minimizes the amount of information that must be shared between the RC and CC, which provides flexiblity.  With &amp;quot;mult&amp;quot; approach, the CC can remain truly ignorant as to what the RC is doing.  In this scheme I have emphasized the rectangle mode features, but I also envision it being useful in raw mode firmware, since a lot of the features (such as a large, flexible RAM block in the RC) would seem useful in that context.  (For raw mode you would need to add a lock to the buffer so that it could be read out with multiple queries.)&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=PCI_card_code_assembly_on_Linux&amp;diff=3323</id>
		<title>PCI card code assembly on Linux</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=PCI_card_code_assembly_on_Linux&amp;diff=3323"/>
		<updated>2010-04-30T20:06:30Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Assembler and linker =&lt;br /&gt;
&lt;br /&gt;
Motorola/Frescale provide a Windows/DOS assembler/linker, called CLAS.  The binaries run quite well under Linux via Wine.  An exception is the final hex-file creation step that converts the .lod file to an Intel S-record file for use with an eprom burner; we have our own code for that.&lt;br /&gt;
&lt;br /&gt;
== Install and configure Wine ==&lt;br /&gt;
&lt;br /&gt;
To install wine (the Windows Emulator for Linux):&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install wine&lt;br /&gt;
 wine&lt;br /&gt;
&lt;br /&gt;
Running wine with no arguments should initialize it and create a place for the fake windows file system it uses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Install CLAS ==&lt;br /&gt;
&lt;br /&gt;
The assembler binaries are available from Astrocam [ http://www.astro-cam.com/arcpage.php?txt=software.php#dsp ], or from mhasse [http://e-mode.phas.ubc.ca/~mhasse/mce/arc_pci/clas563.zip].  We need the versions for the DSP56300 family.&lt;br /&gt;
&lt;br /&gt;
This will grab the binaries and put them in the right place:  &lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/arc_pci/clas563.zip&lt;br /&gt;
 unzip clas563.zip&lt;br /&gt;
 mv CLAS563 ~/.wine/drive_c/&lt;br /&gt;
&lt;br /&gt;
You could now run the programs via, e.g.&lt;br /&gt;
 wine ~/.wine/drive_c/CLAS563/BIN/ASM56300.EXE &amp;lt;args&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Install wrapper scripts ==&lt;br /&gt;
&lt;br /&gt;
The arc_pci repository includes a folder &amp;quot;clash&amp;quot; which contains the lod2s program and some wrapper scripts for launching the CLAS programs.  The scripts, and the lod2s program, should probably be copied into the path somewhere.  I use ~/bin.&lt;br /&gt;
&lt;br /&gt;
 MY_BIN=~/bin&lt;br /&gt;
 cd src/arc_pci&lt;br /&gt;
 cd clash&lt;br /&gt;
 make -C srec lod2s&lt;br /&gt;
 cp srec/lod2s script/* $MY_BIN&lt;br /&gt;
&lt;br /&gt;
Now the makefiles in, e.g., arc_pci/trunk should work.&lt;br /&gt;
&lt;br /&gt;
The wrapper scripts assume location ~/.wine/drive_c/CLAS563/BIN/ for the CLAS windows binaries.  You can override this by putting&lt;br /&gt;
 export CLAS_BIN=/somewhere/else&lt;br /&gt;
in your .bashrc .&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=PCI_card_firmware&amp;diff=3322</id>
		<title>PCI card firmware</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=PCI_card_firmware&amp;diff=3322"/>
		<updated>2010-04-30T20:00:44Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Download =&lt;br /&gt;
&lt;br /&gt;
These S-record files should work with any reasonable EPROM programmer:&lt;br /&gt;
* U0105 (latest) - http://e-mode.phas.ubc.ca/~mhasse/mce/arc_pci/SDSU_RevU0105.s&lt;br /&gt;
* U0104 (stable) - http://e-mode.phas.ubc.ca/~mhasse/mce/arc_pci/SDSU_RevU0104.s&lt;br /&gt;
&lt;br /&gt;
The full source code is available in these archives (it will not compile unless you get the correct assembler and stuff):&lt;br /&gt;
* U0105 - http://e-mode.phas.ubc.ca/~mhasse/mce/arc_pci/arc_pci-U0105.tar.gz&lt;br /&gt;
* U0104 - http://e-mode.phas.ubc.ca/~mhasse/mce/arc_pci/arc_pci-U0104.tar.gz&lt;br /&gt;
&lt;br /&gt;
The subversion tree can be obtained like this (you may not have access to this repository; contact UBC);&lt;br /&gt;
 svn checkout svn://e-mode.phas.ubc.ca/arc_pci&lt;br /&gt;
&lt;br /&gt;
It is laid out roughly as follows:&lt;br /&gt;
 /trunk       main line of development&lt;br /&gt;
 /releases    tagged versions of code &lt;br /&gt;
 /tools       debugging tools&lt;br /&gt;
 /clash       stuff for making CLAS work with wine and linux&lt;br /&gt;
 /docs        useful (though maybe not to you) notes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Other information =&lt;br /&gt;
&lt;br /&gt;
* [[ PCI card bug list ]]&lt;br /&gt;
* [[ PCI card hacking ]]&lt;br /&gt;
* [[ PCI card code assembly on Linux ]]&lt;br /&gt;
&lt;br /&gt;
= Firmware version notes =&lt;br /&gt;
&lt;br /&gt;
== Latest release: U0105 (2009-06-08) ==&lt;br /&gt;
&lt;br /&gt;
* Backward compatible with U0104.&lt;br /&gt;
* Support for MCE STOP commands and commands-on-the-fly.&lt;br /&gt;
* Accelerated MCE command code (along with Quiet-RP this increases commanding rate to ~6 kHz).&lt;br /&gt;
* Quiet-RP simplifies the protocol for MCE reply handling.&lt;br /&gt;
* Low-level improvements:&lt;br /&gt;
** CON is done as PCI burst&lt;br /&gt;
** Fibre-optic FIFO is emptied with timed read instead of polling.&lt;br /&gt;
** Hand-shaking for interrupts instead of host command to clear INTA and HC3.&lt;br /&gt;
** Non-interrupt context code disables interrupts when performing PCI transactions.&lt;br /&gt;
** Host vector interrupts are otherwise enabled, so PC doesn't have to force with HNMI bit.&lt;br /&gt;
&lt;br /&gt;
== Last stable version: U0104 ==&lt;br /&gt;
&lt;br /&gt;
* Implements quiet transfer mode!  Remains backwards compatible with A1.4.&lt;br /&gt;
* Fixes the 64k boundary crossing issue&lt;br /&gt;
* Moves parameters that enter via interrupt out of registers and into variables&lt;br /&gt;
* Version reporting tag-along to RDM command (sending 'VER' to RDM's vector address returns the code version).&lt;br /&gt;
* Maximum burst length is reduced to 64 bytes, and is configurable.&lt;br /&gt;
* Reset (RST) clears the fibre fifo&lt;br /&gt;
&lt;br /&gt;
== Oldest UBC release: U0103 ==&lt;br /&gt;
&lt;br /&gt;
* Minor modifications of SCUBA2's A1.4 firmware, to improve PCI stability.&lt;br /&gt;
* Not compatible with non-realtime systems.&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=PCI_card_bug_list&amp;diff=3167</id>
		<title>PCI card bug list</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=PCI_card_bug_list&amp;diff=3167"/>
		<updated>2010-03-12T23:39:08Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is a list of things to fix in subsequent releases.&lt;br /&gt;
&lt;br /&gt;
== U0105 bugs ==&lt;br /&gt;
&lt;br /&gt;
* STATUS[DMA_RESUME] flag is not cleared after the error is handled.  Innocuous.&lt;br /&gt;
* STATUS[HST_NFYD] flag is half-used, not cleared.  Innocuous.&lt;br /&gt;
* Asynchronous MCE reply NFY does not seem to play well with QTS TAIL updates.  I.e. some part of the system breaks when a QTS is issued between a CON and the associated NFY REP.&lt;br /&gt;
* Does CON_TRANSMIT need to disable PCI interrupts while it is sending the command to MCE?  What is the MCE input time-out?&lt;br /&gt;
&lt;br /&gt;
== U0103 bugs ==&lt;br /&gt;
&lt;br /&gt;
* Data packets can fail to HST properly.  This was observed in MAS driver, and only recently in DAS.  In one instance, DAS failed with a timeout after receiving 1381/2000 frames and could not take data (though other mce commands worked) until the driver was reloaded.  This looks to me like lost HST replies.  The NFY comes through and the HST gets sent but then everything hangs.&lt;br /&gt;
&lt;br /&gt;
* After some failures (card lookup?), one-behind state emerges.  &amp;quot;Reset&amp;quot; doesn't help, nor does &amp;quot;reset_mce&amp;quot;.  A command must be issued (which returns as unmatched), and then reset dsp will fix the problem.  I'm not even sure where the packet is trapped.&lt;br /&gt;
&lt;br /&gt;
== A1.5 / U0103 design issues ==&lt;br /&gt;
&lt;br /&gt;
* PCI reset doesn't empty the FIFO!  FIFO is cleared on preamble error.  But that means you have will definitely lose an MCE packet if buffer gets out of sync.  Reset is 2 ms long; perhaps this is a way of waiting for an entire reply to have been transmitted?  A PCI reset routine should clear the FIFO.  Either that or a separate vector command, but that seems like overkill.&lt;br /&gt;
&lt;br /&gt;
* Since packet choke is on after a reset, any words in fifo get discarded without a preamble check; this means that FIFO can't be reset before the first MCE command.  This is silly; reset should clear the fifo!&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Dirfile_support&amp;diff=2870</id>
		<title>Dirfile support</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Dirfile_support&amp;diff=2870"/>
		<updated>2009-11-20T20:00:36Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* System configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Support overview =&lt;br /&gt;
&lt;br /&gt;
As of mas/trunk/:r384, MAS supports writing of dirfiles.  For now we are using a very basic dirfile standard, compatible with older versions of KST as well more recent versions of libgetdata.&lt;br /&gt;
&lt;br /&gt;
Consult the sourceforge page for dirfile libraries and documentation:&lt;br /&gt;
 http://getdata.sourceforge.net/&lt;br /&gt;
&lt;br /&gt;
Although MAS can write dirfiles, we do not currently provide a facility for reading dirfiles into python or IDL, as we do for MCE flatfiles.  We recommend that flatfiles be used for tuning and diagnostic data, with dirfiles only used for long acquisitions that will be analyzed off-line or by non-MAS software.&lt;br /&gt;
&lt;br /&gt;
dirfiles are very useful for large, multi-rate data sets.  They are not ideal in all circumstances, however.&lt;br /&gt;
&lt;br /&gt;
= Invocation =&lt;br /&gt;
&lt;br /&gt;
To acquire data into a dirfile, pass the --dirfile option to mce_run:&lt;br /&gt;
&lt;br /&gt;
 mce_run 10000 dirfile_0526 s --dirfile&lt;br /&gt;
&lt;br /&gt;
This will create a dirfile at $MAS_DATA/dirfile_0526/ , and acquire 10000 frames from all readout card channels.&lt;br /&gt;
&lt;br /&gt;
Please note the following:&lt;br /&gt;
* currently the &amp;quot;--dirfile&amp;quot; option must be listed after the three mandatory arguments.&lt;br /&gt;
* the number of &amp;quot;samples&amp;quot; requested should be a multiple of 100, as this is the samples/frame ratio specified in the MCE dirfile format file.&lt;br /&gt;
&lt;br /&gt;
= System configuration =&lt;br /&gt;
&lt;br /&gt;
To prevent crazy programs from bringing down the system, Linux controls the maximum number of files that any one shell can have open.  The dirfile writer needs to keep a file open for each data channel, and for MCE data this could be ~2000 separate files.  If the OS limit is too low to accommodate this, we need to increase it.&lt;br /&gt;
&lt;br /&gt;
To check current OS limit, run ulimit:&lt;br /&gt;
 mhasse@gamow:~$ ulimit -n&lt;br /&gt;
 1024&lt;br /&gt;
&lt;br /&gt;
This is too small.  To increase it, edit /etc/security/limits.conf .  Add / edit lines for item &amp;quot;nofile&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 *               soft    nofile          2048&lt;br /&gt;
 *               hard    nofile          4096&lt;br /&gt;
&lt;br /&gt;
After reboot, you should get&lt;br /&gt;
 mhasse@gamow:~$ ulimit -n&lt;br /&gt;
 2048&lt;br /&gt;
&lt;br /&gt;
= Dirfile fields =&lt;br /&gt;
&lt;br /&gt;
== Raw fields ==&lt;br /&gt;
The dirfile consists of raw fields and derived fields.  For MCE data, the raw fields consist of fields from the frame header:&lt;br /&gt;
 status&lt;br /&gt;
 frame_ctr&lt;br /&gt;
 row_len&lt;br /&gt;
 num_rows_reported&lt;br /&gt;
 data_rate&lt;br /&gt;
 address0_ctr&lt;br /&gt;
 header_version&lt;br /&gt;
 ramp_value&lt;br /&gt;
 ramp_addr&lt;br /&gt;
 num_rows&lt;br /&gt;
 sync_box_num&lt;br /&gt;
 runfile_id&lt;br /&gt;
 userfield&lt;br /&gt;
&lt;br /&gt;
as well as the 32 bit words returned for each detector channel:&lt;br /&gt;
 tesdatar00c00&lt;br /&gt;
 tesdatar00c01&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Note that MAS will determine exactly what channels are returning data and name the fields appropriately.  So when reading RC2 only with readout_row_index=4 and num_rows_reported=1, the output fields will be&lt;br /&gt;
 tesdatar04c08&lt;br /&gt;
 tesdatar04c09&lt;br /&gt;
 tesdatar04c10&lt;br /&gt;
 tesdatar04c11&lt;br /&gt;
 tesdatar04c12&lt;br /&gt;
 tesdatar04c13&lt;br /&gt;
 tesdatar04c14&lt;br /&gt;
 tesdatar04c15&lt;br /&gt;
&lt;br /&gt;
== Derived fields ==&lt;br /&gt;
&lt;br /&gt;
Based on the [[ data_mode | Data Mode ]] of each readout card, derived signals are extracted from the raw data and made available to libgetdata users.  The field extraction and conversion is accomplished according to the same rules used by [[ Python data and runfile modules | mce_data.py ]] and [[ mas_data.pro ]], i.e. the data are scaled to some reference level for that signal.  See the discussion in the [[ Data Mode ]] page.&lt;br /&gt;
&lt;br /&gt;
The field names for error, feedback, filtered feedback, and phi0 counter data are, respectively (for r00c00)&lt;br /&gt;
 error_r00c00&lt;br /&gt;
 fb_r00c00&lt;br /&gt;
 filt_r00c00&lt;br /&gt;
 fj_r00c00&lt;br /&gt;
&lt;br /&gt;
For some conversions, it is necessary to first extract the bitfield from the raw MCE word and then scale it.  In these cases an intermediate field will be created, e.g.:&lt;br /&gt;
 INTER_filt_r00c00&lt;br /&gt;
&lt;br /&gt;
Such fields can be ignored.&lt;br /&gt;
&lt;br /&gt;
== Warning about signed fields in mixed-mode data ==&lt;br /&gt;
&lt;br /&gt;
Currently the dirfile standard does not support sign extension of bit-field data.  The result is that signed signals from mixed-mode MCE data will appear as positive numbers, with 'negative' values -D represented by the large positive number 2^n - D.  For example, in data mode 4 the error signal is encoded in the lowest-order 14 bits of the MCE word.  An error reading of 12 gets encoded as 00000000001100 in binary and would be extracted as 12, but an error reading of -12 would be encoded with the 14 binary digits 11111111110100, and upon extraction would end up as 2^14 - 12 = 16372.&lt;br /&gt;
&lt;br /&gt;
Sign-related issues can be corrected in down-stream software; there is no information loss.  But something like KST will not naturally 'do the right thing' here, so the time-stream and spectrum plots will be awful.&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Auto-setup_(IDL)&amp;diff=2851</id>
		<title>Auto-setup (IDL)</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Auto-setup_(IDL)&amp;diff=2851"/>
		<updated>2009-10-19T19:44:43Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* IDL calling parameters */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This script tunes a squid array using the MCE.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The steps in the tuning are roughly the following:&lt;br /&gt;
# &amp;quot;SA ramp&amp;quot;: Ramp the SA feedback to select the SA output value of the lock-point (at this stage it is also possible to ramp the SA bias to find a V-phi curve of maximum amplitide). &lt;br /&gt;
# &amp;quot;SQ2 servo&amp;quot;: Ramp the SQ2 feedback and servo the SA feedback to determine the SA feedback at lock-point.&lt;br /&gt;
# &amp;quot;SQ1 servo&amp;quot;: For a single SQ1 in each column , ramp the SQ1 feedback and servo the SQ2 feedback to determine the SQ2 feedback at lock-point.&lt;br /&gt;
# &amp;quot;SQ1 ramp&amp;quot;: For each SQ1, ramp the SQ1 feedback and determine the SA output value correction (ADC_offset) of the lock-point.&lt;br /&gt;
&lt;br /&gt;
In addition to these, there is a final acquisition of a few hundred frames to evaluate the lock of each detector.  This is called &amp;quot;frametest&amp;quot;.  Following this test, and independent of it, the servo parameters of channels known to be dead or problematic are turned off.&lt;br /&gt;
&lt;br /&gt;
== Tuning parameters ==&lt;br /&gt;
&lt;br /&gt;
Most tuning parameters (such as biases, servo gains, SQ1 servo row selections) are defined in the [[experiment.cfg]] file.  Contact UBC for help with this.&lt;br /&gt;
&lt;br /&gt;
== Auto script ==&lt;br /&gt;
&lt;br /&gt;
Command-line access is via auto_setup_squids_sh, called like this:&lt;br /&gt;
  auto_setup_squids_sh &amp;lt;level&amp;gt; &amp;lt;cards&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* level is one of 0,1,2 and selects what parts of the tuning to perform&lt;br /&gt;
** 0 (default): full tuning of all stages of the array.&lt;br /&gt;
** 1: perform only the &amp;quot;SQ1 servo&amp;quot; and the &amp;quot;SQ1 ramp&amp;quot; &lt;br /&gt;
** 2: perform only the &amp;quot;SQ1 ramp&amp;quot;&lt;br /&gt;
* cards is one of s,1,2,3,4, with s the default:&lt;br /&gt;
** Note for &amp;quot;s&amp;quot;: this will tune all *4* readout cards.  'rcs' support for systems with 2 readout cards is still in development.&lt;br /&gt;
&lt;br /&gt;
== IDL calling parameters ==&lt;br /&gt;
&lt;br /&gt;
The IDL function declaration is (as of r397)&lt;br /&gt;
 pro auto_setup_squids, COLUMN=column, ROW=row, $&lt;br /&gt;
      RCs=rcs, $&lt;br /&gt;
      interactive=interactive, text=text, $&lt;br /&gt;
      numrows=numrows, note=note, $&lt;br /&gt;
      ramp_sa_bias=ramp_sa_bias, check_bias=check_bias, $&lt;br /&gt;
      short=short, quiet=quiet&lt;br /&gt;
&lt;br /&gt;
Parameters that continue to be supported are:&lt;br /&gt;
* '''rcs''' (int array): an array of readout card numbers to tune.  e.g. [1,2].&lt;br /&gt;
* '''note''' (string): a string to pass to the DB registration program (for logging)&lt;br /&gt;
* '''short''' (int): causes tuning of only particular stages of the array (useful for correcting minor drifts due to changing thermal or magnetic environments)&lt;br /&gt;
* '''ramp_sa_bias''' (switch): forces ramping of the SA bias during the SA ramp step.  This can also be controlled through experiment.cfg&lt;br /&gt;
* '''check_bias''' (switch): causes the script to check for biasing of the SA and SQ2.  If these are off, they are biased on and the script delays execution for a couple of minutes to let the system equilibrate. &lt;br /&gt;
* '''quiet''' (int): when set to 1 or 2, reduces text output to the terminal.&lt;br /&gt;
&lt;br /&gt;
Parameters that no one really uses but might still work:&lt;br /&gt;
* '''column''' and '''row''' (int array): columns and rows to plot in the final frametest step.&lt;br /&gt;
&lt;br /&gt;
Parameters that are probably broken or definitely meaningless:&lt;br /&gt;
* '''interactive'''&lt;br /&gt;
* '''text'''&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2850</id>
		<title>Locking slopes</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2850"/>
		<updated>2009-10-19T19:42:53Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Servos */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MCE/MAS parameters that affect locking slopes =&lt;br /&gt;
&lt;br /&gt;
== Slope controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters in [[Mce config template system | experiment.cfg]] affect the locking slopes:&lt;br /&gt;
&lt;br /&gt;
* '''sq2servo_gain''': sets the gain of the SQ2 servo and effectively determines the sign of the SA lock slope.&lt;br /&gt;
* '''sq1servo_gain''': sets the gain of the SQ1 servo and, with the sq2servo_gain, determines the SQ2 lock slope.&lt;br /&gt;
* '''default_servo_i''': determines the I gain of the MCE servo (rc# gaini#), and thus the sign of the locking slopeof the SQ1.&lt;br /&gt;
&lt;br /&gt;
== Plotting controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters affect plotting of locking slopes in IDL, as well as the choice of starting feedbacks for the next stage of servos:&lt;br /&gt;
&lt;br /&gt;
* '''sq2servo_slope''' in experiment.cfg: (+1 or -1) the sign of the slope in the SQ2 servo plots to which we expect to lock.&lt;br /&gt;
* '''sq1servo_slope''' in experiment.cfg: (+1 or -1) the sign of the slope in the SQ1 servo plots to which we expect to lock.&lt;br /&gt;
&lt;br /&gt;
In newer versions of auto-tuning, these parameters are ignored and the locking slope is determined from the signs of the servo gains.&lt;br /&gt;
&lt;br /&gt;
== Consistency between locking and plotting ==&lt;br /&gt;
&lt;br /&gt;
The above slope and plotting parameters should satisfy the following:&lt;br /&gt;
* sq2servo_slope =  -sign( sq2servo_gain / sq1servo_gain) &lt;br /&gt;
* sq1servo_slope =  -sign( sq1servo_gain / default_servo_i)&lt;br /&gt;
&lt;br /&gt;
These relations follow from the discussion in the sections below.&lt;br /&gt;
&lt;br /&gt;
Violation of the above will likely only result in misleading plots, and not bad locking.  Misleading plots can indirectly lead to a user setting up bad locking, however; so keep it clean.&lt;br /&gt;
&lt;br /&gt;
'''The sa_points.ps plot may be misleading''': older auto-tuning code (still in use all over the place) plots the positive-slope lock-points, regardless of any other parameters.  Newer auto-tuning code resolves this.&lt;br /&gt;
&lt;br /&gt;
= MCE and tuning servos =&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
We will need to deal with three servos.  One is the &amp;quot;MCE servo&amp;quot;, which is the fast servoing of the TES signal via adjustment of the SQ1 feedback.  The other two are the auto-tuning SQ2 and SQ1 servos, described [[auto_setup_squids.pro | here]]. &lt;br /&gt;
&lt;br /&gt;
In all cases, the servo is computed by measuring an error (&amp;lt;math&amp;gt;\Delta&amp;lt;/math&amp;gt; y), multiplying by a gain (g), and using this to correct the output (x):&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x = g~\Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the case of the MCE PID loop servo, we run with an I term only so we actually calculate&lt;br /&gt;
 &amp;lt;math&amp;gt;x = P ~\sum \Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but differentially this is exactly &amp;lt;math&amp;gt;\Delta x = P * \Delta y&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE/MAS and sneaky signs ==&lt;br /&gt;
&lt;br /&gt;
There are no sneaky, extra signs in any of the MCE/MAS servo calculations.  This means that given an error (dy) and a gain g, we calculate the change in the feedback (dx) as:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and not&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = -g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is a sneaky gain in the MCE servo, though; once the default_servo_i is set, the DAC value of the feedback is actually calculated as&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta FB = (I~dy) / 2^{12}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But there's no sneaky sign.  Just a sneaky gain.&lt;br /&gt;
&lt;br /&gt;
= The meaning of the plots =&lt;br /&gt;
&lt;br /&gt;
== Definition of a lock point ==&lt;br /&gt;
&lt;br /&gt;
Let the feedback signals on the three stages (in one channel) be &amp;lt;math&amp;gt;x_{SA}, x_{S2}, x_{S1}&amp;lt;/math&amp;gt;, and let the error signal be y.  Let s be the signal from the TES.  The error signal is obviously a function of all 4 numbers:&lt;br /&gt;
 &amp;lt;math&amp;gt;y = f(x_{SA}, x_{S2}, x_{S1}, t)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But for small variations about one point in this space, we can expand in differentials&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = a_1 dx_{SA} + a_2 dx_{S2} + a_3 dx_{S1} +  a_4 s&amp;lt;/math&amp;gt;&lt;br /&gt;
but it is convenient to reparametrize this to resemble the chain of amplifiers:&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = m_{SA}(dx_{SA} - m_{S2}(dx_{S2} - m_{S1}(dx_{S1} - m_{TES} s)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the 'slopes' m account for the instantaneous gain between the stages at the lock point.&lt;br /&gt;
&lt;br /&gt;
== Open loop ramps ==&lt;br /&gt;
&lt;br /&gt;
Note that lock points are not ultimately chosen as a result of the open loop ramps.  However, it is important to understand the relationship between what the open loop ramps and the settings for the auto-tuning and MCE servos.&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SA ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{S2}, x_{S1}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{SA}&amp;lt;/math&amp;gt;.  Thus identifying a lock point permits the measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{SA} = m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SQ1 ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{SA}, x_{S2}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{S1}&amp;lt;/math&amp;gt;.  A slope measurement on this curve is a measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{S1} = m_{SA} m_{S2} m_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
In servos, we ramp one stage's x while adjusting another x to keep the error at zero.&lt;br /&gt;
&lt;br /&gt;
Thus in the &amp;quot;SQ2 servo&amp;quot; step (where SQ2 FB is ramped and SQA FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{SA} = m_{S2} dx_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, this can only be accomplished via measurement of the error&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = -m_{SA} m_{S2} \Delta x_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
so operationally we apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{SA} = - \Delta y / m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the ideal gain of the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S2} = -1/m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;SQ1 servo&amp;quot; step (where SQ1 FB is ramped and SQ2 FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S2} = m_{S1} dx_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
so we measure&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = m_{SA} m_{S2} m_{S1} \Delta x_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
and apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S2} = \Delta y / (m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
so the ideal gain of the SQ1 servo is&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S1} = 1/(m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE servo I parameter ==&lt;br /&gt;
&lt;br /&gt;
When the MCE servo is activated, it cancels changes in TES current by adjusting the SQ1 FB:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S1} = m_{TES} ds&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
i.e.&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S1} = -\Delta y / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
and ideal gain is thus&lt;br /&gt;
 &amp;lt;math&amp;gt;I_{servo} = -1 / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Consequences for tuning parameters ==&lt;br /&gt;
&lt;br /&gt;
We have expressed, above, the ideal gains for the servos as a function of the slopes of the ramp and servo curves from auto-tuning.  Solving these for the slopes as a function of the ideal gains yields the locking slopes' dependence on the signs of the gains:&lt;br /&gt;
&lt;br /&gt;
=== SA locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SA ramp) is determined by the gain in the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA}) =  -sgn(1/g_{S2})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ2 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SQ2 servo curve) is determined by the ratio of the gains in the SQ1 and SQ2 servos:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S2}) = -sgn(g_{S2}/g_{S1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ1 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope on the '''SQ1 servo curve''' is determined by the ratio of the gains in the SQ1 servo and the MCE servo I term:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S1}) = -sgn(g_{S1}/I)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the sign of the locking slope on the '''SQ1 ramp''' curves is simply:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA} m_{S2} m_{S1}) = - sgn(1/I)&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2849</id>
		<title>Locking slopes</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2849"/>
		<updated>2009-10-19T19:41:50Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Plotting controls */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MCE/MAS parameters that affect locking slopes =&lt;br /&gt;
&lt;br /&gt;
== Slope controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters in [[Mce config template system | experiment.cfg]] affect the locking slopes:&lt;br /&gt;
&lt;br /&gt;
* '''sq2servo_gain''': sets the gain of the SQ2 servo and effectively determines the sign of the SA lock slope.&lt;br /&gt;
* '''sq1servo_gain''': sets the gain of the SQ1 servo and, with the sq2servo_gain, determines the SQ2 lock slope.&lt;br /&gt;
* '''default_servo_i''': determines the I gain of the MCE servo (rc# gaini#), and thus the sign of the locking slopeof the SQ1.&lt;br /&gt;
&lt;br /&gt;
== Plotting controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters affect plotting of locking slopes in IDL, as well as the choice of starting feedbacks for the next stage of servos:&lt;br /&gt;
&lt;br /&gt;
* '''sq2servo_slope''' in experiment.cfg: (+1 or -1) the sign of the slope in the SQ2 servo plots to which we expect to lock.&lt;br /&gt;
* '''sq1servo_slope''' in experiment.cfg: (+1 or -1) the sign of the slope in the SQ1 servo plots to which we expect to lock.&lt;br /&gt;
&lt;br /&gt;
In newer versions of auto-tuning, these parameters are ignored and the locking slope is determined from the signs of the servo gains.&lt;br /&gt;
&lt;br /&gt;
== Consistency between locking and plotting ==&lt;br /&gt;
&lt;br /&gt;
The above slope and plotting parameters should satisfy the following:&lt;br /&gt;
* sq2servo_slope =  -sign( sq2servo_gain / sq1servo_gain) &lt;br /&gt;
* sq1servo_slope =  -sign( sq1servo_gain / default_servo_i)&lt;br /&gt;
&lt;br /&gt;
These relations follow from the discussion in the sections below.&lt;br /&gt;
&lt;br /&gt;
Violation of the above will likely only result in misleading plots, and not bad locking.  Misleading plots can indirectly lead to a user setting up bad locking, however; so keep it clean.&lt;br /&gt;
&lt;br /&gt;
'''The sa_points.ps plot may be misleading''': older auto-tuning code (still in use all over the place) plots the positive-slope lock-points, regardless of any other parameters.  Newer auto-tuning code resolves this.&lt;br /&gt;
&lt;br /&gt;
= MCE and tuning servos =&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
We will need to deal with three servos.  One is the &amp;quot;MCE servo&amp;quot;, which is the fast servoing of the TES signal via adjustment of the SQ1 feedback.  The other two are the auto-tuning SQ2 and SQ1 servos, described [here | auto_setup_squids.pro]. &lt;br /&gt;
&lt;br /&gt;
In all cases, the servo is computed by measuring an error (&amp;lt;math&amp;gt;\Delta&amp;lt;/math&amp;gt; y), multiplying by a gain (g), and using this to correct the output (x):&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x = g~\Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the case of the MCE PID loop servo, we run with an I term only so we actually calculate&lt;br /&gt;
 &amp;lt;math&amp;gt;x = P ~\sum \Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but differentially this is exactly &amp;lt;math&amp;gt;\Delta x = P * \Delta y&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE/MAS and sneaky signs ==&lt;br /&gt;
&lt;br /&gt;
There are no sneaky, extra signs in any of the MCE/MAS servo calculations.  This means that given an error (dy) and a gain g, we calculate the change in the feedback (dx) as:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and not&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = -g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is a sneaky gain in the MCE servo, though; once the default_servo_i is set, the DAC value of the feedback is actually calculated as&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta FB = (I~dy) / 2^{12}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But there's no sneaky sign.  Just a sneaky gain.&lt;br /&gt;
&lt;br /&gt;
= The meaning of the plots =&lt;br /&gt;
&lt;br /&gt;
== Definition of a lock point ==&lt;br /&gt;
&lt;br /&gt;
Let the feedback signals on the three stages (in one channel) be &amp;lt;math&amp;gt;x_{SA}, x_{S2}, x_{S1}&amp;lt;/math&amp;gt;, and let the error signal be y.  Let s be the signal from the TES.  The error signal is obviously a function of all 4 numbers:&lt;br /&gt;
 &amp;lt;math&amp;gt;y = f(x_{SA}, x_{S2}, x_{S1}, t)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But for small variations about one point in this space, we can expand in differentials&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = a_1 dx_{SA} + a_2 dx_{S2} + a_3 dx_{S1} +  a_4 s&amp;lt;/math&amp;gt;&lt;br /&gt;
but it is convenient to reparametrize this to resemble the chain of amplifiers:&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = m_{SA}(dx_{SA} - m_{S2}(dx_{S2} - m_{S1}(dx_{S1} - m_{TES} s)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the 'slopes' m account for the instantaneous gain between the stages at the lock point.&lt;br /&gt;
&lt;br /&gt;
== Open loop ramps ==&lt;br /&gt;
&lt;br /&gt;
Note that lock points are not ultimately chosen as a result of the open loop ramps.  However, it is important to understand the relationship between what the open loop ramps and the settings for the auto-tuning and MCE servos.&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SA ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{S2}, x_{S1}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{SA}&amp;lt;/math&amp;gt;.  Thus identifying a lock point permits the measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{SA} = m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SQ1 ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{SA}, x_{S2}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{S1}&amp;lt;/math&amp;gt;.  A slope measurement on this curve is a measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{S1} = m_{SA} m_{S2} m_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
In servos, we ramp one stage's x while adjusting another x to keep the error at zero.&lt;br /&gt;
&lt;br /&gt;
Thus in the &amp;quot;SQ2 servo&amp;quot; step (where SQ2 FB is ramped and SQA FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{SA} = m_{S2} dx_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, this can only be accomplished via measurement of the error&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = -m_{SA} m_{S2} \Delta x_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
so operationally we apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{SA} = - \Delta y / m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the ideal gain of the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S2} = -1/m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;SQ1 servo&amp;quot; step (where SQ1 FB is ramped and SQ2 FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S2} = m_{S1} dx_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
so we measure&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = m_{SA} m_{S2} m_{S1} \Delta x_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
and apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S2} = \Delta y / (m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
so the ideal gain of the SQ1 servo is&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S1} = 1/(m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE servo I parameter ==&lt;br /&gt;
&lt;br /&gt;
When the MCE servo is activated, it cancels changes in TES current by adjusting the SQ1 FB:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S1} = m_{TES} ds&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
i.e.&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S1} = -\Delta y / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
and ideal gain is thus&lt;br /&gt;
 &amp;lt;math&amp;gt;I_{servo} = -1 / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Consequences for tuning parameters ==&lt;br /&gt;
&lt;br /&gt;
We have expressed, above, the ideal gains for the servos as a function of the slopes of the ramp and servo curves from auto-tuning.  Solving these for the slopes as a function of the ideal gains yields the locking slopes' dependence on the signs of the gains:&lt;br /&gt;
&lt;br /&gt;
=== SA locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SA ramp) is determined by the gain in the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA}) =  -sgn(1/g_{S2})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ2 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SQ2 servo curve) is determined by the ratio of the gains in the SQ1 and SQ2 servos:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S2}) = -sgn(g_{S2}/g_{S1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ1 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope on the '''SQ1 servo curve''' is determined by the ratio of the gains in the SQ1 servo and the MCE servo I term:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S1}) = -sgn(g_{S1}/I)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the sign of the locking slope on the '''SQ1 ramp''' curves is simply:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA} m_{S2} m_{S1}) = - sgn(1/I)&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2848</id>
		<title>Locking slopes</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2848"/>
		<updated>2009-10-19T19:41:17Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* SQ1 locking point */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MCE/MAS parameters that affect locking slopes =&lt;br /&gt;
&lt;br /&gt;
== Slope controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters in [[Mce config template system | experiment.cfg]] affect the locking slopes:&lt;br /&gt;
&lt;br /&gt;
* '''sq2servo_gain''': sets the gain of the SQ2 servo and effectively determines the sign of the SA lock slope.&lt;br /&gt;
* '''sq1servo_gain''': sets the gain of the SQ1 servo and, with the sq2servo_gain, determines the SQ2 lock slope.&lt;br /&gt;
* '''default_servo_i''': determines the I gain of the MCE servo (rc# gaini#), and thus the sign of the locking slopeof the SQ1.&lt;br /&gt;
&lt;br /&gt;
== Plotting controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters affect plotting of locking slopes in IDL, as well as the choice of starting feedbacks for the next stage of servos:&lt;br /&gt;
&lt;br /&gt;
* sq2servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ2 servo plots to which we expect to lock.&lt;br /&gt;
* sq1servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ1 servo plots to which we expect to lock.&lt;br /&gt;
&lt;br /&gt;
In newer versions of auto-tuning, these parameters are ignored and the locking slope is determined from the signs of the servo gains.&lt;br /&gt;
&lt;br /&gt;
== Consistency between locking and plotting ==&lt;br /&gt;
&lt;br /&gt;
The above slope and plotting parameters should satisfy the following:&lt;br /&gt;
* sq2servo_slope =  -sign( sq2servo_gain / sq1servo_gain) &lt;br /&gt;
* sq1servo_slope =  -sign( sq1servo_gain / default_servo_i)&lt;br /&gt;
&lt;br /&gt;
These relations follow from the discussion in the sections below.&lt;br /&gt;
&lt;br /&gt;
Violation of the above will likely only result in misleading plots, and not bad locking.  Misleading plots can indirectly lead to a user setting up bad locking, however; so keep it clean.&lt;br /&gt;
&lt;br /&gt;
'''The sa_points.ps plot may be misleading''': older auto-tuning code (still in use all over the place) plots the positive-slope lock-points, regardless of any other parameters.  Newer auto-tuning code resolves this.&lt;br /&gt;
&lt;br /&gt;
= MCE and tuning servos =&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
We will need to deal with three servos.  One is the &amp;quot;MCE servo&amp;quot;, which is the fast servoing of the TES signal via adjustment of the SQ1 feedback.  The other two are the auto-tuning SQ2 and SQ1 servos, described [here | auto_setup_squids.pro]. &lt;br /&gt;
&lt;br /&gt;
In all cases, the servo is computed by measuring an error (&amp;lt;math&amp;gt;\Delta&amp;lt;/math&amp;gt; y), multiplying by a gain (g), and using this to correct the output (x):&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x = g~\Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the case of the MCE PID loop servo, we run with an I term only so we actually calculate&lt;br /&gt;
 &amp;lt;math&amp;gt;x = P ~\sum \Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but differentially this is exactly &amp;lt;math&amp;gt;\Delta x = P * \Delta y&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE/MAS and sneaky signs ==&lt;br /&gt;
&lt;br /&gt;
There are no sneaky, extra signs in any of the MCE/MAS servo calculations.  This means that given an error (dy) and a gain g, we calculate the change in the feedback (dx) as:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and not&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = -g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is a sneaky gain in the MCE servo, though; once the default_servo_i is set, the DAC value of the feedback is actually calculated as&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta FB = (I~dy) / 2^{12}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But there's no sneaky sign.  Just a sneaky gain.&lt;br /&gt;
&lt;br /&gt;
= The meaning of the plots =&lt;br /&gt;
&lt;br /&gt;
== Definition of a lock point ==&lt;br /&gt;
&lt;br /&gt;
Let the feedback signals on the three stages (in one channel) be &amp;lt;math&amp;gt;x_{SA}, x_{S2}, x_{S1}&amp;lt;/math&amp;gt;, and let the error signal be y.  Let s be the signal from the TES.  The error signal is obviously a function of all 4 numbers:&lt;br /&gt;
 &amp;lt;math&amp;gt;y = f(x_{SA}, x_{S2}, x_{S1}, t)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But for small variations about one point in this space, we can expand in differentials&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = a_1 dx_{SA} + a_2 dx_{S2} + a_3 dx_{S1} +  a_4 s&amp;lt;/math&amp;gt;&lt;br /&gt;
but it is convenient to reparametrize this to resemble the chain of amplifiers:&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = m_{SA}(dx_{SA} - m_{S2}(dx_{S2} - m_{S1}(dx_{S1} - m_{TES} s)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the 'slopes' m account for the instantaneous gain between the stages at the lock point.&lt;br /&gt;
&lt;br /&gt;
== Open loop ramps ==&lt;br /&gt;
&lt;br /&gt;
Note that lock points are not ultimately chosen as a result of the open loop ramps.  However, it is important to understand the relationship between what the open loop ramps and the settings for the auto-tuning and MCE servos.&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SA ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{S2}, x_{S1}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{SA}&amp;lt;/math&amp;gt;.  Thus identifying a lock point permits the measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{SA} = m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SQ1 ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{SA}, x_{S2}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{S1}&amp;lt;/math&amp;gt;.  A slope measurement on this curve is a measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{S1} = m_{SA} m_{S2} m_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
In servos, we ramp one stage's x while adjusting another x to keep the error at zero.&lt;br /&gt;
&lt;br /&gt;
Thus in the &amp;quot;SQ2 servo&amp;quot; step (where SQ2 FB is ramped and SQA FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{SA} = m_{S2} dx_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, this can only be accomplished via measurement of the error&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = -m_{SA} m_{S2} \Delta x_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
so operationally we apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{SA} = - \Delta y / m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the ideal gain of the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S2} = -1/m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;SQ1 servo&amp;quot; step (where SQ1 FB is ramped and SQ2 FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S2} = m_{S1} dx_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
so we measure&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = m_{SA} m_{S2} m_{S1} \Delta x_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
and apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S2} = \Delta y / (m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
so the ideal gain of the SQ1 servo is&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S1} = 1/(m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE servo I parameter ==&lt;br /&gt;
&lt;br /&gt;
When the MCE servo is activated, it cancels changes in TES current by adjusting the SQ1 FB:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S1} = m_{TES} ds&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
i.e.&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S1} = -\Delta y / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
and ideal gain is thus&lt;br /&gt;
 &amp;lt;math&amp;gt;I_{servo} = -1 / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Consequences for tuning parameters ==&lt;br /&gt;
&lt;br /&gt;
We have expressed, above, the ideal gains for the servos as a function of the slopes of the ramp and servo curves from auto-tuning.  Solving these for the slopes as a function of the ideal gains yields the locking slopes' dependence on the signs of the gains:&lt;br /&gt;
&lt;br /&gt;
=== SA locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SA ramp) is determined by the gain in the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA}) =  -sgn(1/g_{S2})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ2 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SQ2 servo curve) is determined by the ratio of the gains in the SQ1 and SQ2 servos:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S2}) = -sgn(g_{S2}/g_{S1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ1 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope on the '''SQ1 servo curve''' is determined by the ratio of the gains in the SQ1 servo and the MCE servo I term:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S1}) = -sgn(g_{S1}/I)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the sign of the locking slope on the '''SQ1 ramp''' curves is simply:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA} m_{S2} m_{S1}) = - sgn(1/I)&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2847</id>
		<title>Locking slopes</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2847"/>
		<updated>2009-10-19T19:37:27Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Consistency between locking and plotting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MCE/MAS parameters that affect locking slopes =&lt;br /&gt;
&lt;br /&gt;
== Slope controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters in [[Mce config template system | experiment.cfg]] affect the locking slopes:&lt;br /&gt;
&lt;br /&gt;
* '''sq2servo_gain''': sets the gain of the SQ2 servo and effectively determines the sign of the SA lock slope.&lt;br /&gt;
* '''sq1servo_gain''': sets the gain of the SQ1 servo and, with the sq2servo_gain, determines the SQ2 lock slope.&lt;br /&gt;
* '''default_servo_i''': determines the I gain of the MCE servo (rc# gaini#), and thus the sign of the locking slopeof the SQ1.&lt;br /&gt;
&lt;br /&gt;
== Plotting controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters affect plotting of locking slopes in IDL, as well as the choice of starting feedbacks for the next stage of servos:&lt;br /&gt;
&lt;br /&gt;
* sq2servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ2 servo plots to which we expect to lock.&lt;br /&gt;
* sq1servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ1 servo plots to which we expect to lock.&lt;br /&gt;
&lt;br /&gt;
In newer versions of auto-tuning, these parameters are ignored and the locking slope is determined from the signs of the servo gains.&lt;br /&gt;
&lt;br /&gt;
== Consistency between locking and plotting ==&lt;br /&gt;
&lt;br /&gt;
The above slope and plotting parameters should satisfy the following:&lt;br /&gt;
* sq2servo_slope =  -sign( sq2servo_gain / sq1servo_gain) &lt;br /&gt;
* sq1servo_slope =  -sign( sq1servo_gain / default_servo_i)&lt;br /&gt;
&lt;br /&gt;
These relations follow from the discussion in the sections below.&lt;br /&gt;
&lt;br /&gt;
Violation of the above will likely only result in misleading plots, and not bad locking.  Misleading plots can indirectly lead to a user setting up bad locking, however; so keep it clean.&lt;br /&gt;
&lt;br /&gt;
'''The sa_points.ps plot may be misleading''': older auto-tuning code (still in use all over the place) plots the positive-slope lock-points, regardless of any other parameters.  Newer auto-tuning code resolves this.&lt;br /&gt;
&lt;br /&gt;
= MCE and tuning servos =&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
We will need to deal with three servos.  One is the &amp;quot;MCE servo&amp;quot;, which is the fast servoing of the TES signal via adjustment of the SQ1 feedback.  The other two are the auto-tuning SQ2 and SQ1 servos, described [here | auto_setup_squids.pro]. &lt;br /&gt;
&lt;br /&gt;
In all cases, the servo is computed by measuring an error (&amp;lt;math&amp;gt;\Delta&amp;lt;/math&amp;gt; y), multiplying by a gain (g), and using this to correct the output (x):&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x = g~\Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the case of the MCE PID loop servo, we run with an I term only so we actually calculate&lt;br /&gt;
 &amp;lt;math&amp;gt;x = P ~\sum \Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but differentially this is exactly &amp;lt;math&amp;gt;\Delta x = P * \Delta y&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE/MAS and sneaky signs ==&lt;br /&gt;
&lt;br /&gt;
There are no sneaky, extra signs in any of the MCE/MAS servo calculations.  This means that given an error (dy) and a gain g, we calculate the change in the feedback (dx) as:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and not&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = -g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is a sneaky gain in the MCE servo, though; once the default_servo_i is set, the DAC value of the feedback is actually calculated as&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta FB = (I~dy) / 2^{12}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But there's no sneaky sign.  Just a sneaky gain.&lt;br /&gt;
&lt;br /&gt;
= The meaning of the plots =&lt;br /&gt;
&lt;br /&gt;
== Definition of a lock point ==&lt;br /&gt;
&lt;br /&gt;
Let the feedback signals on the three stages (in one channel) be &amp;lt;math&amp;gt;x_{SA}, x_{S2}, x_{S1}&amp;lt;/math&amp;gt;, and let the error signal be y.  Let s be the signal from the TES.  The error signal is obviously a function of all 4 numbers:&lt;br /&gt;
 &amp;lt;math&amp;gt;y = f(x_{SA}, x_{S2}, x_{S1}, t)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But for small variations about one point in this space, we can expand in differentials&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = a_1 dx_{SA} + a_2 dx_{S2} + a_3 dx_{S1} +  a_4 s&amp;lt;/math&amp;gt;&lt;br /&gt;
but it is convenient to reparametrize this to resemble the chain of amplifiers:&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = m_{SA}(dx_{SA} - m_{S2}(dx_{S2} - m_{S1}(dx_{S1} - m_{TES} s)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the 'slopes' m account for the instantaneous gain between the stages at the lock point.&lt;br /&gt;
&lt;br /&gt;
== Open loop ramps ==&lt;br /&gt;
&lt;br /&gt;
Note that lock points are not ultimately chosen as a result of the open loop ramps.  However, it is important to understand the relationship between what the open loop ramps and the settings for the auto-tuning and MCE servos.&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SA ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{S2}, x_{S1}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{SA}&amp;lt;/math&amp;gt;.  Thus identifying a lock point permits the measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{SA} = m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SQ1 ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{SA}, x_{S2}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{S1}&amp;lt;/math&amp;gt;.  A slope measurement on this curve is a measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{S1} = m_{SA} m_{S2} m_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
In servos, we ramp one stage's x while adjusting another x to keep the error at zero.&lt;br /&gt;
&lt;br /&gt;
Thus in the &amp;quot;SQ2 servo&amp;quot; step (where SQ2 FB is ramped and SQA FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{SA} = m_{S2} dx_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, this can only be accomplished via measurement of the error&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = -m_{SA} m_{S2} \Delta x_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
so operationally we apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{SA} = - \Delta y / m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the ideal gain of the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S2} = -1/m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;SQ1 servo&amp;quot; step (where SQ1 FB is ramped and SQ2 FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S2} = m_{S1} dx_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
so we measure&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = m_{SA} m_{S2} m_{S1} \Delta x_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
and apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S2} = \Delta y / (m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
so the ideal gain of the SQ1 servo is&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S1} = 1/(m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE servo I parameter ==&lt;br /&gt;
&lt;br /&gt;
When the MCE servo is activated, it cancels changes in TES current by adjusting the SQ1 FB:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S1} = m_{TES} ds&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
i.e.&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S1} = -\Delta y / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
and ideal gain is thus&lt;br /&gt;
 &amp;lt;math&amp;gt;I_{servo} = -1 / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Consequences for tuning parameters ==&lt;br /&gt;
&lt;br /&gt;
We have expressed, above, the ideal gains for the servos as a function of the slopes of the ramp and servo curves from auto-tuning.  Solving these for the slopes as a function of the ideal gains yields the locking slopes' dependence on the signs of the gains:&lt;br /&gt;
&lt;br /&gt;
=== SA locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SA ramp) is determined by the gain in the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA}) =  -sgn(1/g_{S2})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ2 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SQ2 servo curve) is determined by the ratio of the gains in the SQ1 and SQ2 servos:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S2}) = -sgn(g_{S2}/g_{S1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ1 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope on the SQ1 servo curve is determined by the ratio of the gains in the SQ1 servo and the MCE servo I term:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S1}) = -sgn(g_{S1}/I)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the sign of the locking slope on the SQ1 ramp curve is simply:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA} m_{S2} m_{S1}) = - sgn(1/I)&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2846</id>
		<title>Locking slopes</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2846"/>
		<updated>2009-10-19T19:36:34Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Plotting controls */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MCE/MAS parameters that affect locking slopes =&lt;br /&gt;
&lt;br /&gt;
== Slope controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters in [[Mce config template system | experiment.cfg]] affect the locking slopes:&lt;br /&gt;
&lt;br /&gt;
* '''sq2servo_gain''': sets the gain of the SQ2 servo and effectively determines the sign of the SA lock slope.&lt;br /&gt;
* '''sq1servo_gain''': sets the gain of the SQ1 servo and, with the sq2servo_gain, determines the SQ2 lock slope.&lt;br /&gt;
* '''default_servo_i''': determines the I gain of the MCE servo (rc# gaini#), and thus the sign of the locking slopeof the SQ1.&lt;br /&gt;
&lt;br /&gt;
== Plotting controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters affect plotting of locking slopes in IDL, as well as the choice of starting feedbacks for the next stage of servos:&lt;br /&gt;
&lt;br /&gt;
* sq2servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ2 servo plots to which we expect to lock.&lt;br /&gt;
* sq1servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ1 servo plots to which we expect to lock.&lt;br /&gt;
&lt;br /&gt;
In newer versions of auto-tuning, these parameters are ignored and the locking slope is determined from the signs of the servo gains.&lt;br /&gt;
&lt;br /&gt;
== Consistency between locking and plotting ==&lt;br /&gt;
&lt;br /&gt;
The above slope and plotting parameters should satisfy the following:&lt;br /&gt;
* sq2servo_slope =  -sign( sq2servo_gain / sq1servo_gain) &lt;br /&gt;
* sq1servo_slope =  -sign( sq1servo_gain / default_servo_i)&lt;br /&gt;
&lt;br /&gt;
These relations follow from the discussion in the sections below.&lt;br /&gt;
&lt;br /&gt;
Violation of the above will likely only result in misleading plots, and not bad locking.  Misleading plots can indirectly lead to a user setting up bad locking, however; so keep it clean.&lt;br /&gt;
&lt;br /&gt;
'''The sa_points.ps plot may be misleading''': the code (at time of writing) plots the positive-slope lock-points, regardless of any other parameters.&lt;br /&gt;
&lt;br /&gt;
Future code will eliminate sq2servo_slope and sq1servo_slope and determine all locking slopes from the servo gains... &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MCE and tuning servos =&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
We will need to deal with three servos.  One is the &amp;quot;MCE servo&amp;quot;, which is the fast servoing of the TES signal via adjustment of the SQ1 feedback.  The other two are the auto-tuning SQ2 and SQ1 servos, described [here | auto_setup_squids.pro]. &lt;br /&gt;
&lt;br /&gt;
In all cases, the servo is computed by measuring an error (&amp;lt;math&amp;gt;\Delta&amp;lt;/math&amp;gt; y), multiplying by a gain (g), and using this to correct the output (x):&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x = g~\Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the case of the MCE PID loop servo, we run with an I term only so we actually calculate&lt;br /&gt;
 &amp;lt;math&amp;gt;x = P ~\sum \Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but differentially this is exactly &amp;lt;math&amp;gt;\Delta x = P * \Delta y&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE/MAS and sneaky signs ==&lt;br /&gt;
&lt;br /&gt;
There are no sneaky, extra signs in any of the MCE/MAS servo calculations.  This means that given an error (dy) and a gain g, we calculate the change in the feedback (dx) as:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and not&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = -g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is a sneaky gain in the MCE servo, though; once the default_servo_i is set, the DAC value of the feedback is actually calculated as&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta FB = (I~dy) / 2^{12}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But there's no sneaky sign.  Just a sneaky gain.&lt;br /&gt;
&lt;br /&gt;
= The meaning of the plots =&lt;br /&gt;
&lt;br /&gt;
== Definition of a lock point ==&lt;br /&gt;
&lt;br /&gt;
Let the feedback signals on the three stages (in one channel) be &amp;lt;math&amp;gt;x_{SA}, x_{S2}, x_{S1}&amp;lt;/math&amp;gt;, and let the error signal be y.  Let s be the signal from the TES.  The error signal is obviously a function of all 4 numbers:&lt;br /&gt;
 &amp;lt;math&amp;gt;y = f(x_{SA}, x_{S2}, x_{S1}, t)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But for small variations about one point in this space, we can expand in differentials&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = a_1 dx_{SA} + a_2 dx_{S2} + a_3 dx_{S1} +  a_4 s&amp;lt;/math&amp;gt;&lt;br /&gt;
but it is convenient to reparametrize this to resemble the chain of amplifiers:&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = m_{SA}(dx_{SA} - m_{S2}(dx_{S2} - m_{S1}(dx_{S1} - m_{TES} s)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the 'slopes' m account for the instantaneous gain between the stages at the lock point.&lt;br /&gt;
&lt;br /&gt;
== Open loop ramps ==&lt;br /&gt;
&lt;br /&gt;
Note that lock points are not ultimately chosen as a result of the open loop ramps.  However, it is important to understand the relationship between what the open loop ramps and the settings for the auto-tuning and MCE servos.&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SA ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{S2}, x_{S1}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{SA}&amp;lt;/math&amp;gt;.  Thus identifying a lock point permits the measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{SA} = m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SQ1 ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{SA}, x_{S2}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{S1}&amp;lt;/math&amp;gt;.  A slope measurement on this curve is a measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{S1} = m_{SA} m_{S2} m_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
In servos, we ramp one stage's x while adjusting another x to keep the error at zero.&lt;br /&gt;
&lt;br /&gt;
Thus in the &amp;quot;SQ2 servo&amp;quot; step (where SQ2 FB is ramped and SQA FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{SA} = m_{S2} dx_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, this can only be accomplished via measurement of the error&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = -m_{SA} m_{S2} \Delta x_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
so operationally we apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{SA} = - \Delta y / m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the ideal gain of the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S2} = -1/m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;SQ1 servo&amp;quot; step (where SQ1 FB is ramped and SQ2 FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S2} = m_{S1} dx_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
so we measure&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = m_{SA} m_{S2} m_{S1} \Delta x_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
and apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S2} = \Delta y / (m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
so the ideal gain of the SQ1 servo is&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S1} = 1/(m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE servo I parameter ==&lt;br /&gt;
&lt;br /&gt;
When the MCE servo is activated, it cancels changes in TES current by adjusting the SQ1 FB:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S1} = m_{TES} ds&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
i.e.&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S1} = -\Delta y / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
and ideal gain is thus&lt;br /&gt;
 &amp;lt;math&amp;gt;I_{servo} = -1 / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Consequences for tuning parameters ==&lt;br /&gt;
&lt;br /&gt;
We have expressed, above, the ideal gains for the servos as a function of the slopes of the ramp and servo curves from auto-tuning.  Solving these for the slopes as a function of the ideal gains yields the locking slopes' dependence on the signs of the gains:&lt;br /&gt;
&lt;br /&gt;
=== SA locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SA ramp) is determined by the gain in the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA}) =  -sgn(1/g_{S2})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ2 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SQ2 servo curve) is determined by the ratio of the gains in the SQ1 and SQ2 servos:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S2}) = -sgn(g_{S2}/g_{S1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ1 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope on the SQ1 servo curve is determined by the ratio of the gains in the SQ1 servo and the MCE servo I term:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S1}) = -sgn(g_{S1}/I)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the sign of the locking slope on the SQ1 ramp curve is simply:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA} m_{S2} m_{S1}) = - sgn(1/I)&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=PCI_card_firmware&amp;diff=2835</id>
		<title>PCI card firmware</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=PCI_card_firmware&amp;diff=2835"/>
		<updated>2009-10-02T08:28:51Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Download =&lt;br /&gt;
&lt;br /&gt;
* U0105 (latest) - http://e-mode.phas.ubc.ca/~mhasse/mce/SDSU_RevU0105.s&lt;br /&gt;
* U0104 (stable) - http://e-mode.phas.ubc.ca/~mhasse/mce/SDSU_RevU0104.s&lt;br /&gt;
&lt;br /&gt;
= Misc. =&lt;br /&gt;
&lt;br /&gt;
* [[ PCI card bug list ]]&lt;br /&gt;
* [[ PCI card hacking ]]&lt;br /&gt;
* [[ PCI card code assembly on Linux ]]&lt;br /&gt;
&lt;br /&gt;
= Firmware version notes =&lt;br /&gt;
&lt;br /&gt;
== Latest release: U0105 (2009-06-08) ==&lt;br /&gt;
&lt;br /&gt;
* Backward compatible with U0104.&lt;br /&gt;
* Support for MCE STOP commands and commands-on-the-fly.&lt;br /&gt;
* Accelerated MCE command code (along with Quiet-RP this increases commanding rate to ~6 kHz).&lt;br /&gt;
* Quiet-RP simplifies the protocol for MCE reply handling.&lt;br /&gt;
* Low-level improvements:&lt;br /&gt;
** CON is done as PCI burst&lt;br /&gt;
** Fibre-optic FIFO is emptied with timed read instead of polling.&lt;br /&gt;
** Hand-shaking for interrupts instead of host command to clear INTA and HC3.&lt;br /&gt;
** Non-interrupt context code disables interrupts when performing PCI transactions.&lt;br /&gt;
** Host vector interrupts are otherwise enabled, so PC doesn't have to force with HNMI bit.&lt;br /&gt;
&lt;br /&gt;
== Last stable version: U0104 ==&lt;br /&gt;
&lt;br /&gt;
* Implements quiet transfer mode!  Remains backwards compatible with A1.4.&lt;br /&gt;
* Fixes the 64k boundary crossing issue&lt;br /&gt;
* Moves parameters that enter via interrupt out of registers and into variables&lt;br /&gt;
* Version reporting tag-along to RDM command (sending 'VER' to RDM's vector address returns the code version).&lt;br /&gt;
* Maximum burst length is reduced to 64 bytes, and is configurable.&lt;br /&gt;
* Reset (RST) clears the fibre fifo&lt;br /&gt;
&lt;br /&gt;
== Oldest UBC release: U0103 ==&lt;br /&gt;
&lt;br /&gt;
* Minor modifications of SCUBA2's A1.4 firmware, to improve PCI stability.&lt;br /&gt;
* Not compatible with non-realtime systems.&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Rectangle_Mode_Data&amp;diff=2811</id>
		<title>Rectangle Mode Data</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Rectangle_Mode_Data&amp;diff=2811"/>
		<updated>2009-09-05T21:22:59Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;quot;Rectangle Mode&amp;quot; refers to the sampling of a subset of the full array, typically at high rate.  The data from the Readout Cards is packed into output frames efficiently to minimize overhead.  Rectangle mode is available in MCE firmware starting with RC 5.0.1 and CC 5.0.0.&lt;br /&gt;
&lt;br /&gt;
= Description of capabilities =&lt;br /&gt;
&lt;br /&gt;
Rectangle mode eliminates strain on the acquisition system during fast acquisitions by eliminating read-out overhead.  This means that the 'difficulty' of read-out is a fairly linear function of (sampling frequency) x (number of detectors read out) rather than depending on each. &lt;br /&gt;
&lt;br /&gt;
The hardware limit on readout is roughly 4 MB/s.  Since MCE data are 32-bit words, this permits 1e6 detector-samples to be read out per second.&lt;br /&gt;
&lt;br /&gt;
So the maximum number of detectors that can be sampled at some frequency F is&lt;br /&gt;
  D = (1 MHz) / F&lt;br /&gt;
&lt;br /&gt;
You can't sample at 1 MHz.  (Do your squids settle in 1us?  Didn't think so.)  But you could probably do a detector or two at 250 kHz.&lt;br /&gt;
&lt;br /&gt;
= Firmware =&lt;br /&gt;
&lt;br /&gt;
Rectangle mode requires &amp;quot;version 5&amp;quot; firmware on all cards, and at least RC 5.0.2.  Here are links to the recommended SOFs at time of writing:&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/ac_v05000000_22dec2008.sof&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/bc_v05000000_22dec2008.sof&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/cc_v05000002_16jun2009.sof&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/firmware/rc_v05000002_16jun2009.sof&lt;br /&gt;
&lt;br /&gt;
= Configuration =&lt;br /&gt;
&lt;br /&gt;
The steps for configuring a rectangle mode acquisition are:&lt;br /&gt;
# Set the multiplexing rate using num_rows and row_len&lt;br /&gt;
# If necessary, adjust row_order to mux the channels of interest (you can only read out rows you are multiplexing...) &lt;br /&gt;
# Identify a rectangle of detectors on the readout card to read out by setting the RC parameters&lt;br /&gt;
#* num_rows_reported, num_cols_reported, readout_row_index, readout_col_index&lt;br /&gt;
# Set the size of the readout frame by setting the CC parameters&lt;br /&gt;
#* num_rows_reported, num_cols_reported&lt;br /&gt;
# Set the CC decimation factor 'data_rate' so that the RC rectangles will stack perfectly into the CC readout frame.&lt;br /&gt;
#* e.g. suppose&lt;br /&gt;
#** RC num_rows_reported x num_cols_reported =  1x4 &lt;br /&gt;
#** CC num_rows_reported x num_cols_reported = 33x8&lt;br /&gt;
#* then we set &lt;br /&gt;
#** CC data_rate = (33 x 8) / (1 x 4) = 66&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Readout limitations =&lt;br /&gt;
&lt;br /&gt;
Rectangle mode configuration should respect the following hardware limits:&lt;br /&gt;
* Total data rate must not exceed 4 MB/s&lt;br /&gt;
* Read-out frequency must not exceed 20 kHz&lt;br /&gt;
* The multiplexing frame rate must not be set so fast that the MCE cannot communicate with the readout cards.  This limit is probably in the 100s of kHz.&lt;br /&gt;
&lt;br /&gt;
Other things to remember:&lt;br /&gt;
* num_rows &amp;gt;= 2 is encouraged.&lt;br /&gt;
* you can't sample a detector faster than it is being visited in the multiplexing cycle.&lt;br /&gt;
&lt;br /&gt;
= Checking MCE configuration using rect_check.py =&lt;br /&gt;
&lt;br /&gt;
Use the utility @rect_check.py@ to verify that data will be / were acquired reasonably.&lt;br /&gt;
&lt;br /&gt;
e.g. To check the state of the MCE (requires python MCE bindings), run&lt;br /&gt;
 rect_check.py --mce&lt;br /&gt;
&lt;br /&gt;
To analyze the data framing in a runfile:&lt;br /&gt;
 rect_check.py my_data.run&lt;br /&gt;
&lt;br /&gt;
(Depending on stuff, you might need to invoke rect_check as:&lt;br /&gt;
 $MAS_PYTHON/rect_check.py&lt;br /&gt;
or even&lt;br /&gt;
 python $MAS_PYTHON/rect_check.py&lt;br /&gt;
Sorry.)&lt;br /&gt;
&lt;br /&gt;
The output looks like this:&lt;br /&gt;
&lt;br /&gt;
 MCE configuration:&lt;br /&gt;
  cc_rcs   ( cc, rcs_to_report_data ):     60&lt;br /&gt;
  cc_dec   ( cc, data_rate ):             256&lt;br /&gt;
  cc_nmux  ( cc, num_rows ):               33&lt;br /&gt;
  cc_cmux  ( cc, row_len ):               100&lt;br /&gt;
  cc_nr    ( cc, num_rows_reported ):      32&lt;br /&gt;
  cc_nc    ( cc, num_cols_reported ):       8&lt;br /&gt;
  rc_nmux  ( rca, num_rows ):              33&lt;br /&gt;
  rc_cmux  ( rca, row_len ):              100&lt;br /&gt;
  rc_nr    ( rca, num_rows_reported ):      1&lt;br /&gt;
  rc_nc    ( rca, num_cols_reported ):      1&lt;br /&gt;
  rc_r0    ( rca, readout_row_index ):      0&lt;br /&gt;
  rc_c0    ( rca, readout_col_index ):      0&lt;br /&gt;
 Framing:&lt;br /&gt;
  RC storage per mux cycle:                 1&lt;br /&gt;
  CC read-out per frame:                  256&lt;br /&gt;
  CC decimation:                          256&lt;br /&gt;
  Contiguous?                             yes&lt;br /&gt;
  Complete?                                no&lt;br /&gt;
  Bizarro?                                 no&lt;br /&gt;
 Timing:&lt;br /&gt;
  Mux freq:                          15151.00&lt;br /&gt;
  Mean sampling freq:                15104.00&lt;br /&gt;
  Read-out freq:                        59.00&lt;br /&gt;
 Data volume:&lt;br /&gt;
  Frame size (bytes/RC):                 1200&lt;br /&gt;
  Data rate (MB/s/RC):                   0.07&lt;br /&gt;
&lt;br /&gt;
The program has notions of what is &amp;quot;reasonable&amp;quot;, and these are expressed in the lines &amp;quot;Contiguous?&amp;quot;, &amp;quot;Complete?&amp;quot;, and &amp;quot;Bizarro?&amp;quot;:&lt;br /&gt;
* 'Contiguous': all detectors that are read out will be read out at each multiplexing cycle&lt;br /&gt;
** When acquiring fast data from a subset of the detectors, at the multiplexing rate, you want &amp;quot;Contiguous = yes&amp;quot;.&lt;br /&gt;
* 'Complete': all detectors that are multiplexed will be read out&lt;br /&gt;
** When acquiring normal data, you probably want &amp;quot;Complete = yes&amp;quot;.&lt;br /&gt;
* 'Bizarro': the rectangle defined in the RC does not fit evenly into the readout frame.&lt;br /&gt;
** e.g. you have set up an 8x8 rectangle but you're reading CC frames that are 33x8.  Don't do this.  I'm not even sure what you'd get out. &lt;br /&gt;
&lt;br /&gt;
Note that it is possible to be none of Complete, Contiguous, or Bizarro.  For example, you could read out the first 33 of every 66 multiplexing cycles for 8 detectors, packing them efficiently into a 33 x 8 read-out frame.  Maybe that should be called Bizarro.  But right now, it isn't.&lt;br /&gt;
&lt;br /&gt;
It is unlikely, but possible, to be both Contiguous and Complete.&lt;br /&gt;
&lt;br /&gt;
If you are Bizarro, you are neither Contiguous nor Complete.  See Venn diagram below.&lt;br /&gt;
&lt;br /&gt;
[[Image:reasonable_rectangles.png]]&lt;br /&gt;
&lt;br /&gt;
= Data acquisition =&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;mce_run&amp;quot; in the usual way to acquire data.  Note that the argument specifying the number of frames is always the number of 'read-out' frames, so for packed data the number of samples per detector will be higher.&lt;br /&gt;
&lt;br /&gt;
e.g. for the above configuration&lt;br /&gt;
 mce_run my_data 100 1&lt;br /&gt;
&lt;br /&gt;
would acquire 100 read-out frames.  Since the read-out frequency is 59 Hz, this would take about 2 seconds.  Each readout frame contains 8 x 32 = 256 data from a single detector.  So the resulting data stream contains 25600 samples.&lt;br /&gt;
&lt;br /&gt;
= Data file loading =&lt;br /&gt;
&lt;br /&gt;
Recent versions of mce_data.py can extract rectangle mode data from the packed frame structure.  E.g. for the above case, extracting the data is as easy as&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = MCEFile('my_data').Read()&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data.shape&lt;br /&gt;
 (1, 25600)&lt;br /&gt;
&lt;br /&gt;
= Rather long explanation and justification of structure, from an e-mail =&lt;br /&gt;
&lt;br /&gt;
Yesterday Bryce and I were talking about paths towards a new rectangle readout mode.  The following is a recommendation for the rough structure of the system that I think will be easy to manage and provide a maximum flexibility for backwards compatibility and future expansion.&lt;br /&gt;
&lt;br /&gt;
The current rectangle mode is simpler than the planned one because the clock card and readout card need only agree on the number of data to readout, and no addditional waiting/synchronization is required between the clock card and readout card.  The readout frame data sizes, internally and externally, are the same for everyone.  The new mode is much more complex, because now the readout card has to accumulate several samples from each pixel into its internal buffer before sending the data to the clock card, and the clock card needs to ask for the right amount of data, which is probably some multiple of the rectangle size and is not necessarily a multiple of 8 or the number of multiplexing rows.&lt;br /&gt;
&lt;br /&gt;
Anyway, the point is that here is a simple and flexible way to parametrize the new mode parameters and manage synchronization, and to provide flexibility and backwards compatibility.&lt;br /&gt;
&lt;br /&gt;
1.  The meaning of num_rows remains unchanged.  It will always be a multiplexing parameter that all cards need to agree on.&lt;br /&gt;
&lt;br /&gt;
2.  The readout card has parameters (prepend &amp;quot;readout_&amp;quot; to all of these, if you want) &amp;quot;row_index&amp;quot;, &amp;quot;num_rows&amp;quot;, &amp;quot;col_index&amp;quot;, &amp;quot;num_cols&amp;quot; that describe the rectangle of interest.&lt;br /&gt;
&lt;br /&gt;
3. The clock card is programmed with a pair of numbers &amp;quot;readout_mult1&amp;quot; and &amp;quot;readout_mult2&amp;quot;, that it uses to determine how many words of data to query the RCs for:&lt;br /&gt;
   N_data = readout_mult1 * readout_mult2.&lt;br /&gt;
These numbers are analagous to &amp;quot;num_rows_reported&amp;quot; and &amp;quot;num_cols_reported&amp;quot;, but the idea is to kill the idea of &amp;quot;rows&amp;quot; and &amp;quot;columns&amp;quot; in the readout frames because the payload size is not a simple product of n_rows * n_cols.  The clock card continues to support &amp;quot;data rate&amp;quot;, which indicates the period at which data queries are sent to the RCs.  Software will handle the details of getting these factors right.  Eventually we will only use one of mult?; the other is for backwards compat.&lt;br /&gt;
&lt;br /&gt;
4. In the RC: at each mux frame, data from the desired rectangle is copied into a large buffer.  The RC continues filling the buffer until the CC asks for data.  When RC receives a request for N data from the CC, it returns the first N data in the buffer, and resets its write index to the start of the buffer.  If the CC doesn't ask for data, and the RC buffer write index increments all the way past the end, the RC takes _no storage action_ in subsequent steps (i.e. it writes all new data to &amp;quot;/dev/null&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Setting up rectangle mode then proceeds as follows.  Suppose the RC buffer size is 1600 and I want to readout a 4 x 33 patch of the array:&lt;br /&gt;
&lt;br /&gt;
1.  Software computes that 4x33 = 132 words fits into 1600 about 12 times.  So it sets &amp;quot;cc data_rate&amp;quot; to 12, and the product of &amp;quot;mult1&amp;quot; and &amp;quot;mult2&amp;quot; to 12 * 132 = 1584.  It also sets the readout card row and col rectangle parameters.&lt;br /&gt;
&lt;br /&gt;
2.  Software triggers frame acquisition.  For the _first_ frame read out, the clock card and readout card may not be synchronized; i.e. the readout card's buffer almost certainly contains ancient, stale data.  So the first frame is discarded.  But since the first frame query sent the the buffer write index to 0, the data from subsequent frames is fresh and ordered.  Because the clock card is asking for N data at the same rate that the RC can N-fill the buffer, this results in a contiguous data stream.&lt;br /&gt;
&lt;br /&gt;
This scheme is simple because:&lt;br /&gt;
1. CC has only enough information to ask the readout cards for the right amount of data at the right times.&lt;br /&gt;
2. RC only needs to know the rectangle of interest, and it basically lets the CC manage the resetting of the buffer.&lt;br /&gt;
3. It is backwards-compatible with existing firmware; mult1 and mult2 can masquerade as num_rows_reported and &amp;quot;8&amp;quot; (num_cols_reported).&lt;br /&gt;
&lt;br /&gt;
The scheme minimizes the amount of information that must be shared between the RC and CC, which provides flexiblity.  With &amp;quot;mult&amp;quot; approach, the CC can remain truly ignorant as to what the RC is doing.  In this scheme I have emphasized the rectangle mode features, but I also envision it being useful in raw mode firmware, since a lot of the features (such as a large, flexible RAM block in the RC) would seem useful in that context.  (For raw mode you would need to add a lock to the buffer so that it could be read out with multiple queries.)&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MAS_OS_setup&amp;diff=2731</id>
		<title>MAS OS setup</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MAS_OS_setup&amp;diff=2731"/>
		<updated>2009-06-11T16:23:41Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Install python stuff */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Ubuntu 6.06 LTS server''':  This is the most supported OS.  The instructions below are mostly for 6.06.&lt;br /&gt;
&lt;br /&gt;
'''Ubuntu 7.10 server''':  We can support this now.  Patched kernels are available.  In the text below, major deviations from the 6.06 installation procedure are identified.&lt;br /&gt;
&lt;br /&gt;
'''Ubuntu 8.04 LTS server''':  This version is new enough that the kernel build system isn't producing portable kernel packages.  MAS works with 8.04 but I don't want to install too many 8.04 systems until they clean up the build system.&lt;br /&gt;
&lt;br /&gt;
= Install additional ubuntu packages =&lt;br /&gt;
&lt;br /&gt;
== Disable CDROM seeking ==&lt;br /&gt;
&lt;br /&gt;
The package manager knows that you have the Ubuntu disk and will say things like&lt;br /&gt;
 Media change: please insert the disc labeled&lt;br /&gt;
 'Ubuntu-Server 6.06.1 _Dapper Drake_ - Release i386 (20060807.1)'&lt;br /&gt;
&lt;br /&gt;
To disable this (and download packages from the internet instead), open /etc/apt/sources.list &lt;br /&gt;
 sudo pico /etc/apt/sources.list&lt;br /&gt;
and remove (comment) the line &lt;br /&gt;
 deb cdrom:[Ubuntu-Server 6.06.1 _Dapper Drake_ - Release i386 (20060807.1)]/ dapper main restricted&lt;br /&gt;
&lt;br /&gt;
== Install required packages ==&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get update&lt;br /&gt;
 sudo apt-get install build-essential subversion emacs21 libreadline5-dev &lt;br /&gt;
&lt;br /&gt;
== Enable universe repository and install GGV ==&lt;br /&gt;
&lt;br /&gt;
Uncomment the line in /etc/apt/sources.list so it says &lt;br /&gt;
 deb http://us.archive.ubuntu.com/ubuntu/ dapper universe&lt;br /&gt;
&lt;br /&gt;
Then run&lt;br /&gt;
 sudo apt-get update&lt;br /&gt;
 sudo apt-get install gnome-gv&lt;br /&gt;
&lt;br /&gt;
gnome-gv doesn't exist on 7.10, you'll have to settle for&lt;br /&gt;
 sudo apt-get install gv&lt;br /&gt;
&lt;br /&gt;
== Install packages that you shouldn't even want to install (soon to be optional) ==&lt;br /&gt;
 sudo apt-get install tcsh&lt;br /&gt;
&lt;br /&gt;
== Install desktop manager (optional) ==&lt;br /&gt;
 sudo apt-get install ubuntu-desktop gdm&lt;br /&gt;
&lt;br /&gt;
== Install python stuff ==&lt;br /&gt;
&lt;br /&gt;
The 'pyth' branch MAS has experimental support for python using wx and matplotlib:&lt;br /&gt;
 sudo apt-get install python-dev python-wxglade python-matplotlib python-numarray-ext swig&lt;br /&gt;
&lt;br /&gt;
For loading / plotting MCE data in python using [[Python data and runfile modules | mce_data.py]], you will want numpy / scipy:&lt;br /&gt;
 sudo apt-get install python-numpy python-scipy &lt;br /&gt;
&lt;br /&gt;
For Ubuntu 6.06, numpy and scipy can be obtained following instructions from this page:&lt;br /&gt;
 http://debs.astraw.com/dapper/&lt;br /&gt;
&lt;br /&gt;
On more recent, but not new, Ubuntu (e.g. 8.10), you may want to install a more current version of numpy.  The easiest way to do this seems to get source code from&lt;br /&gt;
 http://sourceforge.net/projects/numpy&lt;br /&gt;
unzip and run&lt;br /&gt;
 ./setup.py config&lt;br /&gt;
 ./setup.py build&lt;br /&gt;
 sudo ./setup.py install&lt;br /&gt;
The config step may complain that it can't find BLAS and ATLAS, but that's ok because the numpy source has scaled-down substitutes.&lt;br /&gt;
&lt;br /&gt;
== Install unpackaged libraries ==&lt;br /&gt;
&lt;br /&gt;
MAS uses libconfig to manage its configuration files.  The webpage is here: [ http://www.hyperrealm.com/libconfig/ ].  To install libconfig run the following:&lt;br /&gt;
&lt;br /&gt;
  wget http://www.hyperrealm.com/libconfig/libconfig-1.3.tar.gz&lt;br /&gt;
  tar -xzf libconfig-1.3.tar.gz&lt;br /&gt;
  cd libconfig-1.3&lt;br /&gt;
  ./configure&lt;br /&gt;
  make&lt;br /&gt;
  sudo make install&lt;br /&gt;
&lt;br /&gt;
To make the system aware of this library, add &amp;quot;/usr/local/lib&amp;quot; to /etc/ld.so.conf and run &amp;quot;sudo ldconfig&amp;quot;.  i.e.&lt;br /&gt;
  echo /usr/local/lib | sudo tee -a /etc/ld.so.conf&lt;br /&gt;
  sudo ldconfig&lt;br /&gt;
&lt;br /&gt;
On newer systems (Ubuntu 7.10) you can do this instead:&lt;br /&gt;
  echo /usr/local/include | sudo tee /etc/ld.so.conf.d/libconfig.conf&lt;br /&gt;
  sudo ldconfig&lt;br /&gt;
&lt;br /&gt;
= Download and install MAS kernel patch =&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
&lt;br /&gt;
If you're not compiling the kernel from scratch, download the binary packages from UBC:&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/kernel-headers-2.6.15.7-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/kernel-image-2.6.15.7-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/extras.patch&lt;br /&gt;
&lt;br /&gt;
For '''Ubuntu 7.10''', get these instead:&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/linux-headers-2.6.22.9-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/linux-image-2.6.22.9-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On '''Ubuntu 7.10''' machines '''without PAE''' hardware (i.e. a maximum of 4G of system memory) use:&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/linux-headers-2.6.22.14-bigphys_2.6.22.14-bigphys-10.00.Custom_i386.deb&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/linux-image-2.6.22.14-bigphys_2.6.22.14-bigphys-10.00.Custom_i386.deb&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
&lt;br /&gt;
Then, install the packages using dpkg:&lt;br /&gt;
 sudo dpkg -i kernel-headers-2.6.15.7-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 sudo dpkg -i kernel-image-2.6.15.7-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
The &amp;quot;image&amp;quot; file might complain about symbolic links, no big deal.&lt;br /&gt;
&lt;br /&gt;
On '''Ubuntu 7.10''', instead install these:&lt;br /&gt;
 sudo dpkg -i linux-headers-2.6.22.9-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 sudo dpkg -i linux-image-2.6.22.9-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
&lt;br /&gt;
Why are these ones called &amp;quot;linux&amp;quot; instead of &amp;quot;kernel&amp;quot;?  I think it's because I got them from Ubuntu repositories instead of kernel.org.&lt;br /&gt;
&lt;br /&gt;
On '''Ubuntu 7.10''' machines '''without PAE''' install these:&lt;br /&gt;
 sudo dpkg -i linux-headers-2.6.22.14-bigphys_2.6.22.14-bigphys-10.00.Custom_i386.deb&lt;br /&gt;
 sudo dpkg -i linux-image-2.6.22.14-bigphys_2.6.22.14-bigphys-10.00.Custom_i386.deb&lt;br /&gt;
&lt;br /&gt;
The '''Ubuntu 8.04''' kernel has a sound-card driver that lays claim to the Motorola DSP on the PCI card.  We have to blacklist this module to prevent it from trying to configure the card as a sound card.  Add the following to the bottom of /etc/modprobe.d/blacklist :&lt;br /&gt;
 # Conflicts with Astro-cam PCI card!!&lt;br /&gt;
 blacklist snd_asihpi&lt;br /&gt;
&lt;br /&gt;
== Patch ==&lt;br /&gt;
&lt;br /&gt;
This makes it possible to compile against the kernel package as though it had been locally compiled originally.&lt;br /&gt;
 cd /usr/src/kernel-headers-2.6.15.7-bigphys/&lt;br /&gt;
 sudo patch -p1 &amp;lt; ~/extras.patch&lt;br /&gt;
&lt;br /&gt;
This step is not necessary for Ubuntu 7.10.  It may be necessary to link the kernel headers into /lib/modules:&lt;br /&gt;
  sudo ln -s /usr/src/linux-headers-2.6.22.9-bigphys/ /lib/modules/2.6.22.9-bigphys/build&lt;br /&gt;
&lt;br /&gt;
== Boot menu ==&lt;br /&gt;
&lt;br /&gt;
We need to add the kernel option that causes bigphys to allocate boot memory for our driver.  In older versions of MAS (especially ACT's stable release) we also need to disable &amp;quot;acpi&amp;quot;.  It's a good idea to not run any DSP/MCE commands until all of your kernel options are in place. &lt;br /&gt;
&lt;br /&gt;
Having installed the kernel &amp;quot;image&amp;quot; package, the kernel should show up in the boot loader (grub)'s kernel list.&lt;br /&gt;
&lt;br /&gt;
=== Editing the kernel list ===&lt;br /&gt;
As root (or using sudo), edit the file /boot/grub/menu.lst .  &lt;br /&gt;
 sudo pico /boot/grub/menu.lst&lt;br /&gt;
Go to the list of kernels, below the line &amp;quot;## ## End Default Options ##&amp;quot;, and find the new kernel entry.  On Ubuntu 6.06, it should be the third block (index 2), and look like this:&lt;br /&gt;
&lt;br /&gt;
 title           Ubuntu, kernel 2.6.15.7-bigphys&lt;br /&gt;
 root            (hd0,0)&lt;br /&gt;
 kernel          /vmlinuz-2.6.15.7-bigphys root=/dev/sda3 ro quiet splash&lt;br /&gt;
 initrd          /initrd.img-2.6.15.7-bigphys&lt;br /&gt;
 savedefault&lt;br /&gt;
 boot&lt;br /&gt;
&lt;br /&gt;
Add the kernel options to the &amp;quot;kernel&amp;quot; line, producing either this (recent MAS):&lt;br /&gt;
 kernel          /vmlinuz-2.6.15.7-bigphys root=/dev/sda3 ro quiet splash bigphysarea=8192&lt;br /&gt;
or this (old MAS, esp. ACT):&lt;br /&gt;
 kernel          /vmlinuz-2.6.15.7-bigphys root=/dev/sda3 ro quiet splash bigphysarea=8192 acpi=off&lt;br /&gt;
&lt;br /&gt;
Save and close the file, and reboot to test this kernel.  If the kernel &amp;quot;works&amp;quot;, you can edit menu.lst again and change the value of the &amp;quot;default&amp;quot; option to point to this kernel:&lt;br /&gt;
 default    2&lt;br /&gt;
&lt;br /&gt;
'''Ubuntu 7.10 and later''': the kernel packages install a bit differently so the block will likely be the first one in the list.  The 'kernel' line  must change from something like&lt;br /&gt;
 kernel          /boot/vmlinuz-2.6.22.9-bigphys root=UUID=1b6e7b54-894d-4571-9f0a-527fe0103975 ro quiet splash&lt;br /&gt;
to&lt;br /&gt;
 kernel          /boot/vmlinuz-2.6.22.9-bigphys root=UUID=1b6e7b54-894d-4571-9f0a-527fe0103975 ro quiet splash bigphysarea=8192&lt;br /&gt;
Note that the long hexadecimal serial numbers are system specifc and yours are probably different than these ones.  Leave them as they are and just add the new kernel options.  The &amp;quot;default&amp;quot; option will probably be&lt;br /&gt;
 default    0&lt;br /&gt;
but it's a good idea to count these things out for yourself.&lt;br /&gt;
&lt;br /&gt;
= Configure the system for mce users = &lt;br /&gt;
&lt;br /&gt;
== Permissions and umask ==&lt;br /&gt;
&lt;br /&gt;
Set the umask for all users to give write access for their group by default.&lt;br /&gt;
&lt;br /&gt;
Edit /etc/profile and change the &amp;quot;umask 022&amp;quot; line to&lt;br /&gt;
 umask 002&lt;br /&gt;
&lt;br /&gt;
Edit /etc/login.defs and find the line that start &amp;quot;# UMASK&amp;quot; and change it to&lt;br /&gt;
 UMASK           002&lt;br /&gt;
&lt;br /&gt;
Any users wishing to use MCE under their own accounts should be added to the &amp;quot;mce&amp;quot; group and should have &amp;quot;mce&amp;quot; as their primary group.  Their umask must be set properly, or other users will not be free to manipulate shared files.&lt;br /&gt;
&lt;br /&gt;
To setup additional system users, see the page on [[MAS user setup]].&lt;br /&gt;
&lt;br /&gt;
== Folders ==&lt;br /&gt;
&lt;br /&gt;
This is the sort of thing that should be done by an install script...&lt;br /&gt;
&lt;br /&gt;
Data directory:&lt;br /&gt;
 sudo mkdir /data&lt;br /&gt;
 sudo chown mce:mce /data&lt;br /&gt;
 sudo chmod g+ws /data&lt;br /&gt;
 mkdir /data/cryo/&lt;br /&gt;
&lt;br /&gt;
Configuration directory:&lt;br /&gt;
 sudo mkdir /etc/mce&lt;br /&gt;
 sudo chgrp mce /etc/mce&lt;br /&gt;
 sudo chmod g+ws /etc/mce&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= If necessary, branch MAS and mce_script =&lt;br /&gt;
&lt;br /&gt;
You can work with a complete checked-out tree, or not.&lt;br /&gt;
&lt;br /&gt;
In the first case:&lt;br /&gt;
&lt;br /&gt;
 svn checkout svn://e-mode.phas.ubc.ca/mas&lt;br /&gt;
 svn copy mas/trunk mas/branch/{your_project_name}&lt;br /&gt;
 svn commit mas&lt;br /&gt;
&lt;br /&gt;
Alternately, do the copy directly on the svn server (it is automatically committed):&lt;br /&gt;
 svn copy svn://e-mode.phas.ubc.ca/mas/trunk svn://e-mode.phas.ubc.ca/mas/branch/{your_project_name}&lt;br /&gt;
&lt;br /&gt;
For mce_script, replace &amp;quot;mas&amp;quot; with &amp;quot;mce_script&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Then check out the appropriate branch (or the whole tree) on the new machine.&lt;br /&gt;
&lt;br /&gt;
= Download (checkout) MAS and mce_script =&lt;br /&gt;
&lt;br /&gt;
See the page on [[ MAS svn repository ]]&lt;br /&gt;
&lt;br /&gt;
= Compile and install MAS =&lt;br /&gt;
&lt;br /&gt;
== Build the driver ==&lt;br /&gt;
&lt;br /&gt;
By default, the driver will build with bigphysarea support enabled.  To override build options, create a file Makefile.local in the &amp;quot;driver&amp;quot; folder, and add lines like:&lt;br /&gt;
&lt;br /&gt;
 # BIGPHYS=0 disables bigphysarea frame-buffering&lt;br /&gt;
 BIGPHYS = 0&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 # FAKEMCE=1 provides simple emulation of a PCI card/MCE for testing&lt;br /&gt;
 FAKEMCE = 1&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 # REALTIME=1 makes use of realtime interrupt routines&lt;br /&gt;
 REALTIME = 1&lt;br /&gt;
&lt;br /&gt;
In Makefiles, there should not be comments on the same line as the variable definitions.  On a system running the bigphys kernel with the correct PCI card, Makefile.local will be created at compile time if it does not already exist.  It can be left empty.&lt;br /&gt;
&lt;br /&gt;
Anyway, once Makefile.local is setup, type&lt;br /&gt;
 cd mas&lt;br /&gt;
 make clean; make&lt;br /&gt;
&lt;br /&gt;
From the driver folder we can test the driver:&lt;br /&gt;
 cd driver&lt;br /&gt;
 ./reload&lt;br /&gt;
 ./mknodes&lt;br /&gt;
&lt;br /&gt;
Note that since &amp;quot;reload&amp;quot; first unloads the driver if it is present, and then loads the driver from the current folder, it may report an &amp;quot;ERROR&amp;quot; message if the first step fails, even though the driver is successfully loaded.  The definitive way to check that the driver is loaded is&lt;br /&gt;
  cat /proc/mce_dsp&lt;br /&gt;
&lt;br /&gt;
If this file does not exist, the driver isn't loaded.  If the cat prints out a bunch of low-level driver information, you're in good shape.&lt;br /&gt;
&lt;br /&gt;
If you're satisfied that the driver works, install the driver with the command&lt;br /&gt;
&lt;br /&gt;
 sudo make install&lt;br /&gt;
&lt;br /&gt;
This should put mce_dsp.ko into /lib/modules/2.6.15.7-bigphys/kernel/drivers/misc/, and re-scan the module dependencies.  To get the driver to load on boot you must add manually the following lines to /etc/rc.local:&lt;br /&gt;
&lt;br /&gt;
 modprobe mce_dsp&lt;br /&gt;
 /home/mce/mas/driver/mknodes&lt;br /&gt;
 sudo -u mce /usr/mce/bin/maslog_server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Install MAS config files ==&lt;br /&gt;
&lt;br /&gt;
Hardware and binary config files live in /etc/mce/ (created above).&lt;br /&gt;
&lt;br /&gt;
Make sure you use the hardware config (mce_*.cfg) file appropriate for your system.  Racks with 4 readout cards should use mce_v1.cfg; small sub-racks with readout card slots should use mce_v2.cfg.   &lt;br /&gt;
&lt;br /&gt;
 cd ~/mas/config&lt;br /&gt;
 cp mce_v1.cfg /etc/mce/mce.cfg&lt;br /&gt;
 cp mas.cfg /etc/mce/mas.cfg&lt;br /&gt;
&lt;br /&gt;
= Install mce_script =&lt;br /&gt;
&lt;br /&gt;
The mce_script files are designed so that users can fairly easily run a different set of scripts.  We will install a system default set in /usr/mce/mce_script&lt;br /&gt;
&lt;br /&gt;
 cd /usr/mce&lt;br /&gt;
 svn checkout svn://e-mode.phas.ubc.ca/mce_script/branch/{your_experiment} mce_script&lt;br /&gt;
&lt;br /&gt;
Current experiments include ACT and SPIDER.&lt;br /&gt;
&lt;br /&gt;
== mas_env.bash ==&lt;br /&gt;
&lt;br /&gt;
To set up the environment and path to use these scripts and idl codes, a user should do &amp;quot;source mas_env.bash&amp;quot;.  (This file used to live in mas/config, but has been moved into mce_script/template.)  Non-developer users can source /usr/mce/mce_script/template/mas_env.bash directly; advanced users may want to keep their own copy (or several different copies) in their home folder.&lt;br /&gt;
&lt;br /&gt;
Note that MAS/mce_script scripts should *not* source mas_env.bash!  The whole point of it is that paths should be flexible.&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
To have bash start up with the MAS variables defined, and the paths ready, add the following lines to .bashrc :&lt;br /&gt;
&lt;br /&gt;
 export MAS_ROOT=/usr/mce/mce_script/&lt;br /&gt;
 source $MAS_ROOT/template/mas_env.bash&lt;br /&gt;
 export IDL_PATH=&amp;quot;&amp;lt;IDL_DEFAULT&amp;gt;:$MAS_IDL/mas&amp;quot;&lt;br /&gt;
&lt;br /&gt;
While you're in there, you may want to define a few aliases.  In particular, I always uncomment the alias ll='ls-l' line.&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MAS_PC_specifications_email_template&amp;diff=2711</id>
		<title>MAS PC specifications email template</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MAS_PC_specifications_email_template&amp;diff=2711"/>
		<updated>2009-06-08T22:55:00Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MAS should run without difficulty on any modern PC that has a standard PCI slot and can run Ubuntu 8.04.  In particular, MAS now supports 64-bit and multi-core machines.  We have run MAS on fairly weak machines (1 GHz single core w/ 1GB RAM), but during detector characterization phases users will probably prefer a much more powerful desktop machine with lots of speed and graphics support.&lt;br /&gt;
&lt;br /&gt;
Note also that MCE data can take up quite a bit of disk space; 1024 channels of 400 Hz will pile up at 1.6 MB/s.  If your data rate is comparable to this then your system should have at least 500 GB of space for MCE data.&lt;br /&gt;
&lt;br /&gt;
Again, each MCE requires a PCI slot for the fibre-optic interface board!  Some new motherboards do not have standard PCI slots, as PCI-express is becoming more popular.&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MCE_flat-file_format&amp;diff=2663</id>
		<title>MCE flat-file format</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MCE_flat-file_format&amp;diff=2663"/>
		<updated>2009-06-03T20:52:39Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Frame status bits */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document describes one of MAS/MCE's output file formats.  The &amp;quot;DAS flat-file&amp;quot; format is closely related to the form that frame data have when they arrive at the PC from the MCE.  This format has many weaknesses as far as end users are concerned.  Only flat-files with &amp;quot;header version 6&amp;quot; are described here.&lt;br /&gt;
&lt;br /&gt;
The data consist of any number of &amp;quot;frames&amp;quot;.  In a given flat-file, all frames should have the same size.  The frame size can be determined from the first 28 bytes of the file.  No MCE flat-file will be shorter than 28 bytes.&lt;br /&gt;
&lt;br /&gt;
The natural data unit of MCE data is the 32-bit unsigned integer.  We refer to 32-bit integers as &amp;quot;words&amp;quot;.  All offsets are expressed in terms of words, and should be multiplied by 4 to get the byte offset.&lt;br /&gt;
&lt;br /&gt;
An MCE/DAS frame, up to and including header version 6, consists of the following:&lt;br /&gt;
&lt;br /&gt;
* 43 words of header information&lt;br /&gt;
* 8*R*N words of data, where N is the number of readout cards reporting and R is the number of rows reporting.&lt;br /&gt;
* 1 word of checksum information&lt;br /&gt;
&lt;br /&gt;
= Frame header =&lt;br /&gt;
&lt;br /&gt;
The frame header is 43 words long.  The table below describes the most useful fields in the header.  Esoteric fields are omitted; absent offsets are not necessarily unused.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;5&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Offset !! Name !! Category !! Detail&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Frame status bits || Status/Structure || described below&lt;br /&gt;
|-&lt;br /&gt;
| 1 || CC frame counter || Status || internal counter, starts at the value of &amp;quot;cc ret_dat_s&amp;quot; and increments by 1 for each output frame.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || row_len || Timing || Dwell time of the multiplexer on each row, in units of 1/50 MHz&lt;br /&gt;
|-&lt;br /&gt;
| 3 || num_rows_reported || Structure || Number of rows in each column that are reported in each output frame.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || data_rate || Timing || Number of internal frames that MCE processes before outputting one to the user.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || CC ARZ counter || Timing || internal counter, counts number of address-return-to-zero (ARZ) or number of internal frames.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || header version || Structure || 6, the number &amp;quot;six&amp;quot;.  Subject to change in future header versions.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || ramp value || Status || Current value of the internal ramping parameter&lt;br /&gt;
|-&lt;br /&gt;
| 8 || ramp address || Status || Card and parameter address of the internal ramping parameter (bits [31-16] are card_addr, bits [15-0] are param_id)&lt;br /&gt;
|-&lt;br /&gt;
| 9 || num_rows || Timing || Number of rows that the MCE is servoing&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Sync box number || Status || Synchronization number, originating at the sync box, that is used to synchronize data from multiple MCEs and the housekeeping system&lt;br /&gt;
|-&lt;br /&gt;
| 11 || run_id || Status || Contents of &amp;quot;cc run_id&amp;quot;, typically the ctime (unix time) associated with the acquisition.&lt;br /&gt;
|-&lt;br /&gt;
| 12 || user_word || Status || Contents of &amp;quot;cc user_word&amp;quot;, which the user may use to store other significant information.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A more complete description of the version 6 frame header can be found in the document &amp;quot;MCE File Formats&amp;quot;, version 3.3:&lt;br /&gt;
&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/index.html&lt;br /&gt;
&lt;br /&gt;
This document is out of date in some respects, but the descriptions of the frame headers up to version 6 should be accurate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame status bits ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;5&amp;quot;&lt;br /&gt;
! Bit !! Category !! Detail&lt;br /&gt;
|-&lt;br /&gt;
|  0 || Status || Last frame bit, indicates that current acquisition cycle has completed.  This does not necessarily indicate the last frame in a flat-file.&lt;br /&gt;
|-&lt;br /&gt;
|  1 || Status || Stop bit, indicates that MCE was commanded to stop acquisition and this is the last frame.&lt;br /&gt;
|-&lt;br /&gt;
|  2 || Status || Sync box free run mode bit, indicates that sync box is generating the data valid information (rather than accepting an external trigger)&lt;br /&gt;
|-&lt;br /&gt;
|  3 || Status || Sync box error bit.&lt;br /&gt;
|-&lt;br /&gt;
|  4 || Status || TES bias square wave level (not present in most firmware)&lt;br /&gt;
|-&lt;br /&gt;
|  10 || Structure || Readout card 1 data are present.&lt;br /&gt;
|-&lt;br /&gt;
|  11 || Structure || Readout card 2 data are present.&lt;br /&gt;
|-&lt;br /&gt;
|  12 || Structure || Readout card 3 data are present.&lt;br /&gt;
|-&lt;br /&gt;
|  13 || Structure || Readout card 4 data are present.&lt;br /&gt;
|-&lt;br /&gt;
|  19:16 (v7 only!) || Structure || Number of columns returning data, per readout card.  Reads as 0 in v6.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Bits 10-13 and 16-19 are especially relevant for determining the frame size and data structure.&lt;br /&gt;
&lt;br /&gt;
== Timing parameters ==&lt;br /&gt;
&lt;br /&gt;
The internal frame rate of the MCE (the rate at which a given row is servoed) and the output frame rate of the MCE (the rate at which frames are returned to the PC and recorded to disk) can be calculated as follows:&lt;br /&gt;
&lt;br /&gt;
 f_internal = 50 MHz / (num_rows * row_len)&lt;br /&gt;
 f_output   = f_internal / data_rate&lt;br /&gt;
&lt;br /&gt;
== Structure determination ==&lt;br /&gt;
&lt;br /&gt;
The size and structure of the readout data block can be determined from&lt;br /&gt;
* num_rows_reported&lt;br /&gt;
* bits 10-13 of the frame status bits, which we will call RC1_on, RC2_on, RC3_on, RC4_on (each taking a value of 1 or 0)&lt;br /&gt;
&lt;br /&gt;
In particular we can determine the number of readout cards reporting, as&lt;br /&gt;
&lt;br /&gt;
 N_card = (RC1_on + RC2_on + RC3_on + RC4_on)&lt;br /&gt;
&lt;br /&gt;
and this gives the size of the readout data block, in words, as&lt;br /&gt;
&lt;br /&gt;
 N_data = 8 * num_rows_reported * N_card&lt;br /&gt;
&lt;br /&gt;
with 8 representing the number of columns managed by each readout card.&lt;br /&gt;
&lt;br /&gt;
The organization of the frame data is described in the next section.&lt;br /&gt;
&lt;br /&gt;
= Frame data =&lt;br /&gt;
&lt;br /&gt;
== Normal acquisitions (row / column) ==&lt;br /&gt;
&lt;br /&gt;
By &amp;quot;normal acquisitions&amp;quot;, we mean everything except data mode 3.&lt;br /&gt;
&lt;br /&gt;
Each word of MCE data is associated with a unique row and column in the multiplexing scheme.  Each readout card is responsible for 8 columns and up to 41 rows.  Columns 0-7 are associated with readout card 1, columns 8-15 are associated with readout card 2, and so on.  MCE can support up to 32 columns.&lt;br /&gt;
&lt;br /&gt;
Schematically, the data is organized like this (with rNNcMM indicating the data assoicated with row NN and column MM):&lt;br /&gt;
&lt;br /&gt;
 r00c00 r00c01 r00c02 ... r00c31&lt;br /&gt;
 r01c00 r01c00 r01c02 ... r01c31&lt;br /&gt;
 ...&lt;br /&gt;
 r40c00 r40c01 r40c02 ... r40c31&lt;br /&gt;
&lt;br /&gt;
When num_rows_reported is less than 41, then the data for rows &amp;gt;= num_rows_reported is omitted.  When a readout card is not reporting data, the data for its associated columns are omitted.  For example, if num_rows_reported is 20 and only RC2 is reporting data then the frame structure is&lt;br /&gt;
&lt;br /&gt;
 r00c08 r00c09 r00c10 ... r00c15&lt;br /&gt;
 r01c08 r01c09 r01c10 ... r01c15&lt;br /&gt;
 r02c08 r02c09 r02c10 ... r02c15&lt;br /&gt;
 ...&lt;br /&gt;
 r19c08 r19c09 r19c10 ... r19c15&lt;br /&gt;
&lt;br /&gt;
Mathematically, the data for row R can be found starting at index&lt;br /&gt;
 I_R = R * N_card * 8&lt;br /&gt;
&lt;br /&gt;
The adjustment to this index to get the data associated with column C depends on which cards are reporting data.&lt;br /&gt;
&lt;br /&gt;
Note that currently MCE only supports single-card and all-card modes; so the slightly more complicated cases of, for example, reporting from readout cards 2 and 4 are not available.  The format described here does uniquely specify a way of handling those cases, however.&lt;br /&gt;
&lt;br /&gt;
= Checksum =&lt;br /&gt;
&lt;br /&gt;
The checksum word is the result of a cumulative XOR of all other words in the frame, including the header.  Since the XOR of any number with itself is zero, the cumulative XOR of all words in the frame (including the header, data, and checksum) should be zero.&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MCE_flat-file_format&amp;diff=2662</id>
		<title>MCE flat-file format</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MCE_flat-file_format&amp;diff=2662"/>
		<updated>2009-06-03T20:52:18Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Frame status bits */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This document describes one of MAS/MCE's output file formats.  The &amp;quot;DAS flat-file&amp;quot; format is closely related to the form that frame data have when they arrive at the PC from the MCE.  This format has many weaknesses as far as end users are concerned.  Only flat-files with &amp;quot;header version 6&amp;quot; are described here.&lt;br /&gt;
&lt;br /&gt;
The data consist of any number of &amp;quot;frames&amp;quot;.  In a given flat-file, all frames should have the same size.  The frame size can be determined from the first 28 bytes of the file.  No MCE flat-file will be shorter than 28 bytes.&lt;br /&gt;
&lt;br /&gt;
The natural data unit of MCE data is the 32-bit unsigned integer.  We refer to 32-bit integers as &amp;quot;words&amp;quot;.  All offsets are expressed in terms of words, and should be multiplied by 4 to get the byte offset.&lt;br /&gt;
&lt;br /&gt;
An MCE/DAS frame, up to and including header version 6, consists of the following:&lt;br /&gt;
&lt;br /&gt;
* 43 words of header information&lt;br /&gt;
* 8*R*N words of data, where N is the number of readout cards reporting and R is the number of rows reporting.&lt;br /&gt;
* 1 word of checksum information&lt;br /&gt;
&lt;br /&gt;
= Frame header =&lt;br /&gt;
&lt;br /&gt;
The frame header is 43 words long.  The table below describes the most useful fields in the header.  Esoteric fields are omitted; absent offsets are not necessarily unused.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;5&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Offset !! Name !! Category !! Detail&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Frame status bits || Status/Structure || described below&lt;br /&gt;
|-&lt;br /&gt;
| 1 || CC frame counter || Status || internal counter, starts at the value of &amp;quot;cc ret_dat_s&amp;quot; and increments by 1 for each output frame.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || row_len || Timing || Dwell time of the multiplexer on each row, in units of 1/50 MHz&lt;br /&gt;
|-&lt;br /&gt;
| 3 || num_rows_reported || Structure || Number of rows in each column that are reported in each output frame.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || data_rate || Timing || Number of internal frames that MCE processes before outputting one to the user.&lt;br /&gt;
|-&lt;br /&gt;
| 5 || CC ARZ counter || Timing || internal counter, counts number of address-return-to-zero (ARZ) or number of internal frames.&lt;br /&gt;
|-&lt;br /&gt;
| 6 || header version || Structure || 6, the number &amp;quot;six&amp;quot;.  Subject to change in future header versions.&lt;br /&gt;
|-&lt;br /&gt;
| 7 || ramp value || Status || Current value of the internal ramping parameter&lt;br /&gt;
|-&lt;br /&gt;
| 8 || ramp address || Status || Card and parameter address of the internal ramping parameter (bits [31-16] are card_addr, bits [15-0] are param_id)&lt;br /&gt;
|-&lt;br /&gt;
| 9 || num_rows || Timing || Number of rows that the MCE is servoing&lt;br /&gt;
|-&lt;br /&gt;
| 10 || Sync box number || Status || Synchronization number, originating at the sync box, that is used to synchronize data from multiple MCEs and the housekeeping system&lt;br /&gt;
|-&lt;br /&gt;
| 11 || run_id || Status || Contents of &amp;quot;cc run_id&amp;quot;, typically the ctime (unix time) associated with the acquisition.&lt;br /&gt;
|-&lt;br /&gt;
| 12 || user_word || Status || Contents of &amp;quot;cc user_word&amp;quot;, which the user may use to store other significant information.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A more complete description of the version 6 frame header can be found in the document &amp;quot;MCE File Formats&amp;quot;, version 3.3:&lt;br /&gt;
&lt;br /&gt;
 http://www.phas.ubc.ca/%7Emce/mcedocs/index.html&lt;br /&gt;
&lt;br /&gt;
This document is out of date in some respects, but the descriptions of the frame headers up to version 6 should be accurate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame status bits ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;5&amp;quot;&lt;br /&gt;
! Bit !! Category !! Detail&lt;br /&gt;
|-&lt;br /&gt;
|  0 || Status || Last frame bit, indicates that current acquisition cycle has completed.  This does not necessarily indicate the last frame in a flat-file.&lt;br /&gt;
|-&lt;br /&gt;
|  1 || Status || Stop bit, indicates that MCE was commanded to stop acquisition and this is the last frame.&lt;br /&gt;
|-&lt;br /&gt;
|  2 || Status || Sync box free run mode bit, indicates that sync box is generating the data valid information (rather than accepting an external trigger)&lt;br /&gt;
|-&lt;br /&gt;
|  3 || Status || Sync box error bit.&lt;br /&gt;
|-&lt;br /&gt;
|  4 || Status || TES bias square wave level (not present in most firmware)&lt;br /&gt;
|-&lt;br /&gt;
|  10 || Structure || Readout card 1 data are present.&lt;br /&gt;
|-&lt;br /&gt;
|  11 || Structure || Readout card 2 data are present.&lt;br /&gt;
|-&lt;br /&gt;
|  12 || Structure || Readout card 3 data are present.&lt;br /&gt;
|-&lt;br /&gt;
|  13 || Structure || Readout card 4 data are present.&lt;br /&gt;
|-&lt;br /&gt;
|  19:16 (v7 only!) || Structure || Number of columns returning data.  Reads as 0 in v6.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Bits 10-13 and 16-19 are especially relevant for determining the frame size and data structure.&lt;br /&gt;
&lt;br /&gt;
== Timing parameters ==&lt;br /&gt;
&lt;br /&gt;
The internal frame rate of the MCE (the rate at which a given row is servoed) and the output frame rate of the MCE (the rate at which frames are returned to the PC and recorded to disk) can be calculated as follows:&lt;br /&gt;
&lt;br /&gt;
 f_internal = 50 MHz / (num_rows * row_len)&lt;br /&gt;
 f_output   = f_internal / data_rate&lt;br /&gt;
&lt;br /&gt;
== Structure determination ==&lt;br /&gt;
&lt;br /&gt;
The size and structure of the readout data block can be determined from&lt;br /&gt;
* num_rows_reported&lt;br /&gt;
* bits 10-13 of the frame status bits, which we will call RC1_on, RC2_on, RC3_on, RC4_on (each taking a value of 1 or 0)&lt;br /&gt;
&lt;br /&gt;
In particular we can determine the number of readout cards reporting, as&lt;br /&gt;
&lt;br /&gt;
 N_card = (RC1_on + RC2_on + RC3_on + RC4_on)&lt;br /&gt;
&lt;br /&gt;
and this gives the size of the readout data block, in words, as&lt;br /&gt;
&lt;br /&gt;
 N_data = 8 * num_rows_reported * N_card&lt;br /&gt;
&lt;br /&gt;
with 8 representing the number of columns managed by each readout card.&lt;br /&gt;
&lt;br /&gt;
The organization of the frame data is described in the next section.&lt;br /&gt;
&lt;br /&gt;
= Frame data =&lt;br /&gt;
&lt;br /&gt;
== Normal acquisitions (row / column) ==&lt;br /&gt;
&lt;br /&gt;
By &amp;quot;normal acquisitions&amp;quot;, we mean everything except data mode 3.&lt;br /&gt;
&lt;br /&gt;
Each word of MCE data is associated with a unique row and column in the multiplexing scheme.  Each readout card is responsible for 8 columns and up to 41 rows.  Columns 0-7 are associated with readout card 1, columns 8-15 are associated with readout card 2, and so on.  MCE can support up to 32 columns.&lt;br /&gt;
&lt;br /&gt;
Schematically, the data is organized like this (with rNNcMM indicating the data assoicated with row NN and column MM):&lt;br /&gt;
&lt;br /&gt;
 r00c00 r00c01 r00c02 ... r00c31&lt;br /&gt;
 r01c00 r01c00 r01c02 ... r01c31&lt;br /&gt;
 ...&lt;br /&gt;
 r40c00 r40c01 r40c02 ... r40c31&lt;br /&gt;
&lt;br /&gt;
When num_rows_reported is less than 41, then the data for rows &amp;gt;= num_rows_reported is omitted.  When a readout card is not reporting data, the data for its associated columns are omitted.  For example, if num_rows_reported is 20 and only RC2 is reporting data then the frame structure is&lt;br /&gt;
&lt;br /&gt;
 r00c08 r00c09 r00c10 ... r00c15&lt;br /&gt;
 r01c08 r01c09 r01c10 ... r01c15&lt;br /&gt;
 r02c08 r02c09 r02c10 ... r02c15&lt;br /&gt;
 ...&lt;br /&gt;
 r19c08 r19c09 r19c10 ... r19c15&lt;br /&gt;
&lt;br /&gt;
Mathematically, the data for row R can be found starting at index&lt;br /&gt;
 I_R = R * N_card * 8&lt;br /&gt;
&lt;br /&gt;
The adjustment to this index to get the data associated with column C depends on which cards are reporting data.&lt;br /&gt;
&lt;br /&gt;
Note that currently MCE only supports single-card and all-card modes; so the slightly more complicated cases of, for example, reporting from readout cards 2 and 4 are not available.  The format described here does uniquely specify a way of handling those cases, however.&lt;br /&gt;
&lt;br /&gt;
= Checksum =&lt;br /&gt;
&lt;br /&gt;
The checksum word is the result of a cumulative XOR of all other words in the frame, including the header.  Since the XOR of any number with itself is zero, the cumulative XOR of all words in the frame (including the header, data, and checksum) should be zero.&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MAS_OS_setup&amp;diff=2661</id>
		<title>MAS OS setup</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=MAS_OS_setup&amp;diff=2661"/>
		<updated>2009-06-03T17:19:18Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Install python stuff */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Ubuntu 6.06 LTS server''':  This is the most supported OS.  The instructions below are mostly for 6.06.&lt;br /&gt;
&lt;br /&gt;
'''Ubuntu 7.10 server''':  We can support this now.  Patched kernels are available.  In the text below, major deviations from the 6.06 installation procedure are identified.&lt;br /&gt;
&lt;br /&gt;
'''Ubuntu 8.04 LTS server''':  This version is new enough that the kernel build system isn't producing portable kernel packages.  MAS works with 8.04 but I don't want to install too many 8.04 systems until they clean up the build system.&lt;br /&gt;
&lt;br /&gt;
= Install additional ubuntu packages =&lt;br /&gt;
&lt;br /&gt;
== Disable CDROM seeking ==&lt;br /&gt;
&lt;br /&gt;
The package manager knows that you have the Ubuntu disk and will say things like&lt;br /&gt;
 Media change: please insert the disc labeled&lt;br /&gt;
 'Ubuntu-Server 6.06.1 _Dapper Drake_ - Release i386 (20060807.1)'&lt;br /&gt;
&lt;br /&gt;
To disable this (and download packages from the internet instead), open /etc/apt/sources.list &lt;br /&gt;
 sudo pico /etc/apt/sources.list&lt;br /&gt;
and remove (comment) the line &lt;br /&gt;
 deb cdrom:[Ubuntu-Server 6.06.1 _Dapper Drake_ - Release i386 (20060807.1)]/ dapper main restricted&lt;br /&gt;
&lt;br /&gt;
== Install required packages ==&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get update&lt;br /&gt;
 sudo apt-get install build-essential subversion emacs21 libreadline5-dev &lt;br /&gt;
&lt;br /&gt;
== Enable universe repository and install GGV ==&lt;br /&gt;
&lt;br /&gt;
Uncomment the line in /etc/apt/sources.list so it says &lt;br /&gt;
 deb http://us.archive.ubuntu.com/ubuntu/ dapper universe&lt;br /&gt;
&lt;br /&gt;
Then run&lt;br /&gt;
 sudo apt-get update&lt;br /&gt;
 sudo apt-get install gnome-gv&lt;br /&gt;
&lt;br /&gt;
gnome-gv doesn't exist on 7.10, you'll have to settle for&lt;br /&gt;
 sudo apt-get install gv&lt;br /&gt;
&lt;br /&gt;
== Install packages that you shouldn't even want to install (soon to be optional) ==&lt;br /&gt;
 sudo apt-get install tcsh&lt;br /&gt;
&lt;br /&gt;
== Install desktop manager (optional) ==&lt;br /&gt;
 sudo apt-get install ubuntu-desktop gdm&lt;br /&gt;
&lt;br /&gt;
== Install python stuff ==&lt;br /&gt;
&lt;br /&gt;
The 'pyth' branch MAS has experimental support for python using wx and matplotlib:&lt;br /&gt;
 sudo apt-get install python-dev python-wxglade python-matplotlib python-numarray-ext swig&lt;br /&gt;
&lt;br /&gt;
For loading / plotting MCE data in python using [[Python data and runfile modules | mce_data.py]], you will want numpy / scipy:&lt;br /&gt;
 sudo apt-get install python-numpy python-scipy &lt;br /&gt;
&lt;br /&gt;
For Ubuntu 6.06, numpy and scipy can be obtained following instructions from this page:&lt;br /&gt;
 http://debs.astraw.com/dapper/&lt;br /&gt;
&lt;br /&gt;
== Install unpackaged libraries ==&lt;br /&gt;
&lt;br /&gt;
MAS uses libconfig to manage its configuration files.  The webpage is here: [ http://www.hyperrealm.com/libconfig/ ].  To install libconfig run the following:&lt;br /&gt;
&lt;br /&gt;
  wget http://www.hyperrealm.com/libconfig/libconfig-1.3.tar.gz&lt;br /&gt;
  tar -xzf libconfig-1.3.tar.gz&lt;br /&gt;
  cd libconfig-1.3&lt;br /&gt;
  ./configure&lt;br /&gt;
  make&lt;br /&gt;
  sudo make install&lt;br /&gt;
&lt;br /&gt;
To make the system aware of this library, add &amp;quot;/usr/local/lib&amp;quot; to /etc/ld.so.conf and run &amp;quot;sudo ldconfig&amp;quot;.  i.e.&lt;br /&gt;
  echo /usr/local/lib | sudo tee -a /etc/ld.so.conf&lt;br /&gt;
  sudo ldconfig&lt;br /&gt;
&lt;br /&gt;
On newer systems (Ubuntu 7.10) you can do this instead:&lt;br /&gt;
  echo /usr/local/include | sudo tee /etc/ld.so.conf.d/libconfig.conf&lt;br /&gt;
  sudo ldconfig&lt;br /&gt;
&lt;br /&gt;
= Download and install MAS kernel patch =&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
&lt;br /&gt;
If you're not compiling the kernel from scratch, download the binary packages from UBC:&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/kernel-headers-2.6.15.7-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/kernel-image-2.6.15.7-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/extras.patch&lt;br /&gt;
&lt;br /&gt;
For '''Ubuntu 7.10''', get these instead:&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/linux-headers-2.6.22.9-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/linux-image-2.6.22.9-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On '''Ubuntu 7.10''' machines '''without PAE''' hardware (i.e. a maximum of 4G of system memory) use:&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/linux-headers-2.6.22.14-bigphys_2.6.22.14-bigphys-10.00.Custom_i386.deb&lt;br /&gt;
 wget http://e-mode.phas.ubc.ca/~mhasse/mce/linux-image-2.6.22.14-bigphys_2.6.22.14-bigphys-10.00.Custom_i386.deb&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
&lt;br /&gt;
Then, install the packages using dpkg:&lt;br /&gt;
 sudo dpkg -i kernel-headers-2.6.15.7-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 sudo dpkg -i kernel-image-2.6.15.7-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
The &amp;quot;image&amp;quot; file might complain about symbolic links, no big deal.&lt;br /&gt;
&lt;br /&gt;
On '''Ubuntu 7.10''', instead install these:&lt;br /&gt;
 sudo dpkg -i linux-headers-2.6.22.9-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
 sudo dpkg -i linux-image-2.6.22.9-bigphys_10.00.Custom_i386.deb&lt;br /&gt;
&lt;br /&gt;
Why are these ones called &amp;quot;linux&amp;quot; instead of &amp;quot;kernel&amp;quot;?  I think it's because I got them from Ubuntu repositories instead of kernel.org.&lt;br /&gt;
&lt;br /&gt;
On '''Ubuntu 7.10''' machines '''without PAE''' install these:&lt;br /&gt;
 sudo dpkg -i linux-headers-2.6.22.14-bigphys_2.6.22.14-bigphys-10.00.Custom_i386.deb&lt;br /&gt;
 sudo dpkg -i linux-image-2.6.22.14-bigphys_2.6.22.14-bigphys-10.00.Custom_i386.deb&lt;br /&gt;
&lt;br /&gt;
The '''Ubuntu 8.04''' kernel has a sound-card driver that lays claim to the Motorola DSP on the PCI card.  We have to blacklist this module to prevent it from trying to configure the card as a sound card.  Add the following to the bottom of /etc/modprobe.d/blacklist :&lt;br /&gt;
 # Conflicts with Astro-cam PCI card!!&lt;br /&gt;
 blacklist snd_asihpi&lt;br /&gt;
&lt;br /&gt;
== Patch ==&lt;br /&gt;
&lt;br /&gt;
This makes it possible to compile against the kernel package as though it had been locally compiled originally.&lt;br /&gt;
 cd /usr/src/kernel-headers-2.6.15.7-bigphys/&lt;br /&gt;
 sudo patch -p1 &amp;lt; ~/extras.patch&lt;br /&gt;
&lt;br /&gt;
This step is not necessary for Ubuntu 7.10.  It may be necessary to link the kernel headers into /lib/modules:&lt;br /&gt;
  sudo ln -s /usr/src/linux-headers-2.6.22.9-bigphys/ /lib/modules/2.6.22.9-bigphys/build&lt;br /&gt;
&lt;br /&gt;
== Boot menu ==&lt;br /&gt;
&lt;br /&gt;
We need to add the kernel option that causes bigphys to allocate boot memory for our driver.  In older versions of MAS (especially ACT's stable release) we also need to disable &amp;quot;acpi&amp;quot;.  It's a good idea to not run any DSP/MCE commands until all of your kernel options are in place. &lt;br /&gt;
&lt;br /&gt;
Having installed the kernel &amp;quot;image&amp;quot; package, the kernel should show up in the boot loader (grub)'s kernel list.&lt;br /&gt;
&lt;br /&gt;
=== Editing the kernel list ===&lt;br /&gt;
As root (or using sudo), edit the file /boot/grub/menu.lst .  &lt;br /&gt;
 sudo pico /boot/grub/menu.lst&lt;br /&gt;
Go to the list of kernels, below the line &amp;quot;## ## End Default Options ##&amp;quot;, and find the new kernel entry.  On Ubuntu 6.06, it should be the third block (index 2), and look like this:&lt;br /&gt;
&lt;br /&gt;
 title           Ubuntu, kernel 2.6.15.7-bigphys&lt;br /&gt;
 root            (hd0,0)&lt;br /&gt;
 kernel          /vmlinuz-2.6.15.7-bigphys root=/dev/sda3 ro quiet splash&lt;br /&gt;
 initrd          /initrd.img-2.6.15.7-bigphys&lt;br /&gt;
 savedefault&lt;br /&gt;
 boot&lt;br /&gt;
&lt;br /&gt;
Add the kernel options to the &amp;quot;kernel&amp;quot; line, producing either this (recent MAS):&lt;br /&gt;
 kernel          /vmlinuz-2.6.15.7-bigphys root=/dev/sda3 ro quiet splash bigphysarea=8192&lt;br /&gt;
or this (old MAS, esp. ACT):&lt;br /&gt;
 kernel          /vmlinuz-2.6.15.7-bigphys root=/dev/sda3 ro quiet splash bigphysarea=8192 acpi=off&lt;br /&gt;
&lt;br /&gt;
Save and close the file, and reboot to test this kernel.  If the kernel &amp;quot;works&amp;quot;, you can edit menu.lst again and change the value of the &amp;quot;default&amp;quot; option to point to this kernel:&lt;br /&gt;
 default    2&lt;br /&gt;
&lt;br /&gt;
'''Ubuntu 7.10 and later''': the kernel packages install a bit differently so the block will likely be the first one in the list.  The 'kernel' line  must change from something like&lt;br /&gt;
 kernel          /boot/vmlinuz-2.6.22.9-bigphys root=UUID=1b6e7b54-894d-4571-9f0a-527fe0103975 ro quiet splash&lt;br /&gt;
to&lt;br /&gt;
 kernel          /boot/vmlinuz-2.6.22.9-bigphys root=UUID=1b6e7b54-894d-4571-9f0a-527fe0103975 ro quiet splash bigphysarea=8192&lt;br /&gt;
Note that the long hexadecimal serial numbers are system specifc and yours are probably different than these ones.  Leave them as they are and just add the new kernel options.  The &amp;quot;default&amp;quot; option will probably be&lt;br /&gt;
 default    0&lt;br /&gt;
but it's a good idea to count these things out for yourself.&lt;br /&gt;
&lt;br /&gt;
= Configure the system for mce users = &lt;br /&gt;
&lt;br /&gt;
== Permissions and umask ==&lt;br /&gt;
&lt;br /&gt;
Set the umask for all users to give write access for their group by default.&lt;br /&gt;
&lt;br /&gt;
Edit /etc/profile and change the &amp;quot;umask 022&amp;quot; line to&lt;br /&gt;
 umask 002&lt;br /&gt;
&lt;br /&gt;
Edit /etc/login.defs and find the line that start &amp;quot;# UMASK&amp;quot; and change it to&lt;br /&gt;
 UMASK           002&lt;br /&gt;
&lt;br /&gt;
Any users wishing to use MCE under their own accounts should be added to the &amp;quot;mce&amp;quot; group and should have &amp;quot;mce&amp;quot; as their primary group.  Their umask must be set properly, or other users will not be free to manipulate shared files.&lt;br /&gt;
&lt;br /&gt;
To setup additional system users, see the page on [[MAS user setup]].&lt;br /&gt;
&lt;br /&gt;
== Folders ==&lt;br /&gt;
&lt;br /&gt;
This is the sort of thing that should be done by an install script...&lt;br /&gt;
&lt;br /&gt;
Data directory:&lt;br /&gt;
 sudo mkdir /data&lt;br /&gt;
 sudo chown mce:mce /data&lt;br /&gt;
 sudo chmod g+ws /data&lt;br /&gt;
 mkdir /data/cryo/&lt;br /&gt;
&lt;br /&gt;
Configuration directory:&lt;br /&gt;
 sudo mkdir /etc/mce&lt;br /&gt;
 sudo chgrp mce /etc/mce&lt;br /&gt;
 sudo chmod g+ws /etc/mce&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= If necessary, branch MAS and mce_script =&lt;br /&gt;
&lt;br /&gt;
You can work with a complete checked-out tree, or not.&lt;br /&gt;
&lt;br /&gt;
In the first case:&lt;br /&gt;
&lt;br /&gt;
 svn checkout svn://e-mode.phas.ubc.ca/mas&lt;br /&gt;
 svn copy mas/trunk mas/branch/{your_project_name}&lt;br /&gt;
 svn commit mas&lt;br /&gt;
&lt;br /&gt;
Alternately, do the copy directly on the svn server (it is automatically committed):&lt;br /&gt;
 svn copy svn://e-mode.phas.ubc.ca/mas/trunk svn://e-mode.phas.ubc.ca/mas/branch/{your_project_name}&lt;br /&gt;
&lt;br /&gt;
For mce_script, replace &amp;quot;mas&amp;quot; with &amp;quot;mce_script&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Then check out the appropriate branch (or the whole tree) on the new machine.&lt;br /&gt;
&lt;br /&gt;
= Download (checkout) MAS and mce_script =&lt;br /&gt;
&lt;br /&gt;
See the page on [[ MAS svn repository ]]&lt;br /&gt;
&lt;br /&gt;
= Compile and install MAS =&lt;br /&gt;
&lt;br /&gt;
== Build the driver ==&lt;br /&gt;
&lt;br /&gt;
By default, the driver will build with bigphysarea support enabled.  To override build options, create a file Makefile.local in the &amp;quot;driver&amp;quot; folder, and add lines like:&lt;br /&gt;
&lt;br /&gt;
 # BIGPHYS=0 disables bigphysarea frame-buffering&lt;br /&gt;
 BIGPHYS = 0&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 # FAKEMCE=1 provides simple emulation of a PCI card/MCE for testing&lt;br /&gt;
 FAKEMCE = 1&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 # REALTIME=1 makes use of realtime interrupt routines&lt;br /&gt;
 REALTIME = 1&lt;br /&gt;
&lt;br /&gt;
In Makefiles, there should not be comments on the same line as the variable definitions.  On a system running the bigphys kernel with the correct PCI card, Makefile.local will be created at compile time if it does not already exist.  It can be left empty.&lt;br /&gt;
&lt;br /&gt;
Anyway, once Makefile.local is setup, type&lt;br /&gt;
 cd mas&lt;br /&gt;
 make clean; make&lt;br /&gt;
&lt;br /&gt;
From the driver folder we can test the driver:&lt;br /&gt;
 cd driver&lt;br /&gt;
 ./reload&lt;br /&gt;
 ./mknodes&lt;br /&gt;
&lt;br /&gt;
Note that since &amp;quot;reload&amp;quot; first unloads the driver if it is present, and then loads the driver from the current folder, it may report an &amp;quot;ERROR&amp;quot; message if the first step fails, even though the driver is successfully loaded.  The definitive way to check that the driver is loaded is&lt;br /&gt;
  cat /proc/mce_dsp&lt;br /&gt;
&lt;br /&gt;
If this file does not exist, the driver isn't loaded.  If the cat prints out a bunch of low-level driver information, you're in good shape.&lt;br /&gt;
&lt;br /&gt;
If you're satisfied that the driver works, install the driver with the command&lt;br /&gt;
&lt;br /&gt;
 sudo make install&lt;br /&gt;
&lt;br /&gt;
This should put mce_dsp.ko into /lib/modules/2.6.15.7-bigphys/kernel/drivers/misc/, and re-scan the module dependencies.  To get the driver to load on boot you must add manually the following lines to /etc/rc.local:&lt;br /&gt;
&lt;br /&gt;
 modprobe mce_dsp&lt;br /&gt;
 /home/mce/mas/driver/mknodes&lt;br /&gt;
 sudo -u mce /usr/mce/bin/maslog_server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Install MAS config files ==&lt;br /&gt;
&lt;br /&gt;
Hardware and binary config files live in /etc/mce/ (created above).&lt;br /&gt;
&lt;br /&gt;
Make sure you use the hardware config (mce_*.cfg) file appropriate for your system.  Racks with 4 readout cards should use mce_v1.cfg; small sub-racks with readout card slots should use mce_v2.cfg.   &lt;br /&gt;
&lt;br /&gt;
 cd ~/mas/config&lt;br /&gt;
 cp mce_v1.cfg /etc/mce/mce.cfg&lt;br /&gt;
 cp mas.cfg /etc/mce/mas.cfg&lt;br /&gt;
&lt;br /&gt;
= Install mce_script =&lt;br /&gt;
&lt;br /&gt;
The mce_script files are designed so that users can fairly easily run a different set of scripts.  We will install a system default set in /usr/mce/mce_script&lt;br /&gt;
&lt;br /&gt;
 cd /usr/mce&lt;br /&gt;
 svn checkout svn://e-mode.phas.ubc.ca/mce_script/branch/{your_experiment} mce_script&lt;br /&gt;
&lt;br /&gt;
Current experiments include ACT and SPIDER.&lt;br /&gt;
&lt;br /&gt;
== mas_env.bash ==&lt;br /&gt;
&lt;br /&gt;
To set up the environment and path to use these scripts and idl codes, a user should do &amp;quot;source mas_env.bash&amp;quot;.  (This file used to live in mas/config, but has been moved into mce_script/template.)  Non-developer users can source /usr/mce/mce_script/template/mas_env.bash directly; advanced users may want to keep their own copy (or several different copies) in their home folder.&lt;br /&gt;
&lt;br /&gt;
Note that MAS/mce_script scripts should *not* source mas_env.bash!  The whole point of it is that paths should be flexible.&lt;br /&gt;
&lt;br /&gt;
== .bashrc ==&lt;br /&gt;
&lt;br /&gt;
To have bash start up with the MAS variables defined, and the paths ready, add the following lines to .bashrc :&lt;br /&gt;
&lt;br /&gt;
 export MAS_ROOT=/usr/mce/mce_script/&lt;br /&gt;
 source $MAS_ROOT/template/mas_env.bash&lt;br /&gt;
 export IDL_PATH=&amp;quot;&amp;lt;IDL_DEFAULT&amp;gt;:$MAS_IDL/mas&amp;quot;&lt;br /&gt;
&lt;br /&gt;
While you're in there, you may want to define a few aliases.  In particular, I always uncomment the alias ll='ls-l' line.&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2603</id>
		<title>Raw-mode readout</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2603"/>
		<updated>2009-04-27T20:22:37Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* General Information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= General Information =&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Raw data&amp;quot; and &amp;quot;Raw mode&amp;quot; refer to the acquisition of ADC samples at 50 MHz.&lt;br /&gt;
* Raw data acquisition occurs in the 'background', i.e. it can occur while multiplexing and servoing are going on.&lt;br /&gt;
* Special readout card firmware is required to support raw mode.  This firmware supports most normal readout card features, but does not support the low-pass filter nor the reading back of some parameters.  It should be loaded temporarily (i.e. as a .sof).&lt;br /&gt;
** For 8-column raw mode readout, maximum 8192 samples per column:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v04030007_26may2008_raw.sof&lt;br /&gt;
** For 1-column raw mode readout, maximum 65536 samples:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v0400000d_17apr2009.sof&lt;br /&gt;
* The ADC readings are 14 bits, signed, and are reported as 32-bit signed integers.&lt;br /&gt;
* Data read from the ADC is already 4 cycles old when it is written to the RC buffer.&lt;br /&gt;
** The row switches thus occur at indices (4 + n*row_len) in the output data.&lt;br /&gt;
** This applies to all raw mode firmware (as of 4.0.d).&lt;br /&gt;
** In normal operation, the delay is accounted for automatically.&lt;br /&gt;
* The ADC_offset '''is not''' included in raw mode readings.  So when servoing, the settled values should be compared to ADC offset.&lt;br /&gt;
&lt;br /&gt;
== Raw mode firmware ==&lt;br /&gt;
&lt;br /&gt;
Raw data acquisition and 4-pole low-pass filter are both memory-intensive features of the MCE readout-card firmware. As a general rule, a given firmware has only one of these features available, e.g., the firmware that has raw mode enabled will not include the filter and vice versa. In some versions that support raw mode, read back of gaini0/gainp0/gaind0 is also not supported.&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
! Firmware Revision !! Reported data (signed)&lt;br /&gt;
|-&lt;br /&gt;
| 4.0.d || 14-bit ADC samples, single column, 65536 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.3.7 || 14-bit ADC samples, 8 columns, 8192 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.7 || upper 8-bit of the 14-bit ADC samples (deprecated)&lt;br /&gt;
|-&lt;br /&gt;
| 4.1.7 || upper 8-bit of the 14-bit ADC sample (deprecated)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== High(er)-level support ==&lt;br /&gt;
&lt;br /&gt;
The scripts &amp;quot;mce_raw_acq&amp;quot; and &amp;quot;mce_raw_acq_1col&amp;quot; handle the details of disabling the sync-box, computing the number of frames the user probably wants, issuing the capture command, and reading out the data.  Use them like this:&lt;br /&gt;
&lt;br /&gt;
For 8-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g 1):&lt;br /&gt;
 mce_raw_acq 1&lt;br /&gt;
&lt;br /&gt;
This will create files &amp;lt;ctime&amp;gt;_raw, &amp;lt;ctime&amp;gt;_raw.run.&lt;br /&gt;
&lt;br /&gt;
For 1-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g. 1) and column (e.g. 3):&lt;br /&gt;
 mce_raw_acq_1col 1 3&lt;br /&gt;
&lt;br /&gt;
Due to differences in firmware implementation, mce_raw_acq and mce_raw_acq_1col have different default behaviours.&lt;br /&gt;
* mce_raw_acq:&lt;br /&gt;
** 8-column firmware supports the acquisition of either 8192 samples, or two full multiplexing frames, whichever is lower.&lt;br /&gt;
** By default, mce_raw_acq attempts to acquire this maximum number of samples.&lt;br /&gt;
* mce_raw_acq_1col:&lt;br /&gt;
** 1-column firmware supports the acquisition of 65536 samples, regardless of multiplexing settings.&lt;br /&gt;
** By default, mce_raw_acq will attempt to acquire 65536 samples.  It will change num_rows_reported to 32 in order to make the readout frame size go evenly into 65536.&lt;br /&gt;
&lt;br /&gt;
== Low-level support ==&lt;br /&gt;
&lt;br /&gt;
Raw mode readout is accomplished by first triggering the MCE to store 50 MHz data, and then reading out that data using a special data mode.&lt;br /&gt;
&lt;br /&gt;
* There are two RC parameters that have to be set for raw data acquisition:&lt;br /&gt;
** '''rc# captr_raw''' stores a snapshot of 50 MHz data, starting at the next row-return-to-zero.&lt;br /&gt;
*** In 8-column firmware, ''row_len'' samples of ''num_rows'' rows for '''2''' consecutive frames up to 8192 entries for each channel and stores them in MCE memory buffer for readout in raw mode.  The user must delay here before proceeding to read out the data.  The delay should be a few return-to-zeros.  (Computers are fast, and RTZ can take a long time if row_len is increased for noise measurements... so be generous when running from within scripts.)&lt;br /&gt;
*** In 1-column firmware, 65536 samples are stored.&lt;br /&gt;
** '''rc# data_mode''' determines the pixel-data readout mode.&lt;br /&gt;
*** The data_mode must be 3 for 8-column raw mode readout.&lt;br /&gt;
*** The data_mode must be 12 for 1-column raw mode readout.&lt;br /&gt;
** '''rc# readout_col_index''', in 1-column raw mode, selects the column to store. &lt;br /&gt;
&lt;br /&gt;
* A typical sequence of commands for data acquisition is (8-column mode):&lt;br /&gt;
  wb cc ret_dat_s 1 1&lt;br /&gt;
  wb rc1 data_mode 3&lt;br /&gt;
  wb rc1 captr_raw 1&lt;br /&gt;
  acq_config ''filename'' rc1&lt;br /&gt;
  acq_go ''row_len*2''&lt;br /&gt;
&lt;br /&gt;
== Data handling ==&lt;br /&gt;
&lt;br /&gt;
Raw mode data files are MCE flatfiles and can be loaded using the usual mas_data.pro or mce_data.py programs.  However, the data should be time-ordered for meaningfullness.  This is done by re-ordering the dimensions and collapsing the row and time dimensions.&lt;br /&gt;
&lt;br /&gt;
In newer MASes, the reader programs are aware of data modes 3 and 12 and automatically reform the output data into an n_cols x n_samples array:&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw_col3').Read()&lt;br /&gt;
 print d.data.shape&lt;br /&gt;
   (1, 65536)&lt;br /&gt;
&lt;br /&gt;
If you wanted to do the unravelling yourself, though, you would do this (assuming 8-column raw mode):&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw').Read(row_col=True, data_mode=0)&lt;br /&gt;
 _, nc, _ = d.data.shape&lt;br /&gt;
 d.data = d.data.transpose((1,2,0)).reshape((nc,-1))&lt;br /&gt;
&lt;br /&gt;
Or in IDL (it's practically a one-liner!):&lt;br /&gt;
 data = mas_data('1234000000_raw', /no_runfile, data_mode=0)&lt;br /&gt;
 ds = size(d)&lt;br /&gt;
 nc = ds[1]&lt;br /&gt;
 nt = ds[2]*ds[3]&lt;br /&gt;
 data_raw = reform(data, nc, nt)&lt;br /&gt;
&lt;br /&gt;
= Details =&lt;br /&gt;
&lt;br /&gt;
== Data storage and packaging ==&lt;br /&gt;
&lt;br /&gt;
'''What follows below is a description of 8-column raw mode data packaging.  For 1-column raw data, the data are packed in time order, and read out in units of the frame size.  Values past the end of the 1-column buffer will read as -2^31 = 0x80000000. '''&lt;br /&gt;
&lt;br /&gt;
* Once the raw-buffer of 8192 samples is full, no more samples are stored till a new captr_raw is issued.&lt;br /&gt;
* The raw-buffer is shipped out of MCE in a regular frame format (header + num_rows_reported*num_columns + checksum).  As compared with normal MCE flatfile data organization, in raw mode the time index takes the place of row.  At each time, all columns are reported.&lt;br /&gt;
* For rc1 only, for example, time indices t = [0, num_rows_reported-1] are reported in the first frame, with the offset of column c and time t being&lt;br /&gt;
 index = t*8 + c&lt;br /&gt;
* Subsequent frames contain subsequent data samples.  Since the number of time samples, per column, in a full multiplexing cycle of the MCE is row_len*num_rows, the number of readout frames required to record an entire MCE internal frame's-worth of raw data is equal to row_len (assuming that num_rows = num_rows_reported).&lt;br /&gt;
* The readout frame and index of a given time t, column c, is thus&lt;br /&gt;
 frame = floor[ (t*8 + c) / num_rows_reported ]&lt;br /&gt;
 index = (t*8 + c) mod num_rows_reported&lt;br /&gt;
* Since the number of clock ticks spent on each row is row_len, the row associated with time t is&lt;br /&gt;
 row = floor [ t / row_len ]&lt;br /&gt;
* It is possible to get raw mode data from multiple readout cards; in that case the data will be packaged in the usual way, with all columns reporting at each time.&lt;br /&gt;
* Schematically, the organization of raw data for num_rows = num_rows_reported = 33 and row_len = 100 can be represented as follows (here sNNNNNcXX represents a word containing the data for time sample NNNNN, column XX):&lt;br /&gt;
 (header of frame 0, 43 words)&lt;br /&gt;
 s0000c00 s0000c01 s0000c02 s0000c03 s0000c04 s0000c05 s0000c06 s0000c07&lt;br /&gt;
 s0001c00 s0001c01 s0001c02 s0001c03 s0001c04 s0001c05 s0001c06 s0001c07&lt;br /&gt;
 s0002c00 s0002c01 s0002c02 s0002c03 s0002c04 s0002c05 s0002c06 s0002c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0032c00 s0032c01 s0032c02 s0032c03 s0032c04 s0032c05 s0032c06 s0032c07&lt;br /&gt;
 (checksum of frame 0, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 1, 43 words)&lt;br /&gt;
 s0033c00 s0033c01 s0033c02 s0033c03 s0033c04 s0033c05 s0033c06 s0033c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0065c00 s0065c01 s0065c02 s0065c03 s0065c04 s0065c05 s0065c06 s0065c07&lt;br /&gt;
 (checksum of frame 1, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 199, 43 words)&lt;br /&gt;
 s6567c67 s6567c01 s6567c02 s6567c03 s6567c04 s6567c05 s6567c06 s6567c07&lt;br /&gt;
 ...&lt;br /&gt;
 s6599c00 s6599c01 s6599c02 s6599c03 s6599c04 s6599c05 s6599c06 s6599c07&lt;br /&gt;
 (checksum of frame 199, 1 word)&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, collecting data for up to '''2''' internal MCE frames is hard-coded in firmware. Even if you reduce number of rows, you will be restricted by 2 frames. If you really want to look at more samples, then you may want to increase row_len instead and using row_order parameter of the address card, move your particular row of interest to the beginning of the frame.&lt;br /&gt;
&lt;br /&gt;
* readout_row_index parameter is ignored when data_mode is set to 3 or raw mode.&lt;br /&gt;
&lt;br /&gt;
* if num_rows_reported &amp;lt; num_rows, it takes more frames (to be exact: n = (num_rows*row_len*2/num_rows_reported) frames) to read all the data out.&lt;br /&gt;
&lt;br /&gt;
== Firmware ==&lt;br /&gt;
* To toggle between raw data firmware and filtering firmware, one must un-comment one or the other (not both) of the following data banks:&lt;br /&gt;
** i_raw_dat_bank in adc_sample_coadd.vhd, for enabling/disabling raw data.&lt;br /&gt;
** i_fsfb_wn11_Q, i_fsfb_wn12_Q, i_fsfb_wn21_Q, i_fsfb_wn22_Q in fsfb_fltr_regs.vhd, for enabling/disabling filtered data.&lt;br /&gt;
* For some versions of Quartus, a quartus.ini file must be present in the synthesis directory for the changes in RAM configurations to register.  The file contains the following line:&lt;br /&gt;
 rtl_no_super_dupe_reg = on&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2602</id>
		<title>Raw-mode readout</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2602"/>
		<updated>2009-04-24T09:47:32Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Data storage and packaging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= General Information =&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Raw data&amp;quot; and &amp;quot;Raw mode&amp;quot; refer to the acquisition of ADC samples at 50 MHz.&lt;br /&gt;
* Raw data acquisition occurs in the 'background', i.e. it can occur while multiplexing and servoing are going on.&lt;br /&gt;
* Special readout card firmware is required to support raw mode.  This firmware supports most normal readout card features, but does not support the low-pass filter nor the reading back of some parameters.  It should be loaded temporarily (i.e. as a .sof).&lt;br /&gt;
** For 8-column raw mode readout, maximum 8192 samples per column:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v04030007_26may2008_raw.sof&lt;br /&gt;
** For 1-column raw mode readout, maximum 65536 samples:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v0400000d_17apr2009.sof&lt;br /&gt;
* The ADC readings are 14 bits, signed, and are reported as 32-bit signed integers.&lt;br /&gt;
* The ADC_offset '''is not''' included in raw mode readings.  So when servoing, the settled values should be compared to ADC offset.&lt;br /&gt;
&lt;br /&gt;
== Raw mode firmware ==&lt;br /&gt;
&lt;br /&gt;
Raw data acquisition and 4-pole low-pass filter are both memory-intensive features of the MCE readout-card firmware. As a general rule, a given firmware has only one of these features available, e.g., the firmware that has raw mode enabled will not include the filter and vice versa. In some versions that support raw mode, read back of gaini0/gainp0/gaind0 is also not supported.&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
! Firmware Revision !! Reported data (signed)&lt;br /&gt;
|-&lt;br /&gt;
| 4.0.d || 14-bit ADC samples, single column, 65536 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.3.7 || 14-bit ADC samples, 8 columns, 8192 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.7 || upper 8-bit of the 14-bit ADC samples (deprecated)&lt;br /&gt;
|-&lt;br /&gt;
| 4.1.7 || upper 8-bit of the 14-bit ADC sample (deprecated)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== High(er)-level support ==&lt;br /&gt;
&lt;br /&gt;
The scripts &amp;quot;mce_raw_acq&amp;quot; and &amp;quot;mce_raw_acq_1col&amp;quot; handle the details of disabling the sync-box, computing the number of frames the user probably wants, issuing the capture command, and reading out the data.  Use them like this:&lt;br /&gt;
&lt;br /&gt;
For 8-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g 1):&lt;br /&gt;
 mce_raw_acq 1&lt;br /&gt;
&lt;br /&gt;
This will create files &amp;lt;ctime&amp;gt;_raw, &amp;lt;ctime&amp;gt;_raw.run.&lt;br /&gt;
&lt;br /&gt;
For 1-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g. 1) and column (e.g. 3):&lt;br /&gt;
 mce_raw_acq_1col 1 3&lt;br /&gt;
&lt;br /&gt;
Due to differences in firmware implementation, mce_raw_acq and mce_raw_acq_1col have different default behaviours.&lt;br /&gt;
* mce_raw_acq:&lt;br /&gt;
** 8-column firmware supports the acquisition of either 8192 samples, or two full multiplexing frames, whichever is lower.&lt;br /&gt;
** By default, mce_raw_acq attempts to acquire this maximum number of samples.&lt;br /&gt;
* mce_raw_acq_1col:&lt;br /&gt;
** 1-column firmware supports the acquisition of 65536 samples, regardless of multiplexing settings.&lt;br /&gt;
** By default, mce_raw_acq will attempt to acquire 65536 samples.  It will change num_rows_reported to 32 in order to make the readout frame size go evenly into 65536.&lt;br /&gt;
&lt;br /&gt;
== Low-level support ==&lt;br /&gt;
&lt;br /&gt;
Raw mode readout is accomplished by first triggering the MCE to store 50 MHz data, and then reading out that data using a special data mode.&lt;br /&gt;
&lt;br /&gt;
* There are two RC parameters that have to be set for raw data acquisition:&lt;br /&gt;
** '''rc# captr_raw''' stores a snapshot of 50 MHz data, starting at the next row-return-to-zero.&lt;br /&gt;
*** In 8-column firmware, ''row_len'' samples of ''num_rows'' rows for '''2''' consecutive frames up to 8192 entries for each channel and stores them in MCE memory buffer for readout in raw mode.  The user must delay here before proceeding to read out the data.  The delay should be a few return-to-zeros.  (Computers are fast, and RTZ can take a long time if row_len is increased for noise measurements... so be generous when running from within scripts.)&lt;br /&gt;
*** In 1-column firmware, 65536 samples are stored.&lt;br /&gt;
** '''rc# data_mode''' determines the pixel-data readout mode.&lt;br /&gt;
*** The data_mode must be 3 for 8-column raw mode readout.&lt;br /&gt;
*** The data_mode must be 12 for 1-column raw mode readout.&lt;br /&gt;
** '''rc# readout_col_index''', in 1-column raw mode, selects the column to store. &lt;br /&gt;
&lt;br /&gt;
* A typical sequence of commands for data acquisition is (8-column mode):&lt;br /&gt;
  wb cc ret_dat_s 1 1&lt;br /&gt;
  wb rc1 data_mode 3&lt;br /&gt;
  wb rc1 captr_raw 1&lt;br /&gt;
  acq_config ''filename'' rc1&lt;br /&gt;
  acq_go ''row_len*2''&lt;br /&gt;
&lt;br /&gt;
== Data handling ==&lt;br /&gt;
&lt;br /&gt;
Raw mode data files are MCE flatfiles and can be loaded using the usual mas_data.pro or mce_data.py programs.  However, the data should be time-ordered for meaningfullness.  This is done by re-ordering the dimensions and collapsing the row and time dimensions.&lt;br /&gt;
&lt;br /&gt;
In newer MASes, the reader programs are aware of data modes 3 and 12 and automatically reform the output data into an n_cols x n_samples array:&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw_col3').Read()&lt;br /&gt;
 print d.data.shape&lt;br /&gt;
   (1, 65536)&lt;br /&gt;
&lt;br /&gt;
If you wanted to do the unravelling yourself, though, you would do this (assuming 8-column raw mode):&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw').Read(row_col=True, data_mode=0)&lt;br /&gt;
 _, nc, _ = d.data.shape&lt;br /&gt;
 d.data = d.data.transpose((1,2,0)).reshape((nc,-1))&lt;br /&gt;
&lt;br /&gt;
Or in IDL (it's practically a one-liner!):&lt;br /&gt;
 data = mas_data('1234000000_raw', /no_runfile, data_mode=0)&lt;br /&gt;
 ds = size(d)&lt;br /&gt;
 nc = ds[1]&lt;br /&gt;
 nt = ds[2]*ds[3]&lt;br /&gt;
 data_raw = reform(data, nc, nt)&lt;br /&gt;
&lt;br /&gt;
= Details =&lt;br /&gt;
&lt;br /&gt;
== Data storage and packaging ==&lt;br /&gt;
&lt;br /&gt;
'''What follows below is a description of 8-column raw mode data packaging.  For 1-column raw data, the data are packed in time order, and read out in units of the frame size.  Values past the end of the 1-column buffer will read as -2^31 = 0x80000000. '''&lt;br /&gt;
&lt;br /&gt;
* Once the raw-buffer of 8192 samples is full, no more samples are stored till a new captr_raw is issued.&lt;br /&gt;
* The raw-buffer is shipped out of MCE in a regular frame format (header + num_rows_reported*num_columns + checksum).  As compared with normal MCE flatfile data organization, in raw mode the time index takes the place of row.  At each time, all columns are reported.&lt;br /&gt;
* For rc1 only, for example, time indices t = [0, num_rows_reported-1] are reported in the first frame, with the offset of column c and time t being&lt;br /&gt;
 index = t*8 + c&lt;br /&gt;
* Subsequent frames contain subsequent data samples.  Since the number of time samples, per column, in a full multiplexing cycle of the MCE is row_len*num_rows, the number of readout frames required to record an entire MCE internal frame's-worth of raw data is equal to row_len (assuming that num_rows = num_rows_reported).&lt;br /&gt;
* The readout frame and index of a given time t, column c, is thus&lt;br /&gt;
 frame = floor[ (t*8 + c) / num_rows_reported ]&lt;br /&gt;
 index = (t*8 + c) mod num_rows_reported&lt;br /&gt;
* Since the number of clock ticks spent on each row is row_len, the row associated with time t is&lt;br /&gt;
 row = floor [ t / row_len ]&lt;br /&gt;
* It is possible to get raw mode data from multiple readout cards; in that case the data will be packaged in the usual way, with all columns reporting at each time.&lt;br /&gt;
* Schematically, the organization of raw data for num_rows = num_rows_reported = 33 and row_len = 100 can be represented as follows (here sNNNNNcXX represents a word containing the data for time sample NNNNN, column XX):&lt;br /&gt;
 (header of frame 0, 43 words)&lt;br /&gt;
 s0000c00 s0000c01 s0000c02 s0000c03 s0000c04 s0000c05 s0000c06 s0000c07&lt;br /&gt;
 s0001c00 s0001c01 s0001c02 s0001c03 s0001c04 s0001c05 s0001c06 s0001c07&lt;br /&gt;
 s0002c00 s0002c01 s0002c02 s0002c03 s0002c04 s0002c05 s0002c06 s0002c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0032c00 s0032c01 s0032c02 s0032c03 s0032c04 s0032c05 s0032c06 s0032c07&lt;br /&gt;
 (checksum of frame 0, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 1, 43 words)&lt;br /&gt;
 s0033c00 s0033c01 s0033c02 s0033c03 s0033c04 s0033c05 s0033c06 s0033c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0065c00 s0065c01 s0065c02 s0065c03 s0065c04 s0065c05 s0065c06 s0065c07&lt;br /&gt;
 (checksum of frame 1, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 199, 43 words)&lt;br /&gt;
 s6567c67 s6567c01 s6567c02 s6567c03 s6567c04 s6567c05 s6567c06 s6567c07&lt;br /&gt;
 ...&lt;br /&gt;
 s6599c00 s6599c01 s6599c02 s6599c03 s6599c04 s6599c05 s6599c06 s6599c07&lt;br /&gt;
 (checksum of frame 199, 1 word)&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, collecting data for up to '''2''' internal MCE frames is hard-coded in firmware. Even if you reduce number of rows, you will be restricted by 2 frames. If you really want to look at more samples, then you may want to increase row_len instead and using row_order parameter of the address card, move your particular row of interest to the beginning of the frame.&lt;br /&gt;
&lt;br /&gt;
* readout_row_index parameter is ignored when data_mode is set to 3 or raw mode.&lt;br /&gt;
&lt;br /&gt;
* if num_rows_reported &amp;lt; num_rows, it takes more frames (to be exact: n = (num_rows*row_len*2/num_rows_reported) frames) to read all the data out.&lt;br /&gt;
&lt;br /&gt;
== Firmware ==&lt;br /&gt;
* To toggle between raw data firmware and filtering firmware, one must un-comment one or the other (not both) of the following data banks:&lt;br /&gt;
** i_raw_dat_bank in adc_sample_coadd.vhd, for enabling/disabling raw data.&lt;br /&gt;
** i_fsfb_wn11_Q, i_fsfb_wn12_Q, i_fsfb_wn21_Q, i_fsfb_wn22_Q in fsfb_fltr_regs.vhd, for enabling/disabling filtered data.&lt;br /&gt;
* For some versions of Quartus, a quartus.ini file must be present in the synthesis directory for the changes in RAM configurations to register.  The file contains the following line:&lt;br /&gt;
 rtl_no_super_dupe_reg = on&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2601</id>
		<title>Raw-mode readout</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2601"/>
		<updated>2009-04-24T09:42:38Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Low-level support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= General Information =&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Raw data&amp;quot; and &amp;quot;Raw mode&amp;quot; refer to the acquisition of ADC samples at 50 MHz.&lt;br /&gt;
* Raw data acquisition occurs in the 'background', i.e. it can occur while multiplexing and servoing are going on.&lt;br /&gt;
* Special readout card firmware is required to support raw mode.  This firmware supports most normal readout card features, but does not support the low-pass filter nor the reading back of some parameters.  It should be loaded temporarily (i.e. as a .sof).&lt;br /&gt;
** For 8-column raw mode readout, maximum 8192 samples per column:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v04030007_26may2008_raw.sof&lt;br /&gt;
** For 1-column raw mode readout, maximum 65536 samples:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v0400000d_17apr2009.sof&lt;br /&gt;
* The ADC readings are 14 bits, signed, and are reported as 32-bit signed integers.&lt;br /&gt;
* The ADC_offset '''is not''' included in raw mode readings.  So when servoing, the settled values should be compared to ADC offset.&lt;br /&gt;
&lt;br /&gt;
== Raw mode firmware ==&lt;br /&gt;
&lt;br /&gt;
Raw data acquisition and 4-pole low-pass filter are both memory-intensive features of the MCE readout-card firmware. As a general rule, a given firmware has only one of these features available, e.g., the firmware that has raw mode enabled will not include the filter and vice versa. In some versions that support raw mode, read back of gaini0/gainp0/gaind0 is also not supported.&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
! Firmware Revision !! Reported data (signed)&lt;br /&gt;
|-&lt;br /&gt;
| 4.0.d || 14-bit ADC samples, single column, 65536 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.3.7 || 14-bit ADC samples, 8 columns, 8192 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.7 || upper 8-bit of the 14-bit ADC samples (deprecated)&lt;br /&gt;
|-&lt;br /&gt;
| 4.1.7 || upper 8-bit of the 14-bit ADC sample (deprecated)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== High(er)-level support ==&lt;br /&gt;
&lt;br /&gt;
The scripts &amp;quot;mce_raw_acq&amp;quot; and &amp;quot;mce_raw_acq_1col&amp;quot; handle the details of disabling the sync-box, computing the number of frames the user probably wants, issuing the capture command, and reading out the data.  Use them like this:&lt;br /&gt;
&lt;br /&gt;
For 8-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g 1):&lt;br /&gt;
 mce_raw_acq 1&lt;br /&gt;
&lt;br /&gt;
This will create files &amp;lt;ctime&amp;gt;_raw, &amp;lt;ctime&amp;gt;_raw.run.&lt;br /&gt;
&lt;br /&gt;
For 1-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g. 1) and column (e.g. 3):&lt;br /&gt;
 mce_raw_acq_1col 1 3&lt;br /&gt;
&lt;br /&gt;
Due to differences in firmware implementation, mce_raw_acq and mce_raw_acq_1col have different default behaviours.&lt;br /&gt;
* mce_raw_acq:&lt;br /&gt;
** 8-column firmware supports the acquisition of either 8192 samples, or two full multiplexing frames, whichever is lower.&lt;br /&gt;
** By default, mce_raw_acq attempts to acquire this maximum number of samples.&lt;br /&gt;
* mce_raw_acq_1col:&lt;br /&gt;
** 1-column firmware supports the acquisition of 65536 samples, regardless of multiplexing settings.&lt;br /&gt;
** By default, mce_raw_acq will attempt to acquire 65536 samples.  It will change num_rows_reported to 32 in order to make the readout frame size go evenly into 65536.&lt;br /&gt;
&lt;br /&gt;
== Low-level support ==&lt;br /&gt;
&lt;br /&gt;
Raw mode readout is accomplished by first triggering the MCE to store 50 MHz data, and then reading out that data using a special data mode.&lt;br /&gt;
&lt;br /&gt;
* There are two RC parameters that have to be set for raw data acquisition:&lt;br /&gt;
** '''rc# captr_raw''' stores a snapshot of 50 MHz data, starting at the next row-return-to-zero.&lt;br /&gt;
*** In 8-column firmware, ''row_len'' samples of ''num_rows'' rows for '''2''' consecutive frames up to 8192 entries for each channel and stores them in MCE memory buffer for readout in raw mode.  The user must delay here before proceeding to read out the data.  The delay should be a few return-to-zeros.  (Computers are fast, and RTZ can take a long time if row_len is increased for noise measurements... so be generous when running from within scripts.)&lt;br /&gt;
*** In 1-column firmware, 65536 samples are stored.&lt;br /&gt;
** '''rc# data_mode''' determines the pixel-data readout mode.&lt;br /&gt;
*** The data_mode must be 3 for 8-column raw mode readout.&lt;br /&gt;
*** The data_mode must be 12 for 1-column raw mode readout.&lt;br /&gt;
** '''rc# readout_col_index''', in 1-column raw mode, selects the column to store. &lt;br /&gt;
&lt;br /&gt;
* A typical sequence of commands for data acquisition is (8-column mode):&lt;br /&gt;
  wb cc ret_dat_s 1 1&lt;br /&gt;
  wb rc1 data_mode 3&lt;br /&gt;
  wb rc1 captr_raw 1&lt;br /&gt;
  acq_config ''filename'' rc1&lt;br /&gt;
  acq_go ''row_len*2''&lt;br /&gt;
&lt;br /&gt;
== Data handling ==&lt;br /&gt;
&lt;br /&gt;
Raw mode data files are MCE flatfiles and can be loaded using the usual mas_data.pro or mce_data.py programs.  However, the data should be time-ordered for meaningfullness.  This is done by re-ordering the dimensions and collapsing the row and time dimensions.&lt;br /&gt;
&lt;br /&gt;
In newer MASes, the reader programs are aware of data modes 3 and 12 and automatically reform the output data into an n_cols x n_samples array:&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw_col3').Read()&lt;br /&gt;
 print d.data.shape&lt;br /&gt;
   (1, 65536)&lt;br /&gt;
&lt;br /&gt;
If you wanted to do the unravelling yourself, though, you would do this (assuming 8-column raw mode):&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw').Read(row_col=True, data_mode=0)&lt;br /&gt;
 _, nc, _ = d.data.shape&lt;br /&gt;
 d.data = d.data.transpose((1,2,0)).reshape((nc,-1))&lt;br /&gt;
&lt;br /&gt;
Or in IDL (it's practically a one-liner!):&lt;br /&gt;
 data = mas_data('1234000000_raw', /no_runfile, data_mode=0)&lt;br /&gt;
 ds = size(d)&lt;br /&gt;
 nc = ds[1]&lt;br /&gt;
 nt = ds[2]*ds[3]&lt;br /&gt;
 data_raw = reform(data, nc, nt)&lt;br /&gt;
&lt;br /&gt;
= Details =&lt;br /&gt;
&lt;br /&gt;
== Data storage and packaging ==&lt;br /&gt;
&lt;br /&gt;
* Once the raw-buffer of 8192 samples is full, no more samples are stored till a new captr_raw is issued.&lt;br /&gt;
* The raw-buffer is shipped out of MCE in a regular frame format (header + num_rows_reported*num_columns + checksum).  As compared with normal MCE flatfile data organization, in raw mode the time index takes the place of row.  At each time, all columns are reported.&lt;br /&gt;
* For rc1 only, for example, time indices t = [0, num_rows_reported-1] are reported in the first frame, with the offset of column c and time t being&lt;br /&gt;
 index = t*8 + c&lt;br /&gt;
* Subsequent frames contain subsequent data samples.  Since the number of time samples, per column, in a full multiplexing cycle of the MCE is row_len*num_rows, the number of readout frames required to record an entire MCE internal frame's-worth of raw data is equal to row_len (assuming that num_rows = num_rows_reported).&lt;br /&gt;
* The readout frame and index of a given time t, column c, is thus&lt;br /&gt;
 frame = floor[ (t*8 + c) / num_rows_reported ]&lt;br /&gt;
 index = (t*8 + c) mod num_rows_reported&lt;br /&gt;
* Since the number of clock ticks spent on each row is row_len, the row associated with time t is&lt;br /&gt;
 row = floor [ t / row_len ]&lt;br /&gt;
* It is possible to get raw mode data from multiple readout cards; in that case the data will be packaged in the usual way, with all columns reporting at each time.&lt;br /&gt;
* Schematically, the organization of raw data for num_rows = num_rows_reported = 33 and row_len = 100 can be represented as follows (here sNNNNNcXX represents a word containing the data for time sample NNNNN, column XX):&lt;br /&gt;
 (header of frame 0, 43 words)&lt;br /&gt;
 s0000c00 s0000c01 s0000c02 s0000c03 s0000c04 s0000c05 s0000c06 s0000c07&lt;br /&gt;
 s0001c00 s0001c01 s0001c02 s0001c03 s0001c04 s0001c05 s0001c06 s0001c07&lt;br /&gt;
 s0002c00 s0002c01 s0002c02 s0002c03 s0002c04 s0002c05 s0002c06 s0002c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0032c00 s0032c01 s0032c02 s0032c03 s0032c04 s0032c05 s0032c06 s0032c07&lt;br /&gt;
 (checksum of frame 0, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 1, 43 words)&lt;br /&gt;
 s0033c00 s0033c01 s0033c02 s0033c03 s0033c04 s0033c05 s0033c06 s0033c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0065c00 s0065c01 s0065c02 s0065c03 s0065c04 s0065c05 s0065c06 s0065c07&lt;br /&gt;
 (checksum of frame 1, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 199, 43 words)&lt;br /&gt;
 s6567c67 s6567c01 s6567c02 s6567c03 s6567c04 s6567c05 s6567c06 s6567c07&lt;br /&gt;
 ...&lt;br /&gt;
 s6599c00 s6599c01 s6599c02 s6599c03 s6599c04 s6599c05 s6599c06 s6599c07&lt;br /&gt;
 (checksum of frame 199, 1 word)&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, collecting data for up to '''2''' internal MCE frames is hard-coded in firmware. Even if you reduce number of rows, you will be restricted by 2 frames. If you really want to look at more samples, then you may want to increase row_len instead and using row_order parameter of the address card, move your particular row of interest to the beginning of the frame.&lt;br /&gt;
&lt;br /&gt;
* readout_row_index parameter is ignored when data_mode is set to 3 or raw mode.&lt;br /&gt;
&lt;br /&gt;
* if num_rows_reported &amp;lt; num_rows, it takes more frames (to be exact: n = (num_rows*row_len*2/num_rows_reported) frames) to read all the data out.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Firmware ==&lt;br /&gt;
* To toggle between raw data firmware and filtering firmware, one must un-comment one or the other (not both) of the following data banks:&lt;br /&gt;
** i_raw_dat_bank in adc_sample_coadd.vhd, for enabling/disabling raw data.&lt;br /&gt;
** i_fsfb_wn11_Q, i_fsfb_wn12_Q, i_fsfb_wn21_Q, i_fsfb_wn22_Q in fsfb_fltr_regs.vhd, for enabling/disabling filtered data.&lt;br /&gt;
* For some versions of Quartus, a quartus.ini file must be present in the synthesis directory for the changes in RAM configurations to register.  The file contains the following line:&lt;br /&gt;
 rtl_no_super_dupe_reg = on&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2600</id>
		<title>Raw-mode readout</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2600"/>
		<updated>2009-04-24T09:41:33Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* Low-level support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= General Information =&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Raw data&amp;quot; and &amp;quot;Raw mode&amp;quot; refer to the acquisition of ADC samples at 50 MHz.&lt;br /&gt;
* Raw data acquisition occurs in the 'background', i.e. it can occur while multiplexing and servoing are going on.&lt;br /&gt;
* Special readout card firmware is required to support raw mode.  This firmware supports most normal readout card features, but does not support the low-pass filter nor the reading back of some parameters.  It should be loaded temporarily (i.e. as a .sof).&lt;br /&gt;
** For 8-column raw mode readout, maximum 8192 samples per column:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v04030007_26may2008_raw.sof&lt;br /&gt;
** For 1-column raw mode readout, maximum 65536 samples:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v0400000d_17apr2009.sof&lt;br /&gt;
* The ADC readings are 14 bits, signed, and are reported as 32-bit signed integers.&lt;br /&gt;
* The ADC_offset '''is not''' included in raw mode readings.  So when servoing, the settled values should be compared to ADC offset.&lt;br /&gt;
&lt;br /&gt;
== Raw mode firmware ==&lt;br /&gt;
&lt;br /&gt;
Raw data acquisition and 4-pole low-pass filter are both memory-intensive features of the MCE readout-card firmware. As a general rule, a given firmware has only one of these features available, e.g., the firmware that has raw mode enabled will not include the filter and vice versa. In some versions that support raw mode, read back of gaini0/gainp0/gaind0 is also not supported.&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
! Firmware Revision !! Reported data (signed)&lt;br /&gt;
|-&lt;br /&gt;
| 4.0.d || 14-bit ADC samples, single column, 65536 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.3.7 || 14-bit ADC samples, 8 columns, 8192 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.7 || upper 8-bit of the 14-bit ADC samples (deprecated)&lt;br /&gt;
|-&lt;br /&gt;
| 4.1.7 || upper 8-bit of the 14-bit ADC sample (deprecated)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== High(er)-level support ==&lt;br /&gt;
&lt;br /&gt;
The scripts &amp;quot;mce_raw_acq&amp;quot; and &amp;quot;mce_raw_acq_1col&amp;quot; handle the details of disabling the sync-box, computing the number of frames the user probably wants, issuing the capture command, and reading out the data.  Use them like this:&lt;br /&gt;
&lt;br /&gt;
For 8-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g 1):&lt;br /&gt;
 mce_raw_acq 1&lt;br /&gt;
&lt;br /&gt;
This will create files &amp;lt;ctime&amp;gt;_raw, &amp;lt;ctime&amp;gt;_raw.run.&lt;br /&gt;
&lt;br /&gt;
For 1-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g. 1) and column (e.g. 3):&lt;br /&gt;
 mce_raw_acq_1col 1 3&lt;br /&gt;
&lt;br /&gt;
Due to differences in firmware implementation, mce_raw_acq and mce_raw_acq_1col have different default behaviours.&lt;br /&gt;
* mce_raw_acq:&lt;br /&gt;
** 8-column firmware supports the acquisition of either 8192 samples, or two full multiplexing frames, whichever is lower.&lt;br /&gt;
** By default, mce_raw_acq attempts to acquire this maximum number of samples.&lt;br /&gt;
* mce_raw_acq_1col:&lt;br /&gt;
** 1-column firmware supports the acquisition of 65536 samples, regardless of multiplexing settings.&lt;br /&gt;
** By default, mce_raw_acq will attempt to acquire 65536 samples.  It will change num_rows_reported to 32 in order to make the readout frame size go evenly into 65536.&lt;br /&gt;
&lt;br /&gt;
== Low-level support ==&lt;br /&gt;
&lt;br /&gt;
Raw mode readout is accomplished by first triggering the MCE to store 50 MHz data, and then reading out that data using a special data mode.&lt;br /&gt;
&lt;br /&gt;
* There are two RC parameters that have to be set for raw data acquisition:&lt;br /&gt;
** '''rc# captr_raw''' stores a snapshot of 50 MHz data, starting at the next row-return-to-zero.&lt;br /&gt;
*** In 8-column firmware, ''row_len'' samples of ''num_rows'' rows for '''2''' consecutive frames up to 8192 entries for each channel and stores them in MCE memory buffer for readout in raw mode.  The user must delay here before proceeding to read out the data.  The delay should be a few return-to-zeros.  (Computers are fast, and RTZ can take a long time if row_len is increased for noise measurements... so be generous when running from within scripts.)&lt;br /&gt;
*** In 1-column firmware, 65536 samples are stored.&lt;br /&gt;
** '''rc# data_mode''' determines the pixel-data readout mode.&lt;br /&gt;
*** The data_mode must be 3 for 8-column raw mode readout.&lt;br /&gt;
*** The data_mode must be 12 for 1-column raw mode readout.&lt;br /&gt;
** In 1-column raw mode, the desired column is set through 'rc# readout_col_index'.  This number will appear in the runfile. &lt;br /&gt;
&lt;br /&gt;
* A typical sequence of commands for data acquisition is (8-column mode):&lt;br /&gt;
  wb cc ret_dat_s 1 1&lt;br /&gt;
  wb rc1 data_mode 3&lt;br /&gt;
  wb rc1 captr_raw 1&lt;br /&gt;
  acq_config ''filename'' rc1&lt;br /&gt;
  acq_go ''row_len*2''&lt;br /&gt;
&lt;br /&gt;
== Data handling ==&lt;br /&gt;
&lt;br /&gt;
Raw mode data files are MCE flatfiles and can be loaded using the usual mas_data.pro or mce_data.py programs.  However, the data should be time-ordered for meaningfullness.  This is done by re-ordering the dimensions and collapsing the row and time dimensions.&lt;br /&gt;
&lt;br /&gt;
In newer MASes, the reader programs are aware of data modes 3 and 12 and automatically reform the output data into an n_cols x n_samples array:&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw_col3').Read()&lt;br /&gt;
 print d.data.shape&lt;br /&gt;
   (1, 65536)&lt;br /&gt;
&lt;br /&gt;
If you wanted to do the unravelling yourself, though, you would do this (assuming 8-column raw mode):&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw').Read(row_col=True, data_mode=0)&lt;br /&gt;
 _, nc, _ = d.data.shape&lt;br /&gt;
 d.data = d.data.transpose((1,2,0)).reshape((nc,-1))&lt;br /&gt;
&lt;br /&gt;
Or in IDL (it's practically a one-liner!):&lt;br /&gt;
 data = mas_data('1234000000_raw', /no_runfile, data_mode=0)&lt;br /&gt;
 ds = size(d)&lt;br /&gt;
 nc = ds[1]&lt;br /&gt;
 nt = ds[2]*ds[3]&lt;br /&gt;
 data_raw = reform(data, nc, nt)&lt;br /&gt;
&lt;br /&gt;
= Details =&lt;br /&gt;
&lt;br /&gt;
== Data storage and packaging ==&lt;br /&gt;
&lt;br /&gt;
* Once the raw-buffer of 8192 samples is full, no more samples are stored till a new captr_raw is issued.&lt;br /&gt;
* The raw-buffer is shipped out of MCE in a regular frame format (header + num_rows_reported*num_columns + checksum).  As compared with normal MCE flatfile data organization, in raw mode the time index takes the place of row.  At each time, all columns are reported.&lt;br /&gt;
* For rc1 only, for example, time indices t = [0, num_rows_reported-1] are reported in the first frame, with the offset of column c and time t being&lt;br /&gt;
 index = t*8 + c&lt;br /&gt;
* Subsequent frames contain subsequent data samples.  Since the number of time samples, per column, in a full multiplexing cycle of the MCE is row_len*num_rows, the number of readout frames required to record an entire MCE internal frame's-worth of raw data is equal to row_len (assuming that num_rows = num_rows_reported).&lt;br /&gt;
* The readout frame and index of a given time t, column c, is thus&lt;br /&gt;
 frame = floor[ (t*8 + c) / num_rows_reported ]&lt;br /&gt;
 index = (t*8 + c) mod num_rows_reported&lt;br /&gt;
* Since the number of clock ticks spent on each row is row_len, the row associated with time t is&lt;br /&gt;
 row = floor [ t / row_len ]&lt;br /&gt;
* It is possible to get raw mode data from multiple readout cards; in that case the data will be packaged in the usual way, with all columns reporting at each time.&lt;br /&gt;
* Schematically, the organization of raw data for num_rows = num_rows_reported = 33 and row_len = 100 can be represented as follows (here sNNNNNcXX represents a word containing the data for time sample NNNNN, column XX):&lt;br /&gt;
 (header of frame 0, 43 words)&lt;br /&gt;
 s0000c00 s0000c01 s0000c02 s0000c03 s0000c04 s0000c05 s0000c06 s0000c07&lt;br /&gt;
 s0001c00 s0001c01 s0001c02 s0001c03 s0001c04 s0001c05 s0001c06 s0001c07&lt;br /&gt;
 s0002c00 s0002c01 s0002c02 s0002c03 s0002c04 s0002c05 s0002c06 s0002c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0032c00 s0032c01 s0032c02 s0032c03 s0032c04 s0032c05 s0032c06 s0032c07&lt;br /&gt;
 (checksum of frame 0, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 1, 43 words)&lt;br /&gt;
 s0033c00 s0033c01 s0033c02 s0033c03 s0033c04 s0033c05 s0033c06 s0033c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0065c00 s0065c01 s0065c02 s0065c03 s0065c04 s0065c05 s0065c06 s0065c07&lt;br /&gt;
 (checksum of frame 1, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 199, 43 words)&lt;br /&gt;
 s6567c67 s6567c01 s6567c02 s6567c03 s6567c04 s6567c05 s6567c06 s6567c07&lt;br /&gt;
 ...&lt;br /&gt;
 s6599c00 s6599c01 s6599c02 s6599c03 s6599c04 s6599c05 s6599c06 s6599c07&lt;br /&gt;
 (checksum of frame 199, 1 word)&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, collecting data for up to '''2''' internal MCE frames is hard-coded in firmware. Even if you reduce number of rows, you will be restricted by 2 frames. If you really want to look at more samples, then you may want to increase row_len instead and using row_order parameter of the address card, move your particular row of interest to the beginning of the frame.&lt;br /&gt;
&lt;br /&gt;
* readout_row_index parameter is ignored when data_mode is set to 3 or raw mode.&lt;br /&gt;
&lt;br /&gt;
* if num_rows_reported &amp;lt; num_rows, it takes more frames (to be exact: n = (num_rows*row_len*2/num_rows_reported) frames) to read all the data out.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Firmware ==&lt;br /&gt;
* To toggle between raw data firmware and filtering firmware, one must un-comment one or the other (not both) of the following data banks:&lt;br /&gt;
** i_raw_dat_bank in adc_sample_coadd.vhd, for enabling/disabling raw data.&lt;br /&gt;
** i_fsfb_wn11_Q, i_fsfb_wn12_Q, i_fsfb_wn21_Q, i_fsfb_wn22_Q in fsfb_fltr_regs.vhd, for enabling/disabling filtered data.&lt;br /&gt;
* For some versions of Quartus, a quartus.ini file must be present in the synthesis directory for the changes in RAM configurations to register.  The file contains the following line:&lt;br /&gt;
 rtl_no_super_dupe_reg = on&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2599</id>
		<title>Raw-mode readout</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Raw-mode_readout&amp;diff=2599"/>
		<updated>2009-04-24T09:12:57Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: /* General Information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= General Information =&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;Raw data&amp;quot; and &amp;quot;Raw mode&amp;quot; refer to the acquisition of ADC samples at 50 MHz.&lt;br /&gt;
* Raw data acquisition occurs in the 'background', i.e. it can occur while multiplexing and servoing are going on.&lt;br /&gt;
* Special readout card firmware is required to support raw mode.  This firmware supports most normal readout card features, but does not support the low-pass filter nor the reading back of some parameters.  It should be loaded temporarily (i.e. as a .sof).&lt;br /&gt;
** For 8-column raw mode readout, maximum 8192 samples per column:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v04030007_26may2008_raw.sof&lt;br /&gt;
** For 1-column raw mode readout, maximum 65536 samples:&lt;br /&gt;
 http://www.phas.ubc.ca/~mce/mcedocs/firmware/rc_v0400000d_17apr2009.sof&lt;br /&gt;
* The ADC readings are 14 bits, signed, and are reported as 32-bit signed integers.&lt;br /&gt;
* The ADC_offset '''is not''' included in raw mode readings.  So when servoing, the settled values should be compared to ADC offset.&lt;br /&gt;
&lt;br /&gt;
== Raw mode firmware ==&lt;br /&gt;
&lt;br /&gt;
Raw data acquisition and 4-pole low-pass filter are both memory-intensive features of the MCE readout-card firmware. As a general rule, a given firmware has only one of these features available, e.g., the firmware that has raw mode enabled will not include the filter and vice versa. In some versions that support raw mode, read back of gaini0/gainp0/gaind0 is also not supported.&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
! Firmware Revision !! Reported data (signed)&lt;br /&gt;
|-&lt;br /&gt;
| 4.0.d || 14-bit ADC samples, single column, 65536 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.3.7 || 14-bit ADC samples, 8 columns, 8192 points.&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.7 || upper 8-bit of the 14-bit ADC samples (deprecated)&lt;br /&gt;
|-&lt;br /&gt;
| 4.1.7 || upper 8-bit of the 14-bit ADC sample (deprecated)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== High(er)-level support ==&lt;br /&gt;
&lt;br /&gt;
The scripts &amp;quot;mce_raw_acq&amp;quot; and &amp;quot;mce_raw_acq_1col&amp;quot; handle the details of disabling the sync-box, computing the number of frames the user probably wants, issuing the capture command, and reading out the data.  Use them like this:&lt;br /&gt;
&lt;br /&gt;
For 8-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g 1):&lt;br /&gt;
 mce_raw_acq 1&lt;br /&gt;
&lt;br /&gt;
This will create files &amp;lt;ctime&amp;gt;_raw, &amp;lt;ctime&amp;gt;_raw.run.&lt;br /&gt;
&lt;br /&gt;
For 1-column readout:&lt;br /&gt;
* Tune and configure your array.&lt;br /&gt;
* Run, for some RC (e.g. 1) and column (e.g. 3):&lt;br /&gt;
 mce_raw_acq_1col 1 3&lt;br /&gt;
&lt;br /&gt;
Due to differences in firmware implementation, mce_raw_acq and mce_raw_acq_1col have different default behaviours.&lt;br /&gt;
* mce_raw_acq:&lt;br /&gt;
** 8-column firmware supports the acquisition of either 8192 samples, or two full multiplexing frames, whichever is lower.&lt;br /&gt;
** By default, mce_raw_acq attempts to acquire this maximum number of samples.&lt;br /&gt;
* mce_raw_acq_1col:&lt;br /&gt;
** 1-column firmware supports the acquisition of 65536 samples, regardless of multiplexing settings.&lt;br /&gt;
** By default, mce_raw_acq will attempt to acquire 65536 samples.  It will change num_rows_reported to 32 in order to make the readout frame size go evenly into 65536.&lt;br /&gt;
&lt;br /&gt;
== Low-level support ==&lt;br /&gt;
&lt;br /&gt;
Raw mode readout is accomplished by first triggering the MCE to store 50 MHz data, and then reading out that data using a special data mode.&lt;br /&gt;
&lt;br /&gt;
* There are two RC parameters that have to be set for raw data acquisition:&lt;br /&gt;
** '''rc# captr_raw''' stores a snapshot of 50 MHz data, starting at the next row-return-to-zero.&lt;br /&gt;
*** In 8-column firmware, ''row_len'' samples of ''num_rows'' rows for '''2''' consecutive frames up to 8192 entries for each channel and stores them in MCE memory buffer for readout in raw mode.  The user must delay here before proceeding to read out the data.  The delay should be a few return-to-zeros.  (Computers are fast, and RTZ can take a long time if row_len is increased for noise measurements... so be generous when running from within scripts.)&lt;br /&gt;
*** In 1-column firmware, 65536 samples are stored for the column indicated by 'rc# readout_col_index' &lt;br /&gt;
** '''rc# data_mode''' determines the pixel-data readout mode.&lt;br /&gt;
*** The data_mode must be 3 for 8-column raw mode readout.&lt;br /&gt;
*** The data_mode must be 12 for 8-column raw mode readout.&lt;br /&gt;
* A typical sequence of commands for data acquisition is:&lt;br /&gt;
  wb cc ret_dat_s 1 1&lt;br /&gt;
  wb rc1 data_mode 3&lt;br /&gt;
  wb rc1 captr_raw 1&lt;br /&gt;
  acq_config ''filename'' rc1&lt;br /&gt;
  acq_go ''row_len*2''&lt;br /&gt;
&lt;br /&gt;
== Data handling ==&lt;br /&gt;
&lt;br /&gt;
Raw mode data files are MCE flatfiles and can be loaded using the usual mas_data.pro or mce_data.py programs.  However, the data should be time-ordered for meaningfullness.  This is done by re-ordering the dimensions and collapsing the row and time dimensions.&lt;br /&gt;
&lt;br /&gt;
In newer MASes, the reader programs are aware of data modes 3 and 12 and automatically reform the output data into an n_cols x n_samples array:&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw_col3').Read()&lt;br /&gt;
 print d.data.shape&lt;br /&gt;
   (1, 65536)&lt;br /&gt;
&lt;br /&gt;
If you wanted to do the unravelling yourself, though, you would do this (assuming 8-column raw mode):&lt;br /&gt;
 d = SmallMCEFile('1234000000_raw').Read(row_col=True, data_mode=0)&lt;br /&gt;
 _, nc, _ = d.data.shape&lt;br /&gt;
 d.data = d.data.transpose((1,2,0)).reshape((nc,-1))&lt;br /&gt;
&lt;br /&gt;
Or in IDL (it's practically a one-liner!):&lt;br /&gt;
 data = mas_data('1234000000_raw', /no_runfile, data_mode=0)&lt;br /&gt;
 ds = size(d)&lt;br /&gt;
 nc = ds[1]&lt;br /&gt;
 nt = ds[2]*ds[3]&lt;br /&gt;
 data_raw = reform(data, nc, nt)&lt;br /&gt;
&lt;br /&gt;
= Details =&lt;br /&gt;
&lt;br /&gt;
== Data storage and packaging ==&lt;br /&gt;
&lt;br /&gt;
* Once the raw-buffer of 8192 samples is full, no more samples are stored till a new captr_raw is issued.&lt;br /&gt;
* The raw-buffer is shipped out of MCE in a regular frame format (header + num_rows_reported*num_columns + checksum).  As compared with normal MCE flatfile data organization, in raw mode the time index takes the place of row.  At each time, all columns are reported.&lt;br /&gt;
* For rc1 only, for example, time indices t = [0, num_rows_reported-1] are reported in the first frame, with the offset of column c and time t being&lt;br /&gt;
 index = t*8 + c&lt;br /&gt;
* Subsequent frames contain subsequent data samples.  Since the number of time samples, per column, in a full multiplexing cycle of the MCE is row_len*num_rows, the number of readout frames required to record an entire MCE internal frame's-worth of raw data is equal to row_len (assuming that num_rows = num_rows_reported).&lt;br /&gt;
* The readout frame and index of a given time t, column c, is thus&lt;br /&gt;
 frame = floor[ (t*8 + c) / num_rows_reported ]&lt;br /&gt;
 index = (t*8 + c) mod num_rows_reported&lt;br /&gt;
* Since the number of clock ticks spent on each row is row_len, the row associated with time t is&lt;br /&gt;
 row = floor [ t / row_len ]&lt;br /&gt;
* It is possible to get raw mode data from multiple readout cards; in that case the data will be packaged in the usual way, with all columns reporting at each time.&lt;br /&gt;
* Schematically, the organization of raw data for num_rows = num_rows_reported = 33 and row_len = 100 can be represented as follows (here sNNNNNcXX represents a word containing the data for time sample NNNNN, column XX):&lt;br /&gt;
 (header of frame 0, 43 words)&lt;br /&gt;
 s0000c00 s0000c01 s0000c02 s0000c03 s0000c04 s0000c05 s0000c06 s0000c07&lt;br /&gt;
 s0001c00 s0001c01 s0001c02 s0001c03 s0001c04 s0001c05 s0001c06 s0001c07&lt;br /&gt;
 s0002c00 s0002c01 s0002c02 s0002c03 s0002c04 s0002c05 s0002c06 s0002c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0032c00 s0032c01 s0032c02 s0032c03 s0032c04 s0032c05 s0032c06 s0032c07&lt;br /&gt;
 (checksum of frame 0, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 1, 43 words)&lt;br /&gt;
 s0033c00 s0033c01 s0033c02 s0033c03 s0033c04 s0033c05 s0033c06 s0033c07&lt;br /&gt;
 ...&lt;br /&gt;
 s0065c00 s0065c01 s0065c02 s0065c03 s0065c04 s0065c05 s0065c06 s0065c07&lt;br /&gt;
 (checksum of frame 1, 1 word)&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
 &lt;br /&gt;
 (header of frame 199, 43 words)&lt;br /&gt;
 s6567c67 s6567c01 s6567c02 s6567c03 s6567c04 s6567c05 s6567c06 s6567c07&lt;br /&gt;
 ...&lt;br /&gt;
 s6599c00 s6599c01 s6599c02 s6599c03 s6599c04 s6599c05 s6599c06 s6599c07&lt;br /&gt;
 (checksum of frame 199, 1 word)&lt;br /&gt;
&lt;br /&gt;
* Unfortunately, collecting data for up to '''2''' internal MCE frames is hard-coded in firmware. Even if you reduce number of rows, you will be restricted by 2 frames. If you really want to look at more samples, then you may want to increase row_len instead and using row_order parameter of the address card, move your particular row of interest to the beginning of the frame.&lt;br /&gt;
&lt;br /&gt;
* readout_row_index parameter is ignored when data_mode is set to 3 or raw mode.&lt;br /&gt;
&lt;br /&gt;
* if num_rows_reported &amp;lt; num_rows, it takes more frames (to be exact: n = (num_rows*row_len*2/num_rows_reported) frames) to read all the data out.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Firmware ==&lt;br /&gt;
* To toggle between raw data firmware and filtering firmware, one must un-comment one or the other (not both) of the following data banks:&lt;br /&gt;
** i_raw_dat_bank in adc_sample_coadd.vhd, for enabling/disabling raw data.&lt;br /&gt;
** i_fsfb_wn11_Q, i_fsfb_wn12_Q, i_fsfb_wn21_Q, i_fsfb_wn22_Q in fsfb_fltr_regs.vhd, for enabling/disabling filtered data.&lt;br /&gt;
* For some versions of Quartus, a quartus.ini file must be present in the synthesis directory for the changes in RAM configurations to register.  The file contains the following line:&lt;br /&gt;
 rtl_no_super_dupe_reg = on&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2591</id>
		<title>Locking slopes</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2591"/>
		<updated>2009-04-17T09:16:25Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MCE/MAS parameters that affect locking slopes =&lt;br /&gt;
&lt;br /&gt;
== Slope controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters in [[Mce config template system | experiment.cfg]] affect the locking slopes:&lt;br /&gt;
&lt;br /&gt;
* '''sq2servo_gain''': sets the gain of the SQ2 servo and effectively determines the sign of the SA lock slope.&lt;br /&gt;
* '''sq1servo_gain''': sets the gain of the SQ1 servo and, with the sq2servo_gain, determines the SQ2 lock slope.&lt;br /&gt;
* '''default_servo_i''': determines the I gain of the MCE servo (rc# gaini#), and thus the sign of the locking slopeof the SQ1.&lt;br /&gt;
&lt;br /&gt;
== Plotting controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters affect plotting of locking slopes in IDL, as well as the choice of initial guesses for lock-points:&lt;br /&gt;
&lt;br /&gt;
* sq2servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ2 servo plots to which we expect to lock.&lt;br /&gt;
* sq1servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ1 servo plots to which we expect to lock.&lt;br /&gt;
&lt;br /&gt;
== Consistency between locking and plotting ==&lt;br /&gt;
&lt;br /&gt;
The above slope and plotting parameters should satisfy the following:&lt;br /&gt;
* sq2servo_slope =  -sign( sq2servo_gain / sq1servo_gain) &lt;br /&gt;
* sq1servo_slope =  -sign( sq1servo_gain / default_servo_i)&lt;br /&gt;
&lt;br /&gt;
These relations follow from the discussion in the sections below.&lt;br /&gt;
&lt;br /&gt;
Violation of the above will likely only result in misleading plots, and not bad locking.  Misleading plots can indirectly lead to a user setting up bad locking, however; so keep it clean.&lt;br /&gt;
&lt;br /&gt;
'''The sa_points.ps plot may be misleading''': the code (at time of writing) plots the positive-slope lock-points, regardless of any other parameters.&lt;br /&gt;
&lt;br /&gt;
Future code will eliminate sq2servo_slope and sq1servo_slope and determine all locking slopes from the servo gains... &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MCE and tuning servos =&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
We will need to deal with three servos.  One is the &amp;quot;MCE servo&amp;quot;, which is the fast servoing of the TES signal via adjustment of the SQ1 feedback.  The other two are the auto-tuning SQ2 and SQ1 servos, described [here | auto_setup_squids.pro]. &lt;br /&gt;
&lt;br /&gt;
In all cases, the servo is computed by measuring an error (&amp;lt;math&amp;gt;\Delta&amp;lt;/math&amp;gt; y), multiplying by a gain (g), and using this to correct the output (x):&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x = g~\Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the case of the MCE PID loop servo, we run with an I term only so we actually calculate&lt;br /&gt;
 &amp;lt;math&amp;gt;x = P ~\sum \Delta y&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
but differentially this is exactly &amp;lt;math&amp;gt;\Delta x = P * \Delta y&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE/MAS and sneaky signs ==&lt;br /&gt;
&lt;br /&gt;
There are no sneaky, extra signs in any of the MCE/MAS servo calculations.  This means that given an error (dy) and a gain g, we calculate the change in the feedback (dx) as:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and not&lt;br /&gt;
 &amp;lt;math&amp;gt;dx = -g~dy&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is a sneaky gain in the MCE servo, though; once the default_servo_i is set, the DAC value of the feedback is actually calculated as&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta FB = (I~dy) / 2^{12}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But there's no sneaky sign.  Just a sneaky gain.&lt;br /&gt;
&lt;br /&gt;
= The meaning of the plots =&lt;br /&gt;
&lt;br /&gt;
== Definition of a lock point ==&lt;br /&gt;
&lt;br /&gt;
Let the feedback signals on the three stages (in one channel) be &amp;lt;math&amp;gt;x_{SA}, x_{S2}, x_{S1}&amp;lt;/math&amp;gt;, and let the error signal be y.  Let s be the signal from the TES.  The error signal is obviously a function of all 4 numbers:&lt;br /&gt;
 &amp;lt;math&amp;gt;y = f(x_{SA}, x_{S2}, x_{S1}, t)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But for small variations about one point in this space, we can expand in differentials&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = a_1 dx_{SA} + a_2 dx_{S2} + a_3 dx_{S1} +  a_4 s&amp;lt;/math&amp;gt;&lt;br /&gt;
but it is convenient to reparametrize this to resemble the chain of amplifiers:&lt;br /&gt;
 &amp;lt;math&amp;gt; dy = m_{SA}(dx_{SA} - m_{S2}(dx_{S2} - m_{S1}(dx_{S1} - m_{TES} s)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So the 'slopes' m account for the instantaneous gain between the stages at the lock point.&lt;br /&gt;
&lt;br /&gt;
== Open loop ramps ==&lt;br /&gt;
&lt;br /&gt;
Note that lock points are not ultimately chosen as a result of the open loop ramps.  However, it is important to understand the relationship between what the open loop ramps and the settings for the auto-tuning and MCE servos.&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SA ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{S2}, x_{S1}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{SA}&amp;lt;/math&amp;gt;.  Thus identifying a lock point permits the measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{SA} = m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SQ1 ramp&amp;quot;, we hold &amp;lt;math&amp;gt;x_{SA}, x_{S2}&amp;lt;/math&amp;gt; and s constant, and plot y vs. &amp;lt;math&amp;gt;x_{S1}&amp;lt;/math&amp;gt;.  A slope measurement on this curve is a measurement of&lt;br /&gt;
 &amp;lt;math&amp;gt;dy / dx_{S1} = m_{SA} m_{S2} m_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
In servos, we ramp one stage's x while adjusting another x to keep the error at zero.&lt;br /&gt;
&lt;br /&gt;
Thus in the &amp;quot;SQ2 servo&amp;quot; step (where SQ2 FB is ramped and SQA FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{SA} = m_{S2} dx_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, this can only be accomplished via measurement of the error&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = -m_{SA} m_{S2} \Delta x_{S2}&amp;lt;/math&amp;gt;&lt;br /&gt;
so operationally we apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{SA} = - \Delta y / m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the ideal gain of the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S2} = -1/m_{SA}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;SQ1 servo&amp;quot; step (where SQ1 FB is ramped and SQ2 FB adjusted) we have:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S2} = m_{S1} dx_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
so we measure&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta y = m_{SA} m_{S2} m_{S1} \Delta x_{S1}&amp;lt;/math&amp;gt;&lt;br /&gt;
and apply&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S2} = \Delta y / (m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
so the ideal gain of the SQ1 servo is&lt;br /&gt;
 &amp;lt;math&amp;gt;g_{S1} = 1/(m_{SA} m_{S2})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== MCE servo I parameter ==&lt;br /&gt;
&lt;br /&gt;
When the MCE servo is activated, it cancels changes in TES current by adjusting the SQ1 FB:&lt;br /&gt;
 &amp;lt;math&amp;gt;dx_{S1} = m_{TES} ds&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
i.e.&lt;br /&gt;
 &amp;lt;math&amp;gt;\Delta x_{S1} = -\Delta y / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
and ideal gain is thus&lt;br /&gt;
 &amp;lt;math&amp;gt;I_{servo} = -1 / (m_{S1} m_{S2} m_{S3})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Consequences for tuning parameters ==&lt;br /&gt;
&lt;br /&gt;
We have expressed, above, the ideal gains for the servos as a function of the slopes of the ramp and servo curves from auto-tuning.  Solving these for the slopes as a function of the ideal gains yields the locking slopes' dependence on the signs of the gains:&lt;br /&gt;
&lt;br /&gt;
=== SA locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SA ramp) is determined by the gain in the SQ2 servo:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA}) =  -sgn(1/g_{S2})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ2 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SQ2 servo curve) is determined by the ratio of the gains in the SQ1 and SQ2 servos:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S2}) = -sgn(g_{S2}/g_{S1})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SQ1 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope on the SQ1 servo curve is determined by the ratio of the gains in the SQ1 servo and the MCE servo I term:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{S1}) = -sgn(g_{S1}/I)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But the sign of the locking slope on the SQ1 ramp curve is simply:&lt;br /&gt;
 &amp;lt;math&amp;gt;sgn(m_{SA} m_{S2} m_{S1}) = - sgn(1/I)&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2590</id>
		<title>Locking slopes</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Locking_slopes&amp;diff=2590"/>
		<updated>2009-04-17T08:45:56Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MCE/MAS parameters that affect locking slopes =&lt;br /&gt;
&lt;br /&gt;
== Slope controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters in [[MCE config template system | experiment.cfg]] affect the locking slopes:&lt;br /&gt;
&lt;br /&gt;
* '''sq2servo_gain''': sets the gain of the SQ2 servo and effectively determines the sign of the SA lock slope.&lt;br /&gt;
* '''sq1servo_gain''': sets the gain of the SQ1 servo and, with the sq2servo_gain, determines the SQ2 lock slope.&lt;br /&gt;
* '''default_servo_i''': determines the I gain of the MCE servo (rc# gaini#), and thus the sign of the locking slopeof the SQ1.&lt;br /&gt;
&lt;br /&gt;
== Plotting controls ==&lt;br /&gt;
&lt;br /&gt;
The following parameters affect plotting of locking slopes in IDL, as well as the choice of initial guesses for lock-points:&lt;br /&gt;
&lt;br /&gt;
* sq2servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ2 servo plots to which we expect to lock.&lt;br /&gt;
* sq1servo_slope in experiment.cfg: (+1 or -1) the sign of the slope in the SQ1 servo plots to which we expect to lock.&lt;br /&gt;
&lt;br /&gt;
== Consistency between locking and plotting ==&lt;br /&gt;
&lt;br /&gt;
The above slope and plotting parameters should satisfy the following:&lt;br /&gt;
* sq2servo_slope =  -sign( sq2servo_gain / sq1servo_gain) &lt;br /&gt;
* sq1servo_slope =  -sign( sq1servo_gain / default_servo_i)&lt;br /&gt;
&lt;br /&gt;
These relations follow from the discussion in the sections below.&lt;br /&gt;
&lt;br /&gt;
Violation of the above will likely only result in misleading plots, and not bad locking.  Misleading plots can indirectly lead to a user setting up bad locking, however; so keep it clean.&lt;br /&gt;
&lt;br /&gt;
'''The sa_points.ps plot may be misleading''': the code (at time of writing) plots the positive-slope lock-points, regardless of any other parameters.&lt;br /&gt;
&lt;br /&gt;
Future code will eliminate sq2servo_slope and sq1servo_slope and determine all locking slopes from the servo gains... &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MCE and tuning servos =&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
We will need to deal with three servos.  One is the &amp;quot;MCE servo&amp;quot;, which is the fast servoing of the TES signal via adjustment of the SQ1 feedback.  The other two are the auto-tuning SQ2 and SQ1 servos, described [here | auto_setup_squids.pro]. &lt;br /&gt;
&lt;br /&gt;
In all cases, the servo is computed by measuring an error (\Delta y), multiplying by a gain (g), and using this to correct the output (x):&lt;br /&gt;
 \Delta x = g \Delta y&lt;br /&gt;
&lt;br /&gt;
In the case of the MCE PID loop servo, we run with an I term only so we actually calculate&lt;br /&gt;
  x = P * \sum dy&lt;br /&gt;
but differentially this is exactly \Delta x = P * \Delta y.&lt;br /&gt;
&lt;br /&gt;
== MCE/MAS and sneaky signs ==&lt;br /&gt;
&lt;br /&gt;
There are no sneaky, extra signs in any of the MCE/MAS servo calculations.  This means that given an error (dy) and a gain g, we calculate the change in the feedback (dx) as:&lt;br /&gt;
 dx = g * dy&lt;br /&gt;
and not&lt;br /&gt;
 dx = -g * dy   (not used)&lt;br /&gt;
&lt;br /&gt;
There is a sneaky gain in the MCE servo, though; once the default_servo_i is set, the DAC value of the feedback is actually calculated as&lt;br /&gt;
 \Delta FB = (I dy) / 2^{12}&lt;br /&gt;
&lt;br /&gt;
But there's no sneaky sign.  Just a sneaky gain.&lt;br /&gt;
&lt;br /&gt;
= The meaning of the plots =&lt;br /&gt;
&lt;br /&gt;
== Definition of a lock point ==&lt;br /&gt;
&lt;br /&gt;
Let the feedback signals on the three stages (in one channel) be x_{SA}, x_{S2}, x_{S1}, and let the error signal be y.  Let s be the signal from the TES.  The error signal is obviously a function of all 4 numbers:&lt;br /&gt;
 y = f(x_{SA}, x_{S2}, x_{S1}, t)&lt;br /&gt;
&lt;br /&gt;
But for small variations about one point in this space, we can expand in differentials&lt;br /&gt;
 dy = a_1 dx_{SA} + a_2 dx_{S2} + a_3 dx_{S1} +  a_4 s&lt;br /&gt;
but it is convenient to reparametrize this to resemble the chain of amplifiers:&lt;br /&gt;
 dy = m_{SA}(dx_{SA} - m_{S2}(dx_{S2} - m_{S1}(dx_{S1} - m_{TES} s)&lt;br /&gt;
&lt;br /&gt;
So the 'slopes' m account for the instantaneous gain between the stages at the lock point.&lt;br /&gt;
&lt;br /&gt;
== Open loop ramps ==&lt;br /&gt;
&lt;br /&gt;
Note that lock points are not ultimately chosen as a result of the open loop ramps.  However, it is important to understand the relationship between what the open loop ramps and the settings for the auto-tuning and MCE servos.&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SA ramp&amp;quot;, we hold x_{S2}, x_{S1} and s constant, and plot y vs. x_{SA}.  Thus identifying a lock point permits the measurement of&lt;br /&gt;
 dy / dx_{SA} = m_{SA}&lt;br /&gt;
&lt;br /&gt;
For the &amp;quot;SQ1 ramp&amp;quot;, we hold x_{SA}, x_{S2} and s constant, and plot y vs. x_{S1}.  A slope measurement on this curve is a measurement of&lt;br /&gt;
 dy / dx_{S1} = m_{SA} m_{S2} m_{S1}&lt;br /&gt;
&lt;br /&gt;
== Servos ==&lt;br /&gt;
&lt;br /&gt;
In servos, we ramp one stage's x while adjusting another x to keep the error at zero.&lt;br /&gt;
&lt;br /&gt;
Thus in the &amp;quot;SQ2 servo&amp;quot; step (where SQ2 FB is ramped and SQA FB adjusted) we have:&lt;br /&gt;
 dx_{SA} = m_{S2} dx_{S2}&lt;br /&gt;
&lt;br /&gt;
However, this can only be accomplished via measurement of the error&lt;br /&gt;
 \Delta y = -m_{SA} m_{S2} \Delta x_{S2}&lt;br /&gt;
so operationally we apply&lt;br /&gt;
 \Delta x_{SA} = - \Delta y / m_{SA}&lt;br /&gt;
&lt;br /&gt;
This tells us the ideal gain of the SQ2 servo:&lt;br /&gt;
 g_{S2} = -1/m_{SA}&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;SQ1 servo&amp;quot; step (where SQ1 FB is ramped and SQ2 FB adjusted) we have:&lt;br /&gt;
 dx_{S2} = m_{S1} dx_{S1}&lt;br /&gt;
so we measure&lt;br /&gt;
 \Delta y = m_{SA} m_{S2} m_{S1} \Delta x_{S1}&lt;br /&gt;
and apply&lt;br /&gt;
 \Delta x_{S2} = \Delta y / (m_{SA} m_{S2}).&lt;br /&gt;
&lt;br /&gt;
so the ideal gain of the sq1 servo is&lt;br /&gt;
 g_{S1} = 1/(m_{SA} m_{S2})&lt;br /&gt;
&lt;br /&gt;
== MCE servo I parameter ==&lt;br /&gt;
&lt;br /&gt;
When the MCE servo is activated, it cancels changes in TES current by adjusting the SQ1 FB:&lt;br /&gt;
 dx_{S1} = m_{TES} ds&lt;br /&gt;
&lt;br /&gt;
i.e.&lt;br /&gt;
 \Delta x_{S1} = -\Delta y / (m_{S1} m_{S2} m_{S3})&lt;br /&gt;
and ideal gain is thus&lt;br /&gt;
 I_{servo} = -1 / (m_{S1} m_{S2} m_{S3})&lt;br /&gt;
&lt;br /&gt;
== Consequences for tuning parameters ==&lt;br /&gt;
&lt;br /&gt;
We have expressed, above, the ideal gains for the servos as a function of the slopes of the ramp and servo curves from auto-tuning.  Solving these for the slopes as a function of the ideal gains yields the locking slopes' dependence on the signs of the gains:&lt;br /&gt;
&lt;br /&gt;
=== SA locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SA ramp) is determined by the gain in the SQ2 servo:&lt;br /&gt;
 sign(m_{SA}) =  -sign(1/g_{S2})&lt;br /&gt;
&lt;br /&gt;
=== SQ2 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope (on the SQ2 servo curve) is determined by the ratio of the gains in the SQ1 and SQ2 servos:&lt;br /&gt;
 sign(m_{S2}) = -sign(g_{S2}/g_{S1})&lt;br /&gt;
&lt;br /&gt;
=== SQ1 locking point ===&lt;br /&gt;
&lt;br /&gt;
The locking slope on the SQ1 servo curve is determined by the ratio of the gains in the SQ1 servo and the MCE servo I term:&lt;br /&gt;
 sign(m_{S1}) = -sign(g_{S1}/I)&lt;br /&gt;
&lt;br /&gt;
But the sign of the locking slope on the SQ1 ramp curve is simply:&lt;br /&gt;
 sign(m_{SA} m_{S2} m_{S1}) = - sign(1/I)&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Python_data_and_runfile_modules&amp;diff=2584</id>
		<title>Python data and runfile modules</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Python_data_and_runfile_modules&amp;diff=2584"/>
		<updated>2009-04-05T22:10:50Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Recent changes:&lt;br /&gt;
* mce_script/trunk r408: Merged mce_runfile.py into mce_data.py.  Use mce_data.py for everything.&lt;br /&gt;
* mce_script/trunk r407: SmallMCEFile is smarter about frame counts, and less verbose unless challenged.&lt;br /&gt;
&lt;br /&gt;
The interfaces described here are based on mce_script/trunk r408.&lt;br /&gt;
&lt;br /&gt;
= mce_data.py and mce_runfile.py =&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
The module mce_data.py provide roughly the same functionality that [[ mas_data.pro ]] and [[ mas_runfile.pro and mas_runparam.pro | mas_runfile.pro ]] provide for IDL.&lt;br /&gt;
&lt;br /&gt;
In the latest versions of the scripts, mce_runfile.py is no longer needed as the MCERunfile class has been merged into mce_data.py&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== System setup ==&lt;br /&gt;
&lt;br /&gt;
Make sure python can find mce_data.py (and possibly mce_runfile.py).  $MAS_PYTHON should be in your PYTHONPATH environment variable.&lt;br /&gt;
 mce@mce-ubc-2:~$ export PYTHONPATH=$PYTHONPATH:$MAS_PYTHON&lt;br /&gt;
&lt;br /&gt;
This should be done automatically if you &amp;quot;source $MAS_ROOT/template/mas_env.bash&amp;quot; in your .bashrc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= MCEFile / SmallMCEFile classes =&lt;br /&gt;
&lt;br /&gt;
The MCEFile class is an alias for the SmallMCEFile class.  These can be used interchangeably.  The &amp;quot;Small&amp;quot; is just meant to suggest that you shouldn't try to load more frame data than your machine's RAM can handle.  The module will complain and prevent you from loading more than 100 MB of data in one go. &lt;br /&gt;
&lt;br /&gt;
== Basic usage ==&lt;br /&gt;
&lt;br /&gt;
In python, import the 'mce_data' module and create a SmallMCEFile object:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; from mce_data import *&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; fn = '/data/cryo/current_data/data002'&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; f = SmallMCEFile(fn)&lt;br /&gt;
 &lt;br /&gt;
To suppress loading of the runfile, or override the runfile name, use one of these:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; f = SmallMCEFile( fn, runfile=False)&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; f = SmallMCEFIle( fn, runfile='template_runfile.run')&lt;br /&gt;
&lt;br /&gt;
Then load the data like this:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read()&lt;br /&gt;
&lt;br /&gt;
The data member of d is a 2d array, [n_detectors, n_frames]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data.shape&lt;br /&gt;
 (328, 100)&lt;br /&gt;
&lt;br /&gt;
The list of rows and columns associated with the 328 detectors is available through col_list and row_list:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.col_list&lt;br /&gt;
 [8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15,&lt;br /&gt;
  8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15,&lt;br /&gt;
  ... &lt;br /&gt;
  8, 9, 10, 11, 12, 13, 14, 15]&lt;br /&gt;
&lt;br /&gt;
To display a pixel's values in all the data frames of a file:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data[col+row*8]&lt;br /&gt;
&lt;br /&gt;
Or to see pixel index i:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data[i,:]&lt;br /&gt;
&lt;br /&gt;
To display all pixels in frame f:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data[:,f]&lt;br /&gt;
&lt;br /&gt;
The data from the first frame header is available in the header member:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.header&lt;br /&gt;
 {'status': 2052, 'data_rate': 47, 'userfield': 0, 'num_rows_reported': 41,&lt;br /&gt;
  'runfile_id': 1231969044, 'row_len': 64, 'header_version': 6, 'rc_present':&lt;br /&gt;
  [False, True, False, False], 'address0_ctr': 23142826, 'num_rows': 41,&lt;br /&gt;
  'ramp_value': 0, 'frame_counter': 0, 'sync_box_num': 0, 'ramp_addr': 0}&lt;br /&gt;
&lt;br /&gt;
== Raw frame data ==&lt;br /&gt;
&lt;br /&gt;
To get raw frames (including header and checksum), pass &amp;quot;raw_frames=True&amp;quot; to the Read call:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; raw = f.Read(raw_frames=True)&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; raw.shape&lt;br /&gt;
 (100, 1100)&lt;br /&gt;
&lt;br /&gt;
Then you can look at, e.g., the checksum:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; raw[:,1099]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; dd[:,1099]&lt;br /&gt;
 array([918158926, 918144283, 918156148, 918156615, 918153934, 918159205,&lt;br /&gt;
        ...&lt;br /&gt;
        918146379, 918145339, 918158232, 918146376], dtype=int32)&lt;br /&gt;
&lt;br /&gt;
== Force row/column ordering ==&lt;br /&gt;
&lt;br /&gt;
To reformat the d.data array so that its indices are (row, column, frame), pass &amp;quot;row_col=True&amp;quot; to Read:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(row_col=True)&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data.shape&lt;br /&gt;
 (33, 32, 100)&lt;br /&gt;
&lt;br /&gt;
Then to see frame k:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data[:,:,k]&lt;br /&gt;
&lt;br /&gt;
== Extracting fields from mixed mode data ==&lt;br /&gt;
&lt;br /&gt;
The MCE signal names, for mce_data purposes, are:&lt;br /&gt;
 error    - co-added error (reference mode 0)&lt;br /&gt;
 fb       - feedback in sq1 DAC units (reference mode 1)&lt;br /&gt;
 fb_filt  - filtered feedback (reference mode 2)&lt;br /&gt;
 fj       - flux jump counter&lt;br /&gt;
&lt;br /&gt;
For mixed modes, the default is to extract the feedback or filtered feedback signal by default.  To extract an alternate signal, pass &amp;quot;field=...&amp;quot; to the Read call:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(field='fj')&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data&lt;br /&gt;
  array([[0,0,0,0,1,0,0,0,0,&lt;br /&gt;
  ...&lt;br /&gt;
&lt;br /&gt;
It is possible to extract a set of fields simultaneously, using the &amp;quot;fields=&amp;quot; option in the Read call.  This will override the &amp;quot;field=&amp;quot; option.  The extracted fields appear in a dictionary in d.data.&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(fields=['fj', 'fb_filt'])&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data['fj']&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data['fb_filt']&lt;br /&gt;
     ...&lt;br /&gt;
&lt;br /&gt;
You can extract all fields by passing &amp;quot;fields='all'&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(fields='all')&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data['fj']&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data['fb_filt']&lt;br /&gt;
     ...&lt;br /&gt;
&lt;br /&gt;
To force the bitfield extraction code to assume a particular data_mode, pass &amp;quot;data_mode=...&amp;quot; to Read.&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(data_mode=10, field='fb_filt')&lt;br /&gt;
&lt;br /&gt;
= MCERunfile class =&lt;br /&gt;
&lt;br /&gt;
Note that in older versions of mce_script, the MCERunfile class is contained in the file mce_runfile.py.  In that case, replace &amp;quot;from mce_data import ...&amp;quot; with &amp;quot;from mce_runfile import ...&amp;quot; in what follows.&lt;br /&gt;
&lt;br /&gt;
== Load a runfile ==&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; from mce_runfile import *&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; runfile_name = '/data/cryo/current_data/1220531790_dat.run'&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; rf = MCERunfile(runfile_name)&lt;br /&gt;
&lt;br /&gt;
== Simple data ==&lt;br /&gt;
&lt;br /&gt;
Recall that the structure of [[ Runfile format v2 | runfiles ]] is such that a line of data has an address defined by its 'block' and 'key' (where the key is the tag + specifiers...).  The contents of rf include a dictionary of dictionaries of all the block / key pairs.  For example:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.data['HEADER']['RB rc1 data_mode']&lt;br /&gt;
  00000010&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.data['SQUID']['SQ_tuning_dir']&lt;br /&gt;
  1220510497&lt;br /&gt;
&lt;br /&gt;
However, the member function &amp;quot;Item&amp;quot; allows us to repackage the runfile data by specifying a data type ('string', 'int', 'float') and whether or not we expect an array or a single value.  For example:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.Item('HEADER', 'RB rc1 data_mode')&lt;br /&gt;
 ['00000010']&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.Item('HEADER', 'RB rc1 data_mode', type='int')&lt;br /&gt;
 [10]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.Item('HEADER', 'RB rc1 data_mode', type='int', array=False)&lt;br /&gt;
 10&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.Item('HEADER', 'RB rc1 data_mode', type='float')&lt;br /&gt;
 [10.0]&lt;br /&gt;
&lt;br /&gt;
== Two-dimensional data ==&lt;br /&gt;
&lt;br /&gt;
Some runfile entries are really 2d arrays, entered row by row.  For example, in the 'IV' block there are per-column entries for responsivity:&lt;br /&gt;
 &amp;lt;IV&amp;gt;&lt;br /&gt;
 ...&lt;br /&gt;
 &amp;lt;Responsivity(W/DACfb)_C0&amp;gt; 1.92290e-16 1.92119e-16 0.00000 1.93100e-16 1.92978e-16 1.89769e-16 1.91119e-16 ...&lt;br /&gt;
 &amp;lt;Responsivity(W/DACfb)_C1&amp;gt; 0.00000 1.82838e-16 0.00000 1.84197e-16 1.84822e-16 1.84447e-16 1.83693e-16 ...&lt;br /&gt;
 &amp;lt;Responsivity(W/DACfb)_C2&amp;gt; 1.89962e-16 1.88649e-16 0.00000 1.85339e-16 1.84462e-16 1.82965e-16 1.84045e-16 ...&lt;br /&gt;
 ...&lt;br /&gt;
 &amp;lt;/IV&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These can be extracted at once if you pass a printf-style format string to the member function Item2d:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; a = rf.Item2d('IV', 'Responsivity(W/DACfb)_C%i', type='float')&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print len(a)&lt;br /&gt;
 32&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print len(a[0])&lt;br /&gt;
 33 &lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print a[2][1]&lt;br /&gt;
 1.88649e-16&lt;br /&gt;
&lt;br /&gt;
(i.e. a[2][1] is the responsivity for column 2, row 1.)&lt;br /&gt;
&lt;br /&gt;
Some MCE data are spread across readout cards... e.g. adc_offset is stored in rc# adc_offset#.  To accumulate all of these into a single array, use Item2dRC, passing the format in a way such that it can be evaluated first with the RC number and then with the column index... :&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; a = rf.Item2dRC('HEADER', 'RB rc%i adc_offset%%i', type='int')&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; len(a)&lt;br /&gt;
 32&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; len(a[0])&lt;br /&gt;
 41&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
	<entry>
		<id>https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Python_data_and_runfile_modules&amp;diff=2583</id>
		<title>Python data and runfile modules</title>
		<link rel="alternate" type="text/html" href="https://cmbr.phas.ubc.ca/mcewiki/index.php?title=Python_data_and_runfile_modules&amp;diff=2583"/>
		<updated>2009-04-05T22:10:18Z</updated>

		<summary type="html">&lt;p&gt;174.6.181.2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Recent changes:&lt;br /&gt;
* mce_script/trunk r408: Merged mce_runfile.py into mce_data.py.  Use mce_data.py for everything.&lt;br /&gt;
* mce_script/trunk r407: SmallMCEFile is smarter about frame counts, and less verbose unless challenged.&lt;br /&gt;
&lt;br /&gt;
The interfaces described here are based on mce_script/trunk r408.&lt;br /&gt;
&lt;br /&gt;
= mce_data.py and mce_runfile.py =&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
The module mce_data.py provide roughly the same functionality that [[ mas_data.pro ]] and [[ mas_runfile.pro and mas_runparam.pro | mas_runfile.pro ]] provide for IDL.&lt;br /&gt;
&lt;br /&gt;
In the latest versions of the scripts, mce_runfile.py is no longer needed as the MCERunfile class has been merged into mce_data.py&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== System setup ==&lt;br /&gt;
&lt;br /&gt;
Make sure python can find mce_data.py (and possibly mce_runfile.py).  $MAS_PYTHON should be in your PYTHONPATH environment variable.&lt;br /&gt;
 mce@mce-ubc-2:~$ export PYTHONPATH=$PYTHONPATH:$MAS_PYTHON&lt;br /&gt;
&lt;br /&gt;
This should be done automatically if you &amp;quot;source $MAS_ROOT/template/mas_env.bash&amp;quot; in your .bashrc&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= MCEFile / SmallMCEFile classes =&lt;br /&gt;
&lt;br /&gt;
The MCEFile class is an alias for the SmallMCEFile class.  These can be used interchangeably.  The &amp;quot;Small&amp;quot; is just meant to suggest that you shouldn't try to load more frame data than your machine's RAM can handle.  The module will complain and prevent you from loading more than 100 MB of data in one go. &lt;br /&gt;
&lt;br /&gt;
== Basic usage ==&lt;br /&gt;
&lt;br /&gt;
In python, import the 'mce_data' module and create a SmallMCEFile object:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; from mce_data import *&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; fn = '/data/cryo/current_data/data002'&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; f = SmallMCEFile(fn)&lt;br /&gt;
 &lt;br /&gt;
To suppress loading of the runfile, or override the runfile name, use one of these:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; f = SmallMCEFile( fn, runfile=False)&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; f = SmallMCEFIle( fn, runfile='template_runfile.run')&lt;br /&gt;
&lt;br /&gt;
Then load the data like this:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read()&lt;br /&gt;
&lt;br /&gt;
The data member of d is a 2d array, [n_detectors, n_frames]:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data.shape&lt;br /&gt;
 (328, 100)&lt;br /&gt;
&lt;br /&gt;
The list of rows and columns associated with the 328 detectors is available through col_list and row_list:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.col_list&lt;br /&gt;
 [8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15,&lt;br /&gt;
  8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15,&lt;br /&gt;
  ... &lt;br /&gt;
  8, 9, 10, 11, 12, 13, 14, 15]&lt;br /&gt;
&lt;br /&gt;
To display a pixel's values in all the data frames of a file:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data[col+row*8]&lt;br /&gt;
&lt;br /&gt;
Or to see pixel index i:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data[i,:]&lt;br /&gt;
&lt;br /&gt;
To display all pixels in frame f:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data[:,f]&lt;br /&gt;
&lt;br /&gt;
The data from the first frame header is available in the header member:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.header&lt;br /&gt;
 {'status': 2052, 'data_rate': 47, 'userfield': 0, 'num_rows_reported': 41,&lt;br /&gt;
  'runfile_id': 1231969044, 'row_len': 64, 'header_version': 6, 'rc_present':&lt;br /&gt;
  [False, True, False, False], 'address0_ctr': 23142826, 'num_rows': 41,&lt;br /&gt;
  'ramp_value': 0, 'frame_counter': 0, 'sync_box_num': 0, 'ramp_addr': 0}&lt;br /&gt;
&lt;br /&gt;
== Raw frame data ==&lt;br /&gt;
&lt;br /&gt;
To get raw frames (including header and checksum), pass &amp;quot;raw_frames=True&amp;quot; to the Read call:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; raw = f.Read(raw_frames=True)&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; raw.shape&lt;br /&gt;
 (100, 1100)&lt;br /&gt;
&lt;br /&gt;
Then you can look at, e.g., the checksum:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; raw[:,1099]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; dd[:,1099]&lt;br /&gt;
 array([918158926, 918144283, 918156148, 918156615, 918153934, 918159205,&lt;br /&gt;
        ...&lt;br /&gt;
        918146379, 918145339, 918158232, 918146376], dtype=int32)&lt;br /&gt;
&lt;br /&gt;
== Force row/column ordering ==&lt;br /&gt;
&lt;br /&gt;
To reformat the d.data array so that its indices are (row, column, frame), pass &amp;quot;row_col=True&amp;quot; to Read:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(row_col=True)&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data.shape&lt;br /&gt;
 (33, 32, 100)&lt;br /&gt;
&lt;br /&gt;
Then to see frame k:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d.data[:,:,k]&lt;br /&gt;
&lt;br /&gt;
== Extracting fields from mixed mode data ==&lt;br /&gt;
&lt;br /&gt;
The MCE signal names, for mce_data purposes, are:&lt;br /&gt;
 error    - co-added error (reference mode 0)&lt;br /&gt;
 fb       - feedback in sq1 DAC units (reference mode 1)&lt;br /&gt;
 fb_filt  - filtered feedback (reference mode 2)&lt;br /&gt;
 fj       - flux jump counter&lt;br /&gt;
&lt;br /&gt;
For mixed modes, the default is to extract the feedback or filtered feedback signal by default.  To extract an alternate signal, pass &amp;quot;field=...&amp;quot; to the Read call:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(field='fj')&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data&lt;br /&gt;
  array([[0,0,0,0,1,0,0,0,0,&lt;br /&gt;
  ...&lt;br /&gt;
&lt;br /&gt;
It is possible to extract a set of fields simultaneously, using the &amp;quot;fields=&amp;quot; option in the Read call.  This will override the &amp;quot;field=&amp;quot; option.  The extracted fields appear in a dictionary in d.data.&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(fields=['fj', 'fb_filt'])&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data['fj']&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data['fb_filt']&lt;br /&gt;
     ...&lt;br /&gt;
&lt;br /&gt;
You can extract all fields by passing &amp;quot;fields='all'&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(fields='all')&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data['fj']&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print d.data['fb_filt']&lt;br /&gt;
     ...&lt;br /&gt;
&lt;br /&gt;
To force the bitfield extraction code to assume a particular data_mode, pass &amp;quot;data_mode=...&amp;quot; to Read.&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; d = f.Read(data_mode=10, field='fb_filt')&lt;br /&gt;
&lt;br /&gt;
= mce_runfile.py =&lt;br /&gt;
&lt;br /&gt;
Note that in older versions of mce_script, the MCERunfile class is contained in the file mce_runfile.py.  In that case, replace &amp;quot;from mce_data import ...&amp;quot; with &amp;quot;from mce_runfile import ...&amp;quot; in what follows.&lt;br /&gt;
&lt;br /&gt;
== Load a runfile ==&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; from mce_runfile import *&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; runfile_name = '/data/cryo/current_data/1220531790_dat.run'&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; rf = MCERunfile(runfile_name)&lt;br /&gt;
&lt;br /&gt;
== Simple data ==&lt;br /&gt;
&lt;br /&gt;
Recall that the structure of [[ Runfile format v2 | runfiles ]] is such that a line of data has an address defined by its 'block' and 'key' (where the key is the tag + specifiers...).  The contents of rf include a dictionary of dictionaries of all the block / key pairs.  For example:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.data['HEADER']['RB rc1 data_mode']&lt;br /&gt;
  00000010&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.data['SQUID']['SQ_tuning_dir']&lt;br /&gt;
  1220510497&lt;br /&gt;
&lt;br /&gt;
However, the member function &amp;quot;Item&amp;quot; allows us to repackage the runfile data by specifying a data type ('string', 'int', 'float') and whether or not we expect an array or a single value.  For example:&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.Item('HEADER', 'RB rc1 data_mode')&lt;br /&gt;
 ['00000010']&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.Item('HEADER', 'RB rc1 data_mode', type='int')&lt;br /&gt;
 [10]&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.Item('HEADER', 'RB rc1 data_mode', type='int', array=False)&lt;br /&gt;
 10&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print rf.Item('HEADER', 'RB rc1 data_mode', type='float')&lt;br /&gt;
 [10.0]&lt;br /&gt;
&lt;br /&gt;
== Two-dimensional data ==&lt;br /&gt;
&lt;br /&gt;
Some runfile entries are really 2d arrays, entered row by row.  For example, in the 'IV' block there are per-column entries for responsivity:&lt;br /&gt;
 &amp;lt;IV&amp;gt;&lt;br /&gt;
 ...&lt;br /&gt;
 &amp;lt;Responsivity(W/DACfb)_C0&amp;gt; 1.92290e-16 1.92119e-16 0.00000 1.93100e-16 1.92978e-16 1.89769e-16 1.91119e-16 ...&lt;br /&gt;
 &amp;lt;Responsivity(W/DACfb)_C1&amp;gt; 0.00000 1.82838e-16 0.00000 1.84197e-16 1.84822e-16 1.84447e-16 1.83693e-16 ...&lt;br /&gt;
 &amp;lt;Responsivity(W/DACfb)_C2&amp;gt; 1.89962e-16 1.88649e-16 0.00000 1.85339e-16 1.84462e-16 1.82965e-16 1.84045e-16 ...&lt;br /&gt;
 ...&lt;br /&gt;
 &amp;lt;/IV&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These can be extracted at once if you pass a printf-style format string to the member function Item2d:&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; a = rf.Item2d('IV', 'Responsivity(W/DACfb)_C%i', type='float')&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print len(a)&lt;br /&gt;
 32&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print len(a[0])&lt;br /&gt;
 33 &lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; print a[2][1]&lt;br /&gt;
 1.88649e-16&lt;br /&gt;
&lt;br /&gt;
(i.e. a[2][1] is the responsivity for column 2, row 1.)&lt;br /&gt;
&lt;br /&gt;
Some MCE data are spread across readout cards... e.g. adc_offset is stored in rc# adc_offset#.  To accumulate all of these into a single array, use Item2dRC, passing the format in a way such that it can be evaluated first with the RC number and then with the column index... :&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; a = rf.Item2dRC('HEADER', 'RB rc%i adc_offset%%i', type='int')&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; len(a)&lt;br /&gt;
 32&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; len(a[0])&lt;br /&gt;
 41&lt;/div&gt;</summary>
		<author><name>174.6.181.2</name></author>
		
	</entry>
</feed>