Bonjour à tous,
j'essaye d’améliorer l'autonomie d'un Attiny84.
Pour cela j'ai mon fichier principal .ino et un fichier .h contenant les initialisations nécessaire
J'ai testé plusieurs méthode de watchdog mais aucune ne fonctionne.
Auriez vous une idée ?
Fichier init.h
#include <avr/io.h>
#include <avr/sleep.h>;
#include <avr/wdt.h>
#define adc_enable() (ADCSRA |= (1<<ADEN)) // Turns on ADC in order to read analog values
#define adc_disable() (ADCSRA &= ~_BV(ADEN)) // disable Analog convertor
#define ac_disable() (ACSR |= _BV(ACD)) // disable Analog comparator
uint8_t wdt_count = 0;
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void watchdog_start_interrupt(uint8_t wd_prescaler) {
if(wd_prescaler > 9) wd_prescaler = 9;
byte _prescaler = wd_prescaler & 0x7;
if (wd_prescaler > 7 ) _prescaler |= _BV(WDP3);
MCUSR &= ~(1 << WDRF);
WDTCSR = _prescaler;
WDTCSR |= _BV(WDIE) | _BV(WDCE) | _BV(WDE);
}
// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect) {
wdt_count++;
}
/* Turn off WDT */
void watchdog_stop() {
WDTCSR |= _BV(WDCE) | _BV(WDE);
WDTCSR = 0x00;
}
void watchdogReset()
{
wdt_count = 0;
}
Fichier Ino
#include <RF24.h>
#include <RF24Network.h>
#include <avr/power.h>
#include <init_variable_attiny.h>
const byte this_node = 01;
const byte other_node = 0;
#include <getSingleTemp.h>
void setup() {
radio.begin();
radio.setDataRate(RF24_250KBPS);
network.begin(1, this_node);
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Power down everything, will only wake up from WDT
sleep_enable(); // Enable sleep
}
void loop() {
SendDataRF24(1, 999, 0,other_node,0); // Fonction permettant d'envoyer des données via NRF24 ( Fonctionne sans probleme)
// radio.powerDown();
// Loops the 8 second internal to extend the sleep state => Work Time ( 9 )
// 18 = 2 minutes
// 45 = 5 minutes
// 90 = 10 mintues
// 135 = 15 minutes
// 270 = 30 minutes
SendDataRF24(1, -1, 0,other_node,0);
while (wdt_count < 18)
{
watchdog_start_interrupt(9);
ADCSRA &= ~(1 << ADEN); // Turns off the ADC sleep_mode();
}
// N'arrive j'amais ici
// radio.powerUp();
SendDataRF24(1, 555, 0,other_node,0);
watchdogReset();
}
De plus est-ce que la fonction millis() est impactée par le sleep ?
Car dans un autre bloc de code j'effectue une comparaison avec le millis()
// difference = millis()+62050 (environ 1 minute)
millis()>= difference
Merci pour votre aide