Some time ago I designed a simple two output USB switch with integrated watchdog. Recently we have stumbled upon some thermal issues in one of our repeaters – the software consumed 100% CPU all the time making the whole chassis red hot and occasionally dropping data frames. We plan to mount a temperature activated fan inside the case and get also some telemetry. The old design will fulfill those needs.
Hardware
The PCB was designed with data acquisition in mind right from the start so it required no changes beside changing some components.
Original schematic:
Components omitted: T2, D1, LED3, R9, R10
Components changed:
- IC1 – ATtiny45 (has more flash and is also cheaper than ATtiny25)
- T1 – IRLZ44N (low threshold voltage)
- C9 – 100n
- R6 – 470
- R12 – 47k
- R13 – 33k
The controller now supports the following features:
- one high-power open-drain output channel
- one analog voltage input channel (up to about 15VDC)
- temperature measurement (the sensor is integrated on the MCU die)
- bang-bang control of the output in heater/cooler modes
Software
From the PC side it enumerates as a HID class device, no drivers are required. A simple command line utility is used to communicate with the device (it compiles easily on Linux, Windows and Mac).
Reading data:
$ ./hidtool read
0x01 0x3f 0x00 0x00 0x01 0x01 0x00 0x00 0x01 0x33 0x01 0x37 0x00 0x00 0x00 0x00
Returned bytes mean:
- Temperature reading MSB (ADC code)
- Temperature reading LSB (ADC code)
- Voltage reading MSB (ADC code)
- Voltage reading LSB (ADC code)
- Output mode
- 0x00 – always off
- 0x01 – bang-bang control (on above high setpoint, off below low setpoint – like fan control)
- 0x02 – always on
- 0x03 – bang-bang control (on below low setpoint, off above high setpoint – like heater control)
- Output status (0x00 off, 0x01 on)
- Unused
- Unused
- Low temperature setpoint MSB (ADC code)
- Low temperature setpoint LSB (ADC code)
- High temperature setpoint MSB (ADC code)
- High temperature setpoint LSB (ADC code)
- Unused
- Unused
Configuration of the device looks similar:
$ ./hidtool write 0x57 0x01 0x1 0x33 0x01 0x37
- 0x57 – magic number (letter 'W’)
- Output mode (same as above)
- Low temperature setpoint MSB (ADC code)
- Low temperature setpoint LSB (ADC code)
- High temperature setpoint MSB (ADC code)
- High temperature setpoint LSB (ADC code)
Calibration
So far the MCU’s supplies measured analog values as a raw ADC code. To find a way of converting them to values of known units a calibration step is required. There are two channels that need to be calibrated: voltage input and temperature sensor.
Voltage calibration
Simply connect a good known multimeter as a reference and a variable power supply to the device, then take some measurements and write down the results. That is what I obtained:
Hex values have to be converted to decimal and plotted along with voltage read from the multimeter. All samples should (ideally) follow a straight line. Double click on the plot, choose menu insert -> trend lines and make the box „show equation” checked. I decided to keep the firmware simple so calculations have to be performed on the host side. That equation can be then directly used in software to calculate voltage from the raw ADC code (substitute the code for x).
Temperature calibration
Temperature calibration is a little bit more tricky, firstly a reference thermometer is needed and secondly a way to sweep the temperature along the required measurement range, like a climate controlled chamber. Sort of…
I had a DS18B20 temperature sensor (and USB interface) at hand. I fixed the sensor on the MCU with scotch tape to keep them both close together. To sweep the temperature above room temperature I placed them both near the exhaust of my laptop and to go below I used a freezer spray (like one used to find cold solder joints). A bash script took measurements from both sensors every three seconds. That is what they look like after some spreadsheet trickery:
Great! They are correlated (somehow). Let’s plot them against each other:
The correlation looks quite good, although some points are for sure odd. Also the sub-zero measurements are scattered too much. I deicded to cherrypick only the values above zero (I think that the temperature inside the chassis will never fall below 10 degrees) and following the baseline.
After cherrypicking I obtained the final equation. The trend line favors measurements taken above about 20 degrees because there were simply more of them. It is of little concern because the case temperature will be between about 25-40 degrees (wild guess). The closer the measured temperature will be to the calibration temperature, the more precise the results.
Chartplotting and telemetry software is still to be written.
Firmware
Firmware, software, schematic, calibration spreadsheet, scripts – release 1.0
Tips:
BTC 15RXzysGYaV6sZnnztBFB9zupjNGDZysPj
LTC Ld1zhCLjvHmvmMFp9NKcTJU7AjAtSBmgaU
Artur SP2AGX
0 komentarzy