Thank you so much, for your kindness!!
I'm bit late to answer, since I lost all hopes to get answered.
I and my friends, we attempt to measure RPM and then save the data periodically on SD card. The system should have a lifespan for 6 months, at least. With the hope that a battery of 10 Ah will suffice.
An attempt was to inject 32KHz into the timer1 (T1/PD5) and gate by ICP (ICP/PB0). The pulses on ICP may vary from 0.16 to 5 Hertz.
I thought that doing so I'll have the count frozen to the number counted between two pulses, theoretically the period in 1/32768 seconds counts. So during that the MCU stay asleep.
This is one test. Part of this sketch I found on the web.
#include <RTClib.h>
#include "LowPower.h"
#include <SPI.h>
#include <SD.h>
#define filename datalog.txt ;
#define chipSelect 4
#define CADENCE 30
RTC_DS3231 RTC;
float RPM = 1;
volatile uint16_t T1capture;
volatile uint16_t lastT1capture;
volatile uint32_t period;
uint8_t numperiod;
char buffer[10];
bool captured;
ISR (TIMER1_CAPT_vect){
T1capture = ICR1 ;
captured = 1;
}
void setup() {
Serial.begin(57600);
while (!Serial) {;}
Serial.println(F("Sistema Pronto"));
RTC.begin();
pinMode(5, INPUT_PULLUP);
if (RTC.lostPower()) {
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
else {
RTC.writeSqwPinMode(DS3231_SquareWave4kHz);
DateTime now = RTC.now();
}
noInterrupts();
TCNT1 = 0;
TCCR1B = B01000111;
TIMSK1 = (1<<ICIE1);
TCCR1A = 0;
interrupts();
}
void loop () {
if (captured) {
captured = 0;
period += (T1capture - lastT1capture);
lastT1capture = T1capture;
numperiod++;
}
DateTime now = RTC.now();
if (!(now.second() % CADENCE)) {
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
delay(10);
RPM = (float)4096 * 60 * numperiod / period;
sprintf(buffer, "[%02d/%02d-", now.day(), now.month());
Serial.print(buffer);
sprintf(buffer, "%02d:%02d:%02d] ", now.hour(),
now.minute(), now.second());
Serial.print(buffer);
Serial.println(RPM);
pinMode(2, INPUT);
LowPower.idle(SLEEP_FOREVER, ADC_OFF, TIMER2_OFF, TIMER1_ON,
TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_ON);
}
}
I'd like to get the pulses number without calculations. ICR1 sholud hold last count and I won't need to calculate any further.
Then it seems that is not going down to power saving. Well I should find the informations to program the MCU for stand-alone.
Our achievement is to go for 1 mAh consumption. Perhaps, the system must be a stand-alone with SD powered down as long as possible and perhaps the RTC also should go power-down with the lowest consumption.