Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DS1620_improved TextLCD_improved mbed-rtos mbed
tsk_temp.cpp@17:94c385ff2641, 2015-12-18 (annotated)
- Committer:
- dzoni
- Date:
- Fri Dec 18 15:23:21 2015 +0000
- Revision:
- 17:94c385ff2641
- Parent:
- 11:e89f89c0920b
- Child:
- 18:be0130c42925
Bugfixes. Works but freezes after some time. Button task requires rewrite (InterruptIn).
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dzoni | 9:645f0e517017 | 1 | #include "mbed.h" |
| dzoni | 9:645f0e517017 | 2 | #include "rtos.h" |
| dzoni | 9:645f0e517017 | 3 | |
| dzoni | 9:645f0e517017 | 4 | #include "DS1620.h" |
| dzoni | 9:645f0e517017 | 5 | |
| dzoni | 17:94c385ff2641 | 6 | #include "tsk_main.h" |
| dzoni | 9:645f0e517017 | 7 | #include "tsk_temp.h" |
| dzoni | 9:645f0e517017 | 8 | |
| dzoni | 9:645f0e517017 | 9 | |
| dzoni | 17:94c385ff2641 | 10 | struct temp_data_struct temp_data; |
| dzoni | 9:645f0e517017 | 11 | |
| dzoni | 9:645f0e517017 | 12 | static DS1620 ds1620Sensor(PB_4, PB_10, PB_3); |
| dzoni | 9:645f0e517017 | 13 | |
| dzoni | 9:645f0e517017 | 14 | |
| dzoni | 11:e89f89c0920b | 15 | uint32_t initDS1620Temp(void const *args) { |
| dzoni | 9:645f0e517017 | 16 | |
| dzoni | 17:94c385ff2641 | 17 | temp_data.temperature = 10.0f; |
| dzoni | 17:94c385ff2641 | 18 | temp_data.temp_raw = 10; |
| dzoni | 17:94c385ff2641 | 19 | |
| dzoni | 17:94c385ff2641 | 20 | ds1620Sensor.setSerialClockFrequency(freq250k); |
| dzoni | 9:645f0e517017 | 21 | |
| dzoni | 9:645f0e517017 | 22 | if ((ds1620Sensor.readConfig() & 0x03) != 0x03) { |
| dzoni | 9:645f0e517017 | 23 | ds1620Sensor.writeConfig(0x03); |
| dzoni | 9:645f0e517017 | 24 | } |
| dzoni | 11:e89f89c0920b | 25 | |
| dzoni | 11:e89f89c0920b | 26 | if ((ds1620Sensor.readConfig() & 0x03) != 0x03) { |
| dzoni | 11:e89f89c0920b | 27 | return 0; |
| dzoni | 11:e89f89c0920b | 28 | } |
| dzoni | 11:e89f89c0920b | 29 | |
| dzoni | 11:e89f89c0920b | 30 | return 1; |
| dzoni | 9:645f0e517017 | 31 | } |
| dzoni | 9:645f0e517017 | 32 | |
| dzoni | 9:645f0e517017 | 33 | void temp_thread(void const *args) { |
| dzoni | 9:645f0e517017 | 34 | |
| dzoni | 17:94c385ff2641 | 35 | float temp; |
| dzoni | 17:94c385ff2641 | 36 | uint32_t temp_raw; |
| dzoni | 17:94c385ff2641 | 37 | |
| dzoni | 9:645f0e517017 | 38 | while (true) { |
| dzoni | 9:645f0e517017 | 39 | ds1620Sensor.startConversion(); |
| dzoni | 9:645f0e517017 | 40 | |
| dzoni | 9:645f0e517017 | 41 | // Wait for conversion completion (Tconv = 750 ms typ) |
| dzoni | 9:645f0e517017 | 42 | Thread::wait(750); |
| dzoni | 9:645f0e517017 | 43 | while (!(ds1620Sensor.readConfig() & 0x80)) |
| dzoni | 9:645f0e517017 | 44 | Thread::wait(10); |
| dzoni | 9:645f0e517017 | 45 | |
| dzoni | 17:94c385ff2641 | 46 | temp = ds1620Sensor.getHighResolutionTemperature(); |
| dzoni | 17:94c385ff2641 | 47 | temp_raw = ds1620Sensor.readTemperatureRaw(); |
| dzoni | 17:94c385ff2641 | 48 | |
| dzoni | 17:94c385ff2641 | 49 | mutexTemp.lock(); |
| dzoni | 17:94c385ff2641 | 50 | temp_data.temperature = temp; |
| dzoni | 17:94c385ff2641 | 51 | temp_data.temp_raw = temp_raw; |
| dzoni | 17:94c385ff2641 | 52 | mutexTemp.unlock(); |
| dzoni | 17:94c385ff2641 | 53 | |
| dzoni | 17:94c385ff2641 | 54 | Thread::wait(1250); |
| dzoni | 9:645f0e517017 | 55 | } |
| dzoni | 9:645f0e517017 | 56 | } |