Saturday, February 25, 2023

X-Ray Source Controller for MOXTEK and AMPTEK Mini X-Ray tubes

A followup on this post this post

 I needed controller for the Magnum series 50kV / 10W MOXTEK X-Ray source - as it turns out the FTC-200 controller, once sold by MOXTEK is no longer available (it was discontinued due components availability) and the Moxtek sales engineer told me - "We expect customers to develop their own controllers". 

This was not a big deal - their FTC-200 controller has very basic functionality anyways and lacking some features I really needed, so I went ahead and developed my own design to control the MOXTEK X-Ray tube.

Currently, MOXTEK tubes are available in one of 3 configuration - built-in USB controller, I2C control and Analog Interface. The MAGNUM tube I am using is equipped with the analog interface, but it should be quite easy to add the I2C control capabilities to the controller design as well.

One of my design goals is to have a stand-alone unit with no PC required. I don't want to fumble with numerous PC applications while doing XRF and prefer to have a piece of hardware with actual buttons and dials to adjust the X-ray tube parameters and to operate it.

I was pleasantly surprised to find out that the AMPTEK Mini-X2 tube uses the same electrical interface as the MOXTEK Magnum series tubes so my controller will work for AMPTEK Mini-X2 just as well.

Simplified block-diagram of XTC-2000

My source controller is based on the nRF52840 System-on-a-Chip (SoC) using Cortex M4F processor and employs 6 control channels as required by the x-ray source interface - 4 Analog and 2 digital channels. Of these 6 channels, there are 2 Analog outputs (driven by 12-bit precision DACs), used for setting up tube's High Voltage and Emission Current parameters and 1 digital output (5V TTL signal) to turn the source ON / OFF. There are also 2 Analog inputs (sampled with a 12-bit ADC) to monitor the x-ray tube's working parameters as they are returned by the Moxtek HV PS module and a digital input (5V TTL signal) to report when the beam is ON and stable (The filament is fully heated and ready). 

I had to employ Level shifters as the nRF52840 is a 3.3V chip and the MOXTEK module has 5V TTL levels for the digital signals. Furthermore, the voltage ranges on the Analog output channels are 0-to-4VDC so I had to use the 4.096V internal DAC reference voltage which means the DAC must be powered with 5V (in reality, the reference is 2.048V and the output op-amp buffer of the DAC is switched to 2X GAIN mode, but still 5VDC DAC power is required) 

For the Analog inputs, I used precision voltage dividers to bring down the Monitor channel voltages in the range of 0-to-3VDC and then used the built-in ADC reference of 0.6V with gain of 5x.

There is also 5th Analog Input channel, internal to the controller, with its own voltage divider, used to monitor the Low-Voltage Main Input Power and to inhibit controller operation if the controller's and tube's input voltage is not within the nominal range. 

OSH Park service delivered again beautiful, high-quality PCBs. The ordering process is very simple and a pure joy - I almost feel sorry I don't have more PCB projects to order. 
The PCB design was done with Autodesk Eagle but I am not big fan of what Autodesk is doing with Eagle (it used to be my favorite PCB app) and very likely to switch over to KiCad in the near future.

The assembled and ready X-Ray Source controller - XTC-2000 (a.k.a. "X-Ray Tube Commander 2000" :-) 
(Chat GPT suggestion :-)

Using a rotary encoder with a pushbutton makes the UI really quick and intuitive. The button (knob-press) is used to enter adjustment mode and the user can dial first the whole number and then the tenths after the decimal point for each parameter separately.
After entering Set mode, the encoder's push-button scrolls through different digit positions, indicated by a blinking cursor and spinning the knob changes the value. 
The rotary encoder is equipped with its own microcontroller (Atmel SAM D09) which takes care of all of the quadrature input stuff - counts, phase-detection, timing, etc. and just reports the actual tick count, delta, etc over I2C bus to the MCU. This makes the Encoder really fast and easy to use and I can reset the tick counter with a command if needed. The encoder breakout can also generate interrupt on button press or encoder rotation.

The complete and working controller during bench-testing and DAC/ADC non-linearity compensation and alignment. The white (unpopulated in this picture) 4-pin JST connector near the encoder is AUX I2C expansion connector, used for the X-ray tube's temperature sensor or controlling a tube with I2C interface.

Currently, the code is complete and mature, the core functionality is all done and bug-free thus "Version 1.0" release
In the unlikely event of some commercial interest, I might write a more elaborate menu system for setting up various tube types, internal parameters and calibration values, but even at this stage, XTC-2000 has more features, better functionality and better ergonomics than both, the discontinued Moxtek FTC-200 controller and the entirely software-controlled Amptek controller. 

In a nutshell - there are 3 modes of operation - MOMENTARY (X-Ray is emitted only while the OPERATE button is pressed), TOGGLE (X-Ray beam is latched, on/off with each press of the OPERATE button) and COUNTDOWN (the user can dial duration in seconds for the beam and start the Timer)

There are many safety features implemented - hardware lockout, software lockout, preventing accidental exposure, emergency beam shutdown, control voltages power-down, tube shut-off watchdog and so on...

In addition, there is a number of features looking after the tube's health as minimum emission time, cooling timeout, temperature alerts, isopower curve ensuring maximum power is never exceeded, mains voltage drop and many more.

As part of the safety and tube's health features, I added external temperature sensing and monitoring using MCP9809 chip.

While designing the PCB, I added an extra I2C bus connector for future expansion such as temperature sensing and control of I2C tube.

The sensor I am using is MCP9808 - a very accurate and precise chip with I2C interface. Resolution is actually much better than 0.25°C but for my purpose 1° Celsius is completely sufficient.

The controller constantly monitors the temperature of the tube, and it will shut it off if temperature exceeds +60°C and the tube will not be disabled until it cools down to below +55°C. The sensor presence is auto-detected on startup - if the I2C cable is not plugged in, the controller will work normally, just without any temperature related features.

The critical part here is the connection cable between the controller and the MCP9808 breakout board - the cable must be fully shielded due to the proximity to the tube's HV cables and must be of very low capacitance as the I2C bus does not tolerate high capacitance on the signal lines or the useable bus speed will begin to drop.  At 70cm cable length the sensor works perfectly well. The cable I used was foil-shielded 4-conductor USB cable.

The last thing currently pending on my development list is a suitable enclosure.

Update: As part of the tube's diagnostics, I added a check for deviation from the requested parameters - if the controller detects a difference between what is requested from the tube and what is returned, it will generate "Tube Error" message with a 3-digit error code - each digit represents one of the 3 critical parameters (Filament ready, High Voltage and Emission Current) and the value represents the type of deviation. This makes it really easy and quickly to understand what is going on with the x-ray tube. The check begins 2 seconds after the tube is turned on, allowing time for all parameters to stabilize. There is an option for the user to turn off temporarily this check if needed.