Digital Thermometer Example
Example Thermometer Output on Mecrisp-Stellaris Terminal:
t 31,8 C 89,2 F ok.
This example is included so the FURS syntax may be examined and tested on a working project. Note, the source works on my STM32F0 Discovery board as is. I use a optional SWDCOM kernel, which you are unlikely to have but you can easily build one. Swdcom is a massive improvement compared to using a USART just for the Forth debugging advantages alone. The library should have the utilities you'll need to run the thermometer on a new setup.
Just upload the FURS output file to the mcu with your usual method.
The operation is fairly simple, the sensor outputs pulses and a STM32F0 Discovery board counts them and displays the temperature. Technically you can run this on any STM32xx with Forth installed, just change the SVD to suit the MCU and run make.
Schematic:
How does it work ?
This is a simple implementation with only two external parts, a LMT01 ($2.00) two terminal digital temperature sensor, and a 6K8 resistor (R2). They work with a STM32F0 Discovery Board ($10) which runs Mecrisp-Stellaris Forth.
Using a complex internal system of a high accuracy A-D and laser trimmed resistors, the LMT01 outputs 100 millisecond bursts of constant current pulses which are equal to the temperature.
The LMT01 outputs data as two states, a LOW which generates a constant current load of 34uA and a HIGH which generates a constant current load of 125 uA. This circuit uses a 6K8 resistor to generate voltages of 0.231 Vdc or 0.85 Vdc respectively from the constant currents.
Inside the STM32F051 MCU, the Comparator peripheral compares these voltages to a reference of 0.6095 Vdc, producing a logic HIGH if 0.85 Vdc is received, or LOW if 0.231 Vdc. This is done because the voltages across R2 are too low to be read by digital inputs directly.
Comparator 1 outputs logic levels to pin PA6 which is jumpered to pin PA5 and then goes back inside the MCU where the pulses clock Timer-2. The temperature is then computed and displayed in the terminal.
Comparator 2 is identical but outputs logic pulses to pin PA-12 which may be used to drive the anode of a LED so it blinks when the temperature pulses are received, for diagnostic or instrumentation purposes. The LED is optional and does not need to be connected for the thermometer to work properly.
Oddly, I couldn't find a way to connect the Comp-1 output internally to a counter, hence the external pin PA6 -> pin PA5 (option link jumper) as it seems the COMPARATOR is only anticipated to connect to a TIMER, not a COUNTER. Please let me know if you know a way ? I've added all the PDF's for the STM32F051 to make any search easy, and of course I've been thru them all myself, several times. There is one way, using 'Input capture mode' but it's complex and involves interrupts. The pin PA6 -> pin PA5 (option link jumper) is far less complex.
Simplified Program Flowchart:
The source files are here and to see the correct sequence of files, check the 'PROJ_FILES=' line in the Makefile