Distance / Time measure and clock tuning
I have built a nice little distance sensor using a Sensebender micro. The power footprint is very low: batteries would last several months.
I'm trying to push it further. To do so, I'm wondering if I could play with the clock of the Atmega.
I have understood that delay(), millis(), .. primitives don't behave appropriately after using clock_prescale_set() usage.
Here is my question: is there a standard library (like NewPing) that handles these changes appropriately ?
Its not like "defaultish"-library but currently I am using this piece:
It features some code to get the "real" millis but all librarys that depend on arduino "delay" and "millis" function might do wrong delays/timings.
All my nodes run at 1mhz to power them up with even 2xAA batteries @2,4volt or less. If some nodes have a more stable supply I use the library this way:
uint8_t old_ps = getClockPrescaler(); setClockPrescaler(0x00); oled.setCursor(0,1); oled << mymin << "," << sum << "," << mymax << "," << (diff < 1024 ? diff : 1024) << "," << (acc < 1024 ? acc : 1024) << " " << endl; oled << "sf: " << spike_forgiveness << " " << endl; oled.setCursor(64,3); oled.print(readVcc()); oled.print("mV "); oled.setCursor(0,3); oled.print(RF24_readByteRegister(OBSERVE_TX),HEX); setClockPrescaler(old_ps);
Regarding the power-footprint. Are you using the sleep-function of mysn?
Well, I've adapted the NewPing library in order to handle different clocks (using inline definition of millis(), micros(), ...) and....it works perfectly !
Now I have a low power, low clock ultrasonic sensor that will last for years on a set of 2 AA batteries.
If I'm not too busy, I might packed it up and publish it
At least in theory .. how much power does the ultrasonic-part consume and/or do you switch it off between measurements?
I will publish my voltage curve once I get enough history.
And yes, I do shut down the sensor (and the booster, and the logic level adapter) between measures