Despertar un ATmega328P del sueño profundo cuando el voltaje de la batería cae por debajo de un nivel establecido
Traducido del English por IA ·
Fundador de una pequeña startup de logística, muy nuevo en hardware, así que disculpen si esto es obvio.Colocamos baterías de plomo-ácido de 12 V cargadas con energía solar en sensores de puertas de remolques. Quiero que un Arduino Pro Mini (ATmega328P, 3,3 V, 8 MHz, LED de alimentación retirado) duerma en power-down y que solo despierte cuando la batería caiga por debajo de unos 11,8 V, para luego enviar un mensaje a Hermetry y que alguien cambie la batería. El divisor es de 100k/33k, así que 11,8 V equivalen a unos 2,93 V en el pin.Leí sobre el comparador analógico (AIN0/AIN1) y su interrupción, y conecté el divisor a AIN1 con una referencia de 2,5 V en AIN0. Con la interrupción del comparador activada, el modo SLEEP_MODE_PWR_DOWN nunca despierta. En SLEEP_MODE_IDLE sí despierta bien, pero mi medidor muestra unos 1,3 mA, lo que anula el sentido del proyecto.¿Hay algún truco de registro que me falte para que el comparador despierte el microcontrolador desde power-down? El código es básicamente:
ACSR = (1 << ACIE) | (1 << ACIS1); // interrupt on falling edge
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable(); sei(); sleep_cpu();
Founder of a tiny logistics startup, very new to hardware, so apologies if this is obvious.
We put solar-charged 12 V lead-acid batteries on trailer gate sensors. I want an Arduino Pro Mini (ATmega328P, 3.3 V, 8 MHz, power LED removed) to sleep in power-down and wake only when the battery falls below about 11.8 V, then send one message to Hermetry so someone swaps the battery. Divider is 100k/33k so 11.8 V is about 2.93 V at the pin.
I read about the analog comparator (AIN0/AIN1) and its interrupt, and wired the divider to AIN1 with a 2.5 V reference on AIN0. With the comparator interrupt set, sleep in SLEEP_MODE_PWR_DOWN never wakes. In SLEEP_MODE_IDLE it wakes fine but my meter shows about 1.3 mA, which kills the point.
Is there a register trick I’m missing to make the comparator wake it from power-down? Code is basically:
ACSR = (1 << ACIE) | (1 << ACIS1); // interrupt on falling edge
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable(); sei(); sleep_cpu();
Traducido del English por IA ·
¿No podrías despertar con el watchdog cada 8 s, leer el ADC y volver a dormir? Eso es lo que hacen nuestros contadores de puertas.
Couldn’t you wake on the watchdog every 8 s, read the ADC, and go back to sleep? That’s what our door counters do.
Traducido del English por IA ·
Lo probé, funciona, con un promedio de unos 20 µA. Esperaba menos, y se siente torpe.
Tried that, it works, average around 20 µA. I was hoping for less, and it feels clumsy.
Traducido del English por IA ·
¿Por qué es tan importante la referencia? ¿No podría usar la bandgap interna de 1.1 V?
Why does the reference matter so much? Couldn’t it use the internal 1.1 V bandgap?
Traducido del English por IA ·
No hay ningún truco de registros, me temo. Que yo recuerde, en la tabla de modos de sueño de la hoja de datos del 328P, el comparador analógico solo es fuente de despertar en idle (y en reducción de ruido del ADC), no en power-down. En power-down solo despiertan las interrupciones externas, el pin change, la coincidencia de dirección TWI y el watchdog. Tu corriente en idle se debe a que los relojes siguen funcionando.Saca el comparador fuera. Un comparador de nanopotencia con salida push-pull conectado a INT0 (D2) permite que el 328P permanezca en power-down con unos pocos µA. El TLV3691 consume unos 75 nA, y la referencia puede ser una referencia shunt de 2,5 V de micropotencia. Añade histéresis con una resistencia desde la salida a la entrada +, de unos cientos de mV en el lado de la batería; si no, una batería que oscile en torno a 11,8 V te despertará cientos de veces por noche al cambiar la carga.
attachInterrupt(digitalPinToInterrupt(2), wake, FALLING);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable(); sleep_cpu(); // wakes on INT0 only
// on wake: read ADC once for the real value, send it, sleep again
Aoife: puedes usar la referencia bandgap internamente, pero el comparador en sí sigue sin poder despertar el power-down, así que aquí no ayuda.Por el lado de Hermetry, seguiría enviando un heartbeat una vez al día con el voltaje. Así, una alarma de offline en el perfil te indica que un sensor ha fallado, algo que un diseño que solo despierta nunca detectaría. Pon también la regla de alarma de bajo voltaje sobre bat_v con algo de histéresis.
No register trick, I’m afraid. As far as I remember the sleep mode table in the 328P datasheet, the analog comparator is only a wake source in idle (and ADC noise reduction), not power-down. In power-down only the external interrupts, pin change, TWI address match and the watchdog wake it. Your idle current is the clocks running.
Move the comparator outside. A nanopower comparator with push-pull output into INT0 (D2) lets the 328P sit in power-down at a few µA. TLV3691 draws about 75 nA, and the reference can be a micropower 2.5 V shunt. Add hysteresis with a resistor from output to the + input, a few hundred mV at the battery side, otherwise a battery hovering at 11.8 V will wake you a hundred times a night as the load changes.
attachInterrupt(digitalPinToInterrupt(2), wake, FALLING);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable(); sleep_cpu(); // wakes on INT0 only
// on wake: read ADC once for the real value, send it, sleep again
Aoife: you can use the bandgap internally, but the comparator itself still can’t wake power-down, so it doesn’t help here.
On the Hermetry side I’d still send a heartbeat once a day with the voltage. Then an offline alarm on the profile tells you a sensor died, which a wake-only design never would. Put the low-voltage alarm rule on bat_v with some hysteresis too.
Traducido del English por IA ·
Pedí los TLV3691. La versión en protoboard con una referencia de 2.5 V y unos 300 mV de histéresis consume 4.8 µA en power-down y se despierta limpiamente a 11.79 V con mi fuente de laboratorio. Añadí el heartbeat diario y la regla offline. Gracias Laura, y Keisha, la versión WDT es mi plan B.
Ordered TLV3691s. Breadboard version with a 2.5 V reference and about 300 mV hysteresis sits at 4.8 µA in power-down and wakes cleanly at 11.79 V on my bench supply. Daily heartbeat added, and the offline rule. Thanks Laura, and Keisha the WDT version is my fallback.
- Debes estar registrado para responder a este debate.
Únete a la conversación
Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

