Governance by those who do the work.

Friday, April 10, 2015

Temperature Sensor Calibration

Having gotten the digital-to-analog and analog-to-digital conversions working while connected to each other, I plugged the STM32F3DISCOVERY board into my apparatus and started to debug the program to do analog-to-digital conversions of the LM35CZ temperature sensors. The initial readings were quite noisy; I traced this back to power supply noise caused by current fluctuations from the STM32F3DISCOVERY LEDs being switched on and off. I changed the program to keep the LEDs off during conversions and improved the power supply conditioning. The STM32F3DISCOVERY board consumes about 90.mA while running.

I found that the plate heater was slightly heating even though my program had the DAC controlling it set to 0. It turns out that when its output buffer is enabled, the STM32F303VCTx isn't specified to drive that output below 0.2V. Disabling the buffer reduced the output to a few millivolts.

The next task was to calibrate the temperature sensors. The calculations for measurement of convection are most sensitive to the time-derivative of the plate temperature and the difference between temperatures of the plate and ambient air. I attached the two ambient sensors ("ambient" and "free") to the back of the plate with thermal adhesive so that they would be at the same temperature. The statistics of (triple) 621 samples taken once per second are:

nREPS = 1ambientplatefreeoffset
mean:1696.751667.321734.46-29
variance:15.5816.659.83
mean:1.37.V1.34.V1.40.V-24.mV
variance:13.mV13.mV7.9.mV
mean:20.84C20.47C21.30C-0.36C
variance:0.19C0.20C0.12C

The plate-ambient offset is about -29 LSB = -24.mV = -0.36C. The 13.mV variance is rather large and matches measurements made by a RMS voltmeter at the ADC inputs; this bodes ill for the time-derivative of the plate temperature.

Note that voltage is measuread at the ADC input. There is a voltage gain of 6.56 from each LM35CZ (10.mV/C) output to the ADC input.

The STM32F303VCTx datasheet specifies a total unadjusted error of +/-4.5 LSB for the single-ended ADC at 25C and with a 3.3V supply.

The 16 LSB variance is much larger than the ADC error; thus it will act as a dither and smooth discontinuities in the ADC transfer function. So I rewrote the program to sum the result of converting each signal 16 times (per second). The statistics of 943 readings averaged over 16 conversions apiece are:

nREPS = 1ambientplatefreeoffset
mean:1702.791669.571736.16-33
variance:3.043.031.47
mean:1.37.V1.35.V1.40.V-27.mV
variance:2.4.mV2.4.mV1.2.mV
mean:20.91C20.50C21.32C-0.41C
variance:0.04C0.04C0.02C

The variance is reduced by a factor of 5, which will greatly reduce the effect of noise on the time-derivative of plate temperature.

This time the plate-ambient offset is about -33 LSB = -27.mV = -0.41C. All three temperatures are higher in the averaged test than in the single conversion test. This and subsequent sample runs in a thermostatically controlled building show that ambient and plate temperatures change enough to hamper calibration. The problem was worse when the plate was heated because the ambient sensor had only a small contact area with the plate, causing a temperature gradient which would be indistinguishable from a gain error.

So I fitted some insulation over the temperature sensors to protect them from air currents. This reduced the plate-ambient offset by an order of magnitude!

nREPS = 1ambientplatefreeoffset
mean:2173.752170.442230.43-3
variance:2.853.802.65
mean:1.75.V1.75.V1.80.V-2.7.mV
variance:2.3.mV3.1.mV2.1.mV
mean:26.69C26.65C27.39C-0.04C
variance:0.04C0.05C0.03C

A (304s) run near 20C also shows an offset smaller than the variance and guaranteed minimum offsets of the components.

nREPS = 1ambientplatefreeoffset
mean:1596.041598.531665.272
variance:3.013.001.37
mean:1.29.V1.29.V1.34.V2.0.mV
variance:2.4.mV2.4.mV1.1.mV
mean:19.60C19.63C20.45C0.03C
variance:0.04C0.04C0.02C

