Laurence Blaxter
Member
Hello,
I am attempting to build a datalogger using a Teensy4 board. This has to log data every 15 seconds. The data acquisition process only takes a few milliseconds, and the datalogger is intended to be battery powered (3x AA) with an ideal battery life of a few years. I am currently attempting to use powerdown with RTC alarm to lower current consumption to ~150uA in between measurements. The built in NOR flash is used together with LittleFS to log data, and the MTP library is used to download logged data to a PC.
This works... most of the time. However, occasionally the Teensy4 will get stuck in bootloader mode after the shutdown. Once entered, there is no exit from the bootloader, so the datalogger is unusable. This problem usually occurs within a few minutes. I have tried adding an external 1k resistor from the program pin to 3v3, as I wondered if there was an EMI issue, but this did not solve the problem. Adding a 300ms delay in startup might have cured the problem, but I have seen it occur once or twice with the delay (delay seemed to reduce regularity of the issue by a substantial amount).
The shutdown/wakeup code is included below
note that a 300ms delay is not an acceptable solution as it increases power consumption excessively.
I am attempting to build a datalogger using a Teensy4 board. This has to log data every 15 seconds. The data acquisition process only takes a few milliseconds, and the datalogger is intended to be battery powered (3x AA) with an ideal battery life of a few years. I am currently attempting to use powerdown with RTC alarm to lower current consumption to ~150uA in between measurements. The built in NOR flash is used together with LittleFS to log data, and the MTP library is used to download logged data to a PC.
This works... most of the time. However, occasionally the Teensy4 will get stuck in bootloader mode after the shutdown. Once entered, there is no exit from the bootloader, so the datalogger is unusable. This problem usually occurs within a few minutes. I have tried adding an external 1k resistor from the program pin to 3v3, as I wondered if there was an EMI issue, but this did not solve the problem. Adding a 300ms delay in startup might have cured the problem, but I have seen it occur once or twice with the delay (delay seemed to reduce regularity of the issue by a substantial amount).
The shutdown/wakeup code is included below
Code:
void rtc_setAlarm(uint32_t alarmSeconds, uint32_t prio = 13) {
uint32_t tmp = SNVS_LPCR; //save control register
/* disable SRTC alarm interrupt */
rtc_stopAlarm();
SNVS_LPTAR = alarmSeconds;
while (SNVS_LPTAR != alarmSeconds);
//attachInterruptVector(IRQ_SNVS_IRQ, rtc_isr);
//NVIC_SET_PRIORITY(IRQ_SNVS_IRQ, prio * 16); // 8 is normal priority
//NVIC_DISABLE_IRQ(IRQ_SNVS_IRQ);
//NVIC_ENABLE_IRQ(IRQ_SNVS_IRQ);
SNVS_LPCR = tmp | SNVS_LPCR_LPTA_EN_MASK; // restore control register and set alarm
while (!(SNVS_LPCR & SNVS_LPCR_LPTA_EN_MASK));
}
uint32_t rtc_getAlarm() {
return SNVS_LPTAR;
}
void doShutdown(void) {
SNVS_LPCR |= (1 << 6) ; // turn off power
}
void setWakeupCallandSleep(uint32_t nsec) {
uint32_t to = now();
rtc_setAlarm(to + nsec, 4);
doShutdown();
while (1) asm("wfi");
}