Transistor Gijutsu, October 2014, Special Features Chapter 8,Software of the thermistor thermometer of 0.001 ° resolution, トランジスタ技術2014年10月号 特集第8章のソフトウェア 0.001℃分解能で気配もキャッチ「超敏感肌温度計」

Dependencies:   USBDevice mbed

Information

tg_201410s8_AD7714 トランジスタ技術 2014年 10月号 第8章のソフトウェア

Program for Section 8 in October. 2014 issue of the Transistor Gijutsu
(Japanese electronics magazine)

概要

このプログラムは、サーミスタの抵抗値変化をAD7714(24bitADC)で測定し、抵抗値を温度値に変換することで、0.001℃程度の分解能で温度変化を測定します。

ファイル

このソフトウエアは、次のファイルから構成されています。

  • AD7714.cpp - AD7714の内部レジスタを設定
  • Thermistor.cpp - サーミスタの抵抗値から温度値に変換
  • ExpAvr.cpp - 指数平均によるソフトウエアLPF
  • main.cpp - main()関数

詳細については、10月号の記事および上記ファイル中のコメントを参照してください。

Committer:
Dance
Date:
Fri Aug 29 08:38:36 2014 +0000
Revision:
0:de885a6da962
Transistor Gijutsu, October 2014, Special Features Chapter 8; ????????2014?10??????8????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Dance 0:de885a6da962 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Dance 0:de885a6da962 2 *
Dance 0:de885a6da962 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Dance 0:de885a6da962 4 * and associated documentation files (the "Software"), to deal in the Software without
Dance 0:de885a6da962 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Dance 0:de885a6da962 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Dance 0:de885a6da962 7 * Software is furnished to do so, subject to the following conditions:
Dance 0:de885a6da962 8 *
Dance 0:de885a6da962 9 * The above copyright notice and this permission notice shall be included in all copies or
Dance 0:de885a6da962 10 * substantial portions of the Software.
Dance 0:de885a6da962 11 *
Dance 0:de885a6da962 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Dance 0:de885a6da962 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Dance 0:de885a6da962 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Dance 0:de885a6da962 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Dance 0:de885a6da962 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Dance 0:de885a6da962 17 */
Dance 0:de885a6da962 18
Dance 0:de885a6da962 19 #include "stdint.h"
Dance 0:de885a6da962 20 #include "USBMouse.h"
Dance 0:de885a6da962 21
Dance 0:de885a6da962 22 bool USBMouse::update(int16_t x, int16_t y, uint8_t button, int8_t z) {
Dance 0:de885a6da962 23 switch (mouse_type) {
Dance 0:de885a6da962 24 case REL_MOUSE:
Dance 0:de885a6da962 25 while (x > 127) {
Dance 0:de885a6da962 26 if (!mouseSend(127, 0, button, z)) return false;
Dance 0:de885a6da962 27 x = x - 127;
Dance 0:de885a6da962 28 }
Dance 0:de885a6da962 29 while (x < -128) {
Dance 0:de885a6da962 30 if (!mouseSend(-128, 0, button, z)) return false;
Dance 0:de885a6da962 31 x = x + 128;
Dance 0:de885a6da962 32 }
Dance 0:de885a6da962 33 while (y > 127) {
Dance 0:de885a6da962 34 if (!mouseSend(0, 127, button, z)) return false;
Dance 0:de885a6da962 35 y = y - 127;
Dance 0:de885a6da962 36 }
Dance 0:de885a6da962 37 while (y < -128) {
Dance 0:de885a6da962 38 if (!mouseSend(0, -128, button, z)) return false;
Dance 0:de885a6da962 39 y = y + 128;
Dance 0:de885a6da962 40 }
Dance 0:de885a6da962 41 return mouseSend(x, y, button, z);
Dance 0:de885a6da962 42 case ABS_MOUSE:
Dance 0:de885a6da962 43 HID_REPORT report;
Dance 0:de885a6da962 44
Dance 0:de885a6da962 45 report.data[0] = x & 0xff;
Dance 0:de885a6da962 46 report.data[1] = (x >> 8) & 0xff;
Dance 0:de885a6da962 47 report.data[2] = y & 0xff;
Dance 0:de885a6da962 48 report.data[3] = (y >> 8) & 0xff;
Dance 0:de885a6da962 49 report.data[4] = -z;
Dance 0:de885a6da962 50 report.data[5] = button & 0x07;
Dance 0:de885a6da962 51
Dance 0:de885a6da962 52 report.length = 6;
Dance 0:de885a6da962 53
Dance 0:de885a6da962 54 return send(&report);
Dance 0:de885a6da962 55 default:
Dance 0:de885a6da962 56 return false;
Dance 0:de885a6da962 57 }
Dance 0:de885a6da962 58 }
Dance 0:de885a6da962 59
Dance 0:de885a6da962 60 bool USBMouse::mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z) {
Dance 0:de885a6da962 61 HID_REPORT report;
Dance 0:de885a6da962 62 report.data[0] = buttons & 0x07;
Dance 0:de885a6da962 63 report.data[1] = x;
Dance 0:de885a6da962 64 report.data[2] = y;
Dance 0:de885a6da962 65 report.data[3] = -z; // >0 to scroll down, <0 to scroll up
Dance 0:de885a6da962 66
Dance 0:de885a6da962 67 report.length = 4;
Dance 0:de885a6da962 68
Dance 0:de885a6da962 69 return send(&report);
Dance 0:de885a6da962 70 }
Dance 0:de885a6da962 71
Dance 0:de885a6da962 72 bool USBMouse::move(int16_t x, int16_t y) {
Dance 0:de885a6da962 73 return update(x, y, button, 0);
Dance 0:de885a6da962 74 }
Dance 0:de885a6da962 75
Dance 0:de885a6da962 76 bool USBMouse::scroll(int8_t z) {
Dance 0:de885a6da962 77 return update(0, 0, button, z);
Dance 0:de885a6da962 78 }
Dance 0:de885a6da962 79
Dance 0:de885a6da962 80
Dance 0:de885a6da962 81 bool USBMouse::doubleClick() {
Dance 0:de885a6da962 82 if (!click(MOUSE_LEFT))
Dance 0:de885a6da962 83 return false;
Dance 0:de885a6da962 84 wait(0.1);
Dance 0:de885a6da962 85 return click(MOUSE_LEFT);
Dance 0:de885a6da962 86 }
Dance 0:de885a6da962 87
Dance 0:de885a6da962 88 bool USBMouse::click(uint8_t button) {
Dance 0:de885a6da962 89 if (!update(0, 0, button, 0))
Dance 0:de885a6da962 90 return false;
Dance 0:de885a6da962 91 wait(0.01);
Dance 0:de885a6da962 92 return update(0, 0, 0, 0);
Dance 0:de885a6da962 93 }
Dance 0:de885a6da962 94
Dance 0:de885a6da962 95 bool USBMouse::press(uint8_t button_) {
Dance 0:de885a6da962 96 button = button_ & 0x07;
Dance 0:de885a6da962 97 return update(0, 0, button, 0);
Dance 0:de885a6da962 98 }
Dance 0:de885a6da962 99
Dance 0:de885a6da962 100 bool USBMouse::release(uint8_t button_) {
Dance 0:de885a6da962 101 button = (button & (~button_)) & 0x07;
Dance 0:de885a6da962 102 return update(0, 0, button, 0);
Dance 0:de885a6da962 103 }
Dance 0:de885a6da962 104
Dance 0:de885a6da962 105
Dance 0:de885a6da962 106 uint8_t * USBMouse::reportDesc() {
Dance 0:de885a6da962 107
Dance 0:de885a6da962 108 if (mouse_type == REL_MOUSE) {
Dance 0:de885a6da962 109 static uint8_t reportDescriptor[] = {
Dance 0:de885a6da962 110 USAGE_PAGE(1), 0x01, // Genric Desktop
Dance 0:de885a6da962 111 USAGE(1), 0x02, // Mouse
Dance 0:de885a6da962 112 COLLECTION(1), 0x01, // Application
Dance 0:de885a6da962 113 USAGE(1), 0x01, // Pointer
Dance 0:de885a6da962 114 COLLECTION(1), 0x00, // Physical
Dance 0:de885a6da962 115
Dance 0:de885a6da962 116 REPORT_COUNT(1), 0x03,
Dance 0:de885a6da962 117 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 118 USAGE_PAGE(1), 0x09, // Buttons
Dance 0:de885a6da962 119 USAGE_MINIMUM(1), 0x1,
Dance 0:de885a6da962 120 USAGE_MAXIMUM(1), 0x3,
Dance 0:de885a6da962 121 LOGICAL_MINIMUM(1), 0x00,
Dance 0:de885a6da962 122 LOGICAL_MAXIMUM(1), 0x01,
Dance 0:de885a6da962 123 INPUT(1), 0x02,
Dance 0:de885a6da962 124 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 125 REPORT_SIZE(1), 0x05,
Dance 0:de885a6da962 126 INPUT(1), 0x01,
Dance 0:de885a6da962 127
Dance 0:de885a6da962 128 REPORT_COUNT(1), 0x03,
Dance 0:de885a6da962 129 REPORT_SIZE(1), 0x08,
Dance 0:de885a6da962 130 USAGE_PAGE(1), 0x01,
Dance 0:de885a6da962 131 USAGE(1), 0x30, // X
Dance 0:de885a6da962 132 USAGE(1), 0x31, // Y
Dance 0:de885a6da962 133 USAGE(1), 0x38, // scroll
Dance 0:de885a6da962 134 LOGICAL_MINIMUM(1), 0x81,
Dance 0:de885a6da962 135 LOGICAL_MAXIMUM(1), 0x7f,
Dance 0:de885a6da962 136 INPUT(1), 0x06, // Relative data
Dance 0:de885a6da962 137
Dance 0:de885a6da962 138 END_COLLECTION(0),
Dance 0:de885a6da962 139 END_COLLECTION(0),
Dance 0:de885a6da962 140 };
Dance 0:de885a6da962 141 reportLength = sizeof(reportDescriptor);
Dance 0:de885a6da962 142 return reportDescriptor;
Dance 0:de885a6da962 143 } else if (mouse_type == ABS_MOUSE) {
Dance 0:de885a6da962 144 static uint8_t reportDescriptor[] = {
Dance 0:de885a6da962 145
Dance 0:de885a6da962 146 USAGE_PAGE(1), 0x01, // Generic Desktop
Dance 0:de885a6da962 147 USAGE(1), 0x02, // Mouse
Dance 0:de885a6da962 148 COLLECTION(1), 0x01, // Application
Dance 0:de885a6da962 149 USAGE(1), 0x01, // Pointer
Dance 0:de885a6da962 150 COLLECTION(1), 0x00, // Physical
Dance 0:de885a6da962 151
Dance 0:de885a6da962 152 USAGE_PAGE(1), 0x01, // Generic Desktop
Dance 0:de885a6da962 153 USAGE(1), 0x30, // X
Dance 0:de885a6da962 154 USAGE(1), 0x31, // Y
Dance 0:de885a6da962 155 LOGICAL_MINIMUM(1), 0x00, // 0
Dance 0:de885a6da962 156 LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767
Dance 0:de885a6da962 157 REPORT_SIZE(1), 0x10,
Dance 0:de885a6da962 158 REPORT_COUNT(1), 0x02,
Dance 0:de885a6da962 159 INPUT(1), 0x02, // Data, Variable, Absolute
Dance 0:de885a6da962 160
Dance 0:de885a6da962 161 USAGE_PAGE(1), 0x01, // Generic Desktop
Dance 0:de885a6da962 162 USAGE(1), 0x38, // scroll
Dance 0:de885a6da962 163 LOGICAL_MINIMUM(1), 0x81, // -127
Dance 0:de885a6da962 164 LOGICAL_MAXIMUM(1), 0x7f, // 127
Dance 0:de885a6da962 165 REPORT_SIZE(1), 0x08,
Dance 0:de885a6da962 166 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 167 INPUT(1), 0x06, // Data, Variable, Relative
Dance 0:de885a6da962 168
Dance 0:de885a6da962 169 USAGE_PAGE(1), 0x09, // Buttons
Dance 0:de885a6da962 170 USAGE_MINIMUM(1), 0x01,
Dance 0:de885a6da962 171 USAGE_MAXIMUM(1), 0x03,
Dance 0:de885a6da962 172 LOGICAL_MINIMUM(1), 0x00, // 0
Dance 0:de885a6da962 173 LOGICAL_MAXIMUM(1), 0x01, // 1
Dance 0:de885a6da962 174 REPORT_COUNT(1), 0x03,
Dance 0:de885a6da962 175 REPORT_SIZE(1), 0x01,
Dance 0:de885a6da962 176 INPUT(1), 0x02, // Data, Variable, Absolute
Dance 0:de885a6da962 177 REPORT_COUNT(1), 0x01,
Dance 0:de885a6da962 178 REPORT_SIZE(1), 0x05,
Dance 0:de885a6da962 179 INPUT(1), 0x01, // Constant
Dance 0:de885a6da962 180
Dance 0:de885a6da962 181 END_COLLECTION(0),
Dance 0:de885a6da962 182 END_COLLECTION(0)
Dance 0:de885a6da962 183 };
Dance 0:de885a6da962 184 reportLength = sizeof(reportDescriptor);
Dance 0:de885a6da962 185 return reportDescriptor;
Dance 0:de885a6da962 186 }
Dance 0:de885a6da962 187 return NULL;
Dance 0:de885a6da962 188 }
Dance 0:de885a6da962 189
Dance 0:de885a6da962 190 #define DEFAULT_CONFIGURATION (1)
Dance 0:de885a6da962 191 #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
Dance 0:de885a6da962 192 + (1 * INTERFACE_DESCRIPTOR_LENGTH) \
Dance 0:de885a6da962 193 + (1 * HID_DESCRIPTOR_LENGTH) \
Dance 0:de885a6da962 194 + (2 * ENDPOINT_DESCRIPTOR_LENGTH))
Dance 0:de885a6da962 195
Dance 0:de885a6da962 196 uint8_t * USBMouse::configurationDesc() {
Dance 0:de885a6da962 197 static uint8_t configurationDescriptor[] = {
Dance 0:de885a6da962 198 CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
Dance 0:de885a6da962 199 CONFIGURATION_DESCRIPTOR, // bDescriptorType
Dance 0:de885a6da962 200 LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
Dance 0:de885a6da962 201 MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
Dance 0:de885a6da962 202 0x01, // bNumInterfaces
Dance 0:de885a6da962 203 DEFAULT_CONFIGURATION, // bConfigurationValue
Dance 0:de885a6da962 204 0x00, // iConfiguration
Dance 0:de885a6da962 205 C_RESERVED | C_SELF_POWERED, // bmAttributes
Dance 0:de885a6da962 206 C_POWER(0), // bMaxPowerHello World from Mbed
Dance 0:de885a6da962 207
Dance 0:de885a6da962 208 INTERFACE_DESCRIPTOR_LENGTH, // bLength
Dance 0:de885a6da962 209 INTERFACE_DESCRIPTOR, // bDescriptorType
Dance 0:de885a6da962 210 0x00, // bInterfaceNumber
Dance 0:de885a6da962 211 0x00, // bAlternateSetting
Dance 0:de885a6da962 212 0x02, // bNumEndpoints
Dance 0:de885a6da962 213 HID_CLASS, // bInterfaceClass
Dance 0:de885a6da962 214 1, // bInterfaceSubClass
Dance 0:de885a6da962 215 2, // bInterfaceProtocol (mouse)
Dance 0:de885a6da962 216 0x00, // iInterface
Dance 0:de885a6da962 217
Dance 0:de885a6da962 218 HID_DESCRIPTOR_LENGTH, // bLength
Dance 0:de885a6da962 219 HID_DESCRIPTOR, // bDescriptorType
Dance 0:de885a6da962 220 LSB(HID_VERSION_1_11), // bcdHID (LSB)
Dance 0:de885a6da962 221 MSB(HID_VERSION_1_11), // bcdHID (MSB)
Dance 0:de885a6da962 222 0x00, // bCountryCode
Dance 0:de885a6da962 223 0x01, // bNumDescriptors
Dance 0:de885a6da962 224 REPORT_DESCRIPTOR, // bDescriptorType
Dance 0:de885a6da962 225 (uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
Dance 0:de885a6da962 226 (uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
Dance 0:de885a6da962 227
Dance 0:de885a6da962 228 ENDPOINT_DESCRIPTOR_LENGTH, // bLength
Dance 0:de885a6da962 229 ENDPOINT_DESCRIPTOR, // bDescriptorType
Dance 0:de885a6da962 230 PHY_TO_DESC(EPINT_IN), // bEndpointAddress
Dance 0:de885a6da962 231 E_INTERRUPT, // bmAttributes
Dance 0:de885a6da962 232 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
Dance 0:de885a6da962 233 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
Dance 0:de885a6da962 234 1, // bInterval (milliseconds)
Dance 0:de885a6da962 235
Dance 0:de885a6da962 236 ENDPOINT_DESCRIPTOR_LENGTH, // bLength
Dance 0:de885a6da962 237 ENDPOINT_DESCRIPTOR, // bDescriptorType
Dance 0:de885a6da962 238 PHY_TO_DESC(EPINT_OUT), // bEndpointAddress
Dance 0:de885a6da962 239 E_INTERRUPT, // bmAttributes
Dance 0:de885a6da962 240 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
Dance 0:de885a6da962 241 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
Dance 0:de885a6da962 242 1, // bInterval (milliseconds)
Dance 0:de885a6da962 243 };
Dance 0:de885a6da962 244 return configurationDescriptor;
Dance 0:de885a6da962 245 }