So the measurement program will not need to apply offset and scale corrections to the plate-ambient temperature difference. The ambient and plate sensors came from the same lot, the free sensor from a different batch. To convert the free temperature to the equivalent ambient temperature, multiply by 1.023 and subtract 1.318C.

Sunday, March 22, 2015

Programming the STM32F3-Discovery

http://www.st.com/web/en/catalog/tools/FM116/SC959/SS1532/LN1848/PF254044?sc=stm32f3discovery is the STM32F3DISCOVERY evaluation board I purchased. http://www.st.com/st-web-ui/static/active/jp/resource/technical/document/user_manual/DM00063382.pdf is Feb 2013 "UM1570 User manual STM32F3DISCOVERY Discovery kit for STM32F303xx microcontrollers".

STMicroelectronics offers a MS-Windows software named ST32CubeMX which enables a designer to configure a STM microprocessor and generates C and assembly code for driving it. http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00104712.pdf is the Jan 2015 "UM1718 User manual STM32CubeMX for STM32 configuration and initialization C code generation".  In order to generate code for compilation with the Linux GCC toolchain, choose "TrueSTUDIO" as the toolchain.

When I purchased a STM32F3-discovery board last year, I downloaded ST32CubeMX version 1.0.  There are several projects using the Linux GCC toolchain to compile for STM processors which I found online.  But these projects use ST32CubeMX version 1.1.0; they are incompatible with the files generated by ST32CubeMX-1.0.  So I downloaded the latest ST32CubeMX, which turned out to be version 1.1.1.  The library functions have been renamed in ST32CubeMX-1.1.1 and the directories have been reorganized, so the code it generates is incompatible with both earlier versions.

STMicroelectronics has documentation for the microprocessor, the hardware abstraction layer (HAL), and "middlewares", but I can't figure how to navigate to them on their site.  Google search comes to the rescue.

http://www.st.com/web/en/resource/technical/document/reference_manual/DM00043574.pdf is the Jan 2015 manual for everything in the STM32F303xB/C/D/E, STM32F303x6/8, STM32F328x8, STM32F358xC, STM32F398xE chips other than the CPU, memory layout, and interrupts, which are documented (for STM32F3 and STM32F4) in May 2014 "PM0214 Programming manual" http://www.st.com/web/en/resource/technical/document/programming_manual/DM00046982.pdf

http://www.st.com/web/en/resource/technical/document/datasheet/DM00058181.pdf is the electrical and timing specifications for STM32F303xB and STM32F303xC.

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00122016.pdf documents the hardware-abstraction-layer Feb 2015 "UM1786 User manual Description of STM32F3xx HAL drivers".  It corresponds to ST32CubeMX version 1.1.1.  Between this manual and the specifications, it should be possible to create firmware without starting from the ST32CubeMX (MS-Windows) program.

http://www.st.com/st-web-ui/static/active/jp/resource/technical/document/user_manual/DM00063382.pdf is Nov 2014 "UM1734 User manual STM32Cube USB device library".  It is not quite up-to-date with ST32CubeMX-1.1.1, referring to some function names (eg. Controllability()) which do not exist in version 1.1.1 or version 1.1.0.  Perhaps the code is in transition.  There are fields like _USBD_HandleTypeDef.dev_connection_status which are never referenced by the code and callbacks like HAL_PCD_ConnectCallback() which are never called.

The USB-CDC function CDC_Transmit_FS() is very useful; it sends a message over the USB to /dev/ttyACM0.  Its use has replaced the on-board LEDs for debugging my real-time program.

The toolchain I use is gcc-arm-embedded.  The version in Ubuntu-12.04 doesn't work with the STM32F3.  https://launchpad.net/gcc-arm-embedded has instructions for installing the current version of gcc-arm-embedded (which does work).

Openocd "Open On-Chip Debugger" is used to program and run gdb on the STM32F3DISCOVERY board.  The version of Openocd in Ubuntu-12.04 does not support the STM32F3DISCOVERY.  I downloaded and compiled from http://openocd.sourceforge.net/getting-openocd/.

https://github.com/mblythe86/stm32f3-discovery-basic-template is a 1.1.0 demonstration project for STM32F3.  It was helpful for creating Makefiles and gcc-arm-embedded linking.

