祝、300投稿達成!!
約5年前に作った郵便ポストセンサーは電池が1年も持たなかったが、その後、独自ファームウェアへ変更したり開閉センサーを外付けのマグネットセンサーにしたり間欠起動のリセット回路を切断したりして改良したことにより電池は1年以上持つようにはなったが生産終了した2525Aで作った物でもあり新たにTWELITE CUEで作り直すことにしてみた。
マグネットセンサーの入力回路にプルアップ抵抗が必要であるがTWELITEのDIOの内部プルアップ抵抗は低すぎて電流だだ漏れ状態になってしまうし、かと言って1M程度の外付け抵抗にすると今度は完全にオンにならないしで、しょうがなく適当なMOS-FETをかませていたが電池電圧が2.5V程度まで低下するとCPUはまだ動作するのにMOS-FETがVGSの関係でオンにならなくなったりしていた。
より低消費電力化のためにはといろいろ調べていたところTOREXの電圧検出器(XC6135C-プッシュプル出力)がプルアップ抵抗なしで超低消費電力なセンサー入力回路としても使えることがわかった。
TOREXのロードスイッチ(XC8111)を使ったことがあるがTOREXの製品って痒いところに手が届くというかよく考えられてる製品だと思う。
さて、これで何年持つかな。電池が無くなるのが早いか私の寿命が尽きるのが早いか、いざ勝負だ!!(笑)
【ケースの片側のみ3Dプリンターで作成】

※TWELITE CUEのリセット回路は切断してある。リセットIC(35nA)と加速度センサー(100nA)をはぎ取るともう少し小省電力化できる。
【ファームウェア (独自開発環境用)】
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
/* main.cpp - Post Sensor for NXP JN516x Series Copyright (c) 2024 Sasapea's Lab. All right reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include "device.h" #define WPAN_ADDRESS 12 #define WAKE_INTERVAL 15 // sec #define TX_TIMEOUT 100 // ms #define PIN_SENSOR Gpio::DIO12 // SW-SET (CUE/2525A) #define PIN_LED Gpio::DIO5 // LED (CUE/2525A) static struct __attribute__((packed)) { uint8_t command[3]; uint8_t seqnum; uint16_t battery; uint16_t count; } packet = { .command = { 'M', 'B', 'X' } }; static int txstatus; void clearNVM(void) { for (size_t i = 0; i < 4; ++i) System::writeNVData(i, 0); } uint32 readNVM(uint8 off = 0) { return System::readNVData(off); } uint32 writeNVM(uint32 data, uint8 off = 0) { System::writeNVData(off, data); return data; } uint16_t readVolt(void) { AdcConfig adc; adc.source(AdcConfig::SRC_ADC_VOLT); Adc::begin(Adc::MODE_SINGLE_SHOT, adc); Adc::start(); while (!Adc::conversion()) yield(); uint16_t rv = Adc::voltage(); Adc::end(); return rv; } void WPanTransmitCallback(uint8 u8Handle, uint8 u8Status) { switch (u8Handle) { case 0x01: txstatus = u8Status; break; } } void send(void) { // // Read VDD Voltage // packet.battery = readVolt(); // // Setup Packet // packet.seqnum = packet.count = writeNVM(readNVM() + 1); // // Send Data // txstatus = -1; WPan::transmit(WPAN_BRIDGE, (uint8_t *)&packet, sizeof(packet), 0x01 | WPAN_OPT_DUPLICATE); for (uint32_t t = System::millis(); (txstatus == -1) && (System::millis() - t < TX_TIMEOUT); ) yield(); } void sleep(uint32 seconds = 0) { // // Sleep + Wake Timer (0.64uA + 0.05uA) // if (seconds) { Gpio::pinMode(PIN_SENSOR, Gpio::INPUT); WakeTimer::startSeconds(WakeTimer::WAKE_0, seconds, empty); System::sleep(System::SLEEP_OSCON_RAMOFF); } // // Deep Sleep + Wake DIO (0.1uA) // else { Gpio::wake(PIN_SENSOR, Gpio::FALLING, empty); System::sleep(System::SLEEP_DEEP); } } void setup(void) { // // Setup GPIO // Gpio::pinMode(PIN_SENSOR, Gpio::INPUT); // Set High Impedance (for low leakage) #ifdef PIN_LED Gpio::pinMode(PIN_LED, Gpio::INPUT); // Set High Impedance (for low leakage) #endif // // Clear NVMData // if (!(System::powerStatus() & (System::POWER_DEEP_SLEEP | System::POWER_SLEEP_WAKEUP))) clearNVM(); } void loop(void) { // // MailBox Opened ? // if (System::powerStatus() & System::POWER_DEEP_SLEEP) { // // Setup WPan // WPan::begin(WPAN_ADDRESS, WPAN_PANID, WPAN_CHANNEL); // // Transmit // send(); // // Sleep and Wake // sleep(WAKE_INTERVAL); } // // Deep Sleep // sleep(); } |