Here is the process I used to port a project generated from the directory structure created by ST32CubeMX-1.1.1:

git clone https://github.com/cjheath/stm32f3-discovery-basic-template.git

In your project directory: Create "Device/ldscripts/" directory and copy "sections_flash.ld", "stm32f3discovery_def.ld", and "stm32f3.ld" from "stm32f3-discovery-basic-template/Device/ldscripts/" into "Device/ldscripts/".

Copy "Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xc.s" into "Device/".

Copy "Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/system_stm32f3xx.c" into "Src/".

Copy Makefile from "stm32f3-discovery-basic-template/Libraries/Makefile" into directory "Drivers/".  In it set SRCS = to a list of all the files in "Drivers/STM32F3xx_HAL_Driver/Src/"

Copy "stm32f3-discovery-basic-template/Makefile" into project directory and modify for your file locations.
  


I am undoubtedly forgetting some of the other changes which were necessary.

The callbacks (and some other functions) have "__weak" definitions.  These are supposedly overridden by non-"__weak" function definitions.  I found that this was sometimes not happening.  Changing the link order did not fix the problem.  Removing the "__weak" definitions fixed it.

Even with the documentation, I was unable to get a differential analog-to-digital converter (ADC) to work correctly.  Instead, I convert the two channels separately and subtract.

Sunday, February 1, 2015

Insulating Both Sides


Because of edge effects, the heat leakage through the insulated back-of-the-plate is difficult to calculate.  It would be better to measure it; but that measurement must discount the heat transfer through the front side of the plate.  The .421 W which I estimate for leakage is less than the downward-facing convection (.525 W) for a plate at 5 K higher than ambient temperature.  Because the test surface of the plate is rough, I don't have confidence in convection calculations based on smooth plate measurements; and assuming what I am trying to measure means that I wouldn't be able to test the assertion that surface roughness has no effect on downward natural convection.

So I created insulation for the (rough) front surface of the plate. Constructed using the same materials and techniques as the backside insulation, its leakage should be roughly the same as the backside.

While cutting the extruded polystyrene foam I noticed that the board crowned in the center.  So I arranged the cut strips so that their centers pressed into the plate edges while the duct tape tensions their ends into corners.  It maintains a snug fit and doesn't need tape to seal it.  Because of the bevel, the backside foam is more complicated to cut; but I may at some point rebuild it using the same technique.

Because the expected downward-facing convection is close in magnitude to the leakage, the fully-insulated measurements should be made both level and at some inclinations (convection increases rapidly as the plate is tilted).

Friday, January 30, 2015

Insulating the Plate



The photo shows the thermal insulation for the aluminum plate's backside (covering the heaters).  The reflective square is 25 mm deep polyisocyanurate foam insulation (Dow TUFF-R) with foil on both sides.  The light green border is 19 mm thick extruded polystyrene foam which is beveled to match the back of the aluminum plate.  The corners and metal-to-foam seams are held together with duct tape.  The sensor cable and heater connections thread between the two types of insulation.  The pieces of insulation were machined using a radial-arm saw and a band-saw.  Knife cuts were not as clean.
While suspension by piano wire will be sufficient for performing forced convection measurements of a downward facing horizontal plate, we lack a way to support the plate with insulation at non-horizontal inclinations, which would allow interesting natural convection measurements.

Wednesday, January 21, 2015

Wiring the Plate

For those new to these postings, in 2011 through 2013 I developed a complete theory for single-phase mixed convection from a rough (or smooth) rectangular plate at uniform temperature:
  http://people.csail.mit.edu/jaffer/SimRoof/Convection

In 2014 I started assembling the equipment necessary to test this
theory:
  http://people.csail.mit.edu/jaffer/SimRoof/Convection/Measurements

Previous blog postings document the progress in building the wind tunnel and measurement and control electronics:
  http://voluntocracy.blogspot.com/2014

John Cox milled the front of the plate to have a precision rough surface with 3 mm average height of roughness.  This particular surface also has 3 mm root-mean-squared height of roughness.



John Cox milled slots in the back of the plate for the heaters (TO-220 resistors).  I drilled 11.mm deep pilot holes and tried to hand tap the holes for #6-32 screws.  On the first hole, the tap started to lean.  Carl Mikkelsen suggested that I remove the drive belt from my drill press, clamp the tap in the chuck, and tap (turning by hand) with the drill press enforcing vertical alignment.  Having only two hands, I used an elastic cord to counteract the spring in the press, as can be seen in the photograph.



 Tapping an 11.mm blind (not through) hole is not reliably acheived by machine, but is quite doable by hand.  I tapped each hole in 3 stages, backing out the tap and blowing out the hole with a (sports) ball inflation pump after each stage.  The resistance to turning the tap when the hole is clogged with chips feels different than the hard stop when the tap has reached the bottom of the hole.  Per Carl's suggestion I used vegetable oil when tapping, which eased cleanup and degreasing.



I wired the heaters (resistors) in series with solid AWG 22 wire (red).  The external drive points (top terminal of the top left and top right heaters) are also connected to conductors of the 6-wire ribbon cable (gray).  This allows measurement of the voltage across the heater chain to be unaffected by voltage drop in the drive wires.  Three gray wires connect to an electronic temperature sensor in the hole right of center.  The gray wire connected to the center screw grounds the plate in order to shield the temperature sensor from electrical noise.

In my initial calculations I neglected the tap taper length, so I shortened each screw by 1.6 mm.  I painted "Silver Alumina" thermal grease on the back of each heater and screwed it and a compression washer into its slot.  I used the TO-220 recommended torque limit on the screws.  But the screws were tight in the holes even without the compression washers, so I turned until the grease squeezed out.

To test the thermal coupling of the heaters to the plate, I jumpered the electronics board to run 1.83 Amps (33 Watts) through the string of heaters.  Applying the "finger test", the warmth of the plastic on the heaters was barely discernable, yet the plate temperature sensor registered a 1.K rise after several minutes.

Once the electronics board is programmed to record measurements of the sensors and heater power, I will encase the plate in polyisocyanurate foam board (insulation) and measure the power required to maintain a 5 K or 10 K temperature between the plate and ambient air.  Half of the ratio of this power to temperature difference is the (leakage) thermal conductivity of the back side of the plate.  The back of the plate will remain insulated while the front will be bare for convection measurements.

Friday, December 19, 2014

Precision Roughness Plate

John Cox has completed the difficult job of milling the aluminum plate to make a precision rough surface!  Its average (also the root-mean-squared) height of roughness is 3 mm.  Cutting the MIC-6 aluminum broke several end mill bits.  Reducing the depth-of-cut to less than 1mm, it took 6 hours on a ShopBot CNC mill.

While MIC-6 turned out to be difficult to machine, its cut surfaces are highly reflective and should hold radiative heat transfer to a minimum.

Next, I will attach the heating elements and temperature sensor to the plate and program the microcomputer to take measurements and store them.  The first measurements will be of natural convection.  After that it will be suspended in the wind tunnel for measuring forced convection.

Saturday, November 8, 2014

Convection Measurement Electronics

Pictured are two electronics boards constructed for measuring convection from an instrumented plate.  The small board on the left will measure pressure, humidity, and temperature of the air at the wind-tunnel intake.

The larger board contains power supplies, heater control and drive, signal conditioning, a three-digit 7-segment display, and a STMicroelectronics ARM STM32F3 Discovery board.  The ARM computer is the green board.  It will control the heater embedded in the plate and collect the sensor data during experiment runs.

The two yellow blocks connected by black cables to the larger board are receptacles for Lenovo laptop 20 Volt power supplies.  The large black object is a heat sink for the heater drive.

The other photo shows the wiring on the back of this board.  Although there are many soldered connections, most of the components are mounted on 16-pin DIP headers seen on the front side.  These are plugged into prototyping sockets with insulation-displacement contacts.  Connections made using 30 AWG wirewrap wire.  This technology was sold by 3M in the 1990s.  I don't think it is sold commercially any more.