drgeoff
Posts: 9743
Joined: Wed Jan 25, 2012 6:39 pm

Re: 12v UPS DIY Help

Sun Aug 28, 2016 7:56 am

I was referring to the circuit with the FET as switch not a relay.

The current drain is that of the LM358, 0.7mA typical, plus that through the 22k and pot. Even with the pot at zero resistance that would be about 0.5mA. So less than 1.2mA total.

So 1 day would be 30mAh. Which would not be an issue for a reasonable capacity SLA.

User avatar
flatmax
Posts: 336
Joined: Thu May 26, 2016 10:36 pm

Re: 12v UPS DIY Help

Sun Aug 28, 2016 8:58 am

OK, small current trickle. However over days or weeks, that would add up. That is the equivalent of destrorying your batteries if you can't make it back to the Pi within days worth of time.

In my opinion, the circuit doesn't solve the problem of completely shutting down any current from the battery to avoid undervoltage. Perhaps if the leakage current was micro amps, then it could go for weeks and be ok ...

Matt
Last edited by flatmax on Sun Aug 28, 2016 12:01 pm, edited 1 time in total.
Check the Ultra 2 sound card - use our shop instead of Amazon Europe (Amazon USA is live).
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

drgeoff
Posts: 9743
Joined: Wed Jan 25, 2012 6:39 pm

Re: 12v UPS DIY Help

Sun Aug 28, 2016 10:11 am

To put it in perspective.

The drain is less than 1/500 of what a RPi takes. For every 1 day longer before the SLA can be recharged, the cut-off voltage should be set fractionally higher such that the RPi can be battery powered for 3 minutes less time.

sora03
Posts: 193
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: 12v UPS DIY Help

Mon Aug 29, 2016 4:55 am

I have soldered the cirucit to a stripboard. I used 5v1 zener because 4v7 is no avail. 18k ohm resistor x2, and the IRFZ34N. I powered it up but noticed that I put the Vcc positive to LM358 Pin5 not pin8 so I resoldered it to pin 8. However nothing happens when I move the potentiometer the output of IRFZ34N is still high. It is not cutting the load... But when i connect a ammeter the current that the board is eating lessens Does it mean that I messed up something, like the connection of LM358 and the IRFZ34N or the potentiometer... Here is the picture:

[removed]

Summary:
-I connected them in stripboard from the original circuit components: 22k x2, 4v7 zener, MTP3055V I instead used 18k x2, 5v1 zener, IRFZ34N.
- Misconnected the Vcc to Pin 5 of LM358N [will this fry it?]
- LM358 Reconnected to Pin 8, nothing happens to the load it does not cut the load.

any oother ideas? If not I will switch to another circuit since I do not have all parts like MTP..., 4v7 zener...
Last edited by sora03 on Mon Oct 30, 2017 2:14 pm, edited 1 time in total.
FLOSS enthusiast, Debian user (linux-libre)

drgeoff
Posts: 9743
Joined: Wed Jan 25, 2012 6:39 pm

Re: 12v UPS DIY Help

Mon Aug 29, 2016 11:58 pm

You mention using an ammeter. if you have a voltmeter (or multimeter) check that the voltages around the LM358 are what they should be.

sora03
Posts: 193
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: 12v UPS DIY Help

Sat Sep 10, 2016 10:24 am

I am currently trying to try other low voltage circuits, I am going to update if some thing works.
FLOSS enthusiast, Debian user (linux-libre)

sora03
Posts: 193
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: 12v UPS DIY Help

Mon Jun 19, 2017 11:24 am

The 12V Simple DIY UPS circuit works but it does not have any protection (short,undercharge,overcharge) so I researched on a Battery Monitor circuit that utilized a ATtiny85 and a NTD5867 MOSFET (It is on iNstructables). The circuit was programmed using a Raspberry pi since I do not have any arduino around. It works great the only problem will be sendind a shutdown signal to Pi when the voltage limit is reached, since the battery is about 5m away from the Pi so a GPIO wire is not feasible.
FLOSS enthusiast, Debian user (linux-libre)

User avatar
GeekMike
Posts: 6
Joined: Mon Jun 27, 2016 8:42 pm

Re: 12v UPS DIY Help

Thu Jun 29, 2017 9:32 pm

Sora03:
You just described our solution. We struggled with remote installations in the field, providing clean power, battery backup, and sending a GPIO signal to alert the system of a required shutdown. When the batteries recharge, power is restored and the system boots. It's great :)

If you are interested, see: http://www.lifeguardsolution.com/

sora03
Posts: 193
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: 12v UPS DIY Help

Thu Oct 26, 2017 12:18 pm

Hey guys, i am planning to upgrade my auto cutoff circuit by adding a hardware watchdog like to RPi (prevents shutdown always on if AC and DC are available)
I used this circuit to protect the SLA battery from overdischarging: https://cdn.instructables.com/FN9/4XUC/ ... MEDIUM.jpg
I now want to control the reset P6 header by adding a transistor and resistor to control using the attiny85 if the Pi stops working/freezes or halted
I just need to get a code to send and receive signals from RPI to Attiny85 vice-versa to let the attiny85 know if RPi it is still responding. if it does not respond then the attiny85 will put cause the transistor to on and conduct the reset pin to reset the Pi, else then do nothing but monitor voltage of battery.
If the battery voltage is too low then the attiny85 will send the shutdown signal to rpi maybe using the transistor npn and resistor using a push button like ciruit. then turn off the mosfet NTD5867 after done shutting down.
My main problem is the limited pin of attiny85 and on how to I send and receive the signal to and from Rpi to attiny85.
Does sending a signal requires a attiny85 pin set output and Rpi pin input then the receiving signal requires attiny85 input pin and rpi output pin, so I can use the RESET pin of ATTINY85?
Anyone can give a example code like C code in the cutoff circuit by arduinomaster.

there are 3 pins free in the attiny85 the reset, A3, A2. is this enough to send and receive from rpi and control transisstors RESET P6, and send shutdown signal to Pi: A1,PWM2,PWM1 is used for monitoring voltage of battery and control of mosfet. Also, I will set the MP1584 to output 3v3 to not burn the GPIO of the Pi's 3v3.
I saw a youtube implementation of what I want to do but there are no schematics available,the author does not like to share his work...
https://www.youtube.com/watch?v=N2kvvM3BN-4


refs:
https://raspberrypi.stackexchange.com/q ... ly-via-usb
https://www.freetronics.com.au/pages/nd ... lbRmNIrJhE
https://electronics.stackexchange.com/q ... ff-a-motor
http://www.ermicro.com/blog/?p=423
http://www.instructables.com/id/Tutoria ... yPi-and-a/
http://www.instructables.com/id/Automat ... ch-For-Pi/
http://www.borngeek.net/Blog/attiny-back-basics
http://www.instructables.com/id/Raspber ... wn-Button/
http://www.sudomod.com/forum/viewtopic.php?t=3419
http://www.technoblogy.com/show?LSE
http://www.instructables.com/id/Program ... pberry-Pi/
https://electronics.stackexchange.com/q ... ge-divider
FLOSS enthusiast, Debian user (linux-libre)

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: 12v UPS DIY Help

Thu Oct 26, 2017 12:58 pm

ATtiny 85 has 5 free IO-Pins, not only 2? You can use these 3 used for programming also for your own needs ...

Best Regards, FM_81
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

sora03
Posts: 193
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: 12v UPS DIY Help

Fri Oct 27, 2017 2:11 am

attiny85 ____
PIN1 RESET PIN as INPUT AnalogRead -| |- PIN8 Vcc 3v3 from MP15884
PIN2 connect to 1k 2n3904 to gpio -| |- PIN7 connected to 1k and 2N3904 for controlling the RESET P6 header
PIN3 connect to RPi GPIO for receiv -| |- PIN6 connected to mosfet RPI to battery load (cut-off if battery is 12.2V
PIN4 GND -| |- PIN5 connected to mosfet NTD5867 LED for battery monitor
----

attiny85 pins
Pin 1 will be used to monitor the voltage divider seet to 3v3 for battery monitor. just do not make it below 2.5v or else will reset the attiny85 right?
Pin 2 will be connected to a 1k + 2n3904 which is connected to a GPIO 1k + 10K to ground acting as a switch to trigger soft shutdown
Pin 3 will be connected directly to a GPIO of Pi this will receive Pin HIGH LOW from RPi so the attiny knows if the Pi is runnning if not then RESET Pi P6
Pin 4 GND
Pin 5 connected to MOSFET that blinks LED for battery monitor
Pin 6 connected to RPi will cut off if battery volt is too low
Pin 7 connected to a 1k + 2n3904 that is connected to the RUN pins (RESET P6 header) to triger a hard reboot from broken system
Pin 8 will be connected to MP1584 3v3 originally set o 5v but will burn the Pi

questions are, can I connect the Pin 3 to a GPIO to receive events from RPi like a watchdog
any code to that function?
FLOSS enthusiast, Debian user (linux-libre)

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: 12v UPS DIY Help

Mon Oct 30, 2017 6:27 am

sora03 wrote:
Fri Oct 27, 2017 2:11 am
Pin 1 will be used to monitor the voltage divider seet to 3v3 for battery monitor. just do not make it below 2.5v or else will reset the attiny85 right?
I'm not sure, if this will work; there is also a pull-up-resistor on the RESET-pin? May be, you have to set the RESET-DISABLE-fuse and you must use high-voltage programming for the ATtiny later?

Greetings, FM_81
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

sora03
Posts: 193
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: 12v UPS DIY Help

Mon Oct 30, 2017 2:32 pm

FM81 wrote:
Mon Oct 30, 2017 6:27 am
sora03 wrote:
Fri Oct 27, 2017 2:11 am
Pin 1 will be used to monitor the voltage divider seet to 3v3 for battery monitor. just do not make it below 2.5v or else will reset the attiny85 right?
I'm not sure, if this will work; there is also a pull-up-resistor on the RESET-pin? May be, you have to set the RESET-DISABLE-fuse and you must use high-voltage programming for the ATtiny later?

Greetings, FM_81
it works without disabling the fuse (i don't have a high voltage programmer and I use the Pi to program the attiny85 :) ) I just maintain to not bring the voltage below 2.5v. my only problem is the interrupts implementation in the attiny85.
here is the code. the interrupt section is what i dont understand supposed tobe that the pi will set the gpio to high so the bc547 will activate and atiny85 phys pin 3 will conduct to ground pin to simulate interrupt. the intrrupt now will reset the timer on attiny85 so the reset header wont be armed and not reset the pi. otherwise it will reset the pi if the batery voltage is greater than 12.8V if not then tur off the mosfet that function is the only with issues

here is the code. i use the arduino IDE to compile HEx and upload it the Pi then to avrdude to attiny85

Code: Select all

/*
  LICENSED UNDER GNU GPL v3 

  12 Volt low battery cut off switch using an ATtiny 85 using LOW POWER without led not draining the battery.
  I use a N channel mosfet NTD5867N to switch. The circuit uses only 2 mAH, while a relay drains 65 mAH.
  Switching high-current loads.
  Maximum 60V / 20A switched load

  this program is NOT designed to keep anough power to start a car afterwards.
  it is a design to protect the battery from damage.
  this design is set to cut light to an LED at 12Volt and shut down at 12.2 Volts.

  program to turn off the source when voltage is at or below the set voltage in the software
  A car battery has 12.7 Volt and is empty at 11.8 to 12 Volts
  discharging a battery lower then 11.89 Volts (deat flat) damages it.
  If a relay (using 65 milliamp) would be used with a 120 AmpH battery, it would be flat in 3 days or 72.72 hours.

  http://www.digikey.com.au/en/resources/conversion-calculators/conversion-calculator-battery-life
  http://ep.yimg.com/ty/cdn/sports-imports/BatterydrainCalc.html
  http://www.supercircuits.com/resources/tools/volts-watts-amps-converter

  written for ATtiny 85
  input pin A1 //chip pin 7
  "Mater artium necessitas"=Necessity is the mother of invention
  Program and design by Robert Moller
  Date: 8/2015

  for 12 volt led acid battery cut out
  voltage   Volt  5 at voltage devider
  chargeing    14.4  5 100%
             12.4  4.217687075                                > 4.31
             12.3  4.183673469 blink the led to warn   4.31  && 4.27  brief power cut warning blink to led . Power getting low
  cut-off    12.2  4.149659864 cut_off point value            < 4.24  below


  when charging a car battery the voltage goes up to or near 14 Volts
  --------|              0.1uF Capacitor 104           |
  --------|o--------------------||---------------------o
  14V+  |                                            |---------
  Positive|            18k            10k (5066K)             |Negative
  Battery |----o------/\/\/\-----o----/\/\/\----=-o----|Battery
  --------|    |                 |                |    |---------
             |                 |                |
             |                 |                |
          Battery           ATtiny85           GND
             in             A1 pin7
                              PB2=A1 (RESET)

  check out voltage devider : https://learn.sparkfun.com/tutorials/voltage-dividers
  other sources : http://www.reuk.co.uk/Low-Voltage-Battery-Disconnect-Circuits.htm

  input to check battery voltage analogRead(A1)

  green1 led HIGH above 13.6 to Volts ..to be changed
  green2 led HIGH between 13.2 and 13.6 Volts
  yellow led high between 12.8 and 13.2 Volts
  red led on below 12.8 Volts

  below data if you change to a 12 Volt Battery
  AGM 12Volt battery in a Car dual system
  Healthy resting voltage  12.8V-13V
  Absorption Voltage 14.7V
  Float Voltage  13.8
  Deat flat  11.89
  12.66v . . . . . . . . . . 100%
  12.45v . . . . . . . . . . 75%
  12.24v . . . . . . . . . . 50%
  12.06v . . . . . . . . . . 25%
  11.89v . . . . . . . . . . 0%


  ATTiny85 Pinout
  -------(PCINT5/!RESET//ADC0/dW)PB5  (5) Reset -1    8-  VCC
  -(PCINT3/XTAL1/CLK1/!OC1B/ADC3)PB3  (3)    A3 -2    7-  A1 (2) PB2(SCK/USCK/SCL/ADC1/T0/INT0/PCINT2)
  --(PCINT4/XTAL2/CLK0/OC1B/ADC2)PB4  (4)    A2 -3    6-  PB1 (1) PWM (MISO/D0/AIN1/OC0B/OC1A/PCINT1)
  ------------------------------------------GND -4    5-  PB0 (0) PWM (MOSI/D1/SDA/AIN0/OC0A/!OC1A/AREF/PCINT0)
*/


/* ReModified by sora03
   Project: External RPi Watchdog and auto Reset + Battery Monitor with undervoltage auto cut-off circuit

/if gpio 22 = 0 then ok if 1 then reboot????

*/

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>


const unsigned long Alarm = 420; //Time in seconds that must pass without signal from Pi before power is reset 7mins
unsigned long Timer_time; //Tracks time since last signal from Pi

const int mosf  = 0;// pin 5 to NTD5867N S =source
const int redLed = 1;// pin red led to indicate that the voltage is about to switch off
const int resetpi = 2; //send reset to pi
const int softshut = 3; //send soft shutdow signal topi
//const int wdogin = 4; //set input from rpi


int del = 200; // delay ms
float val = 0;
float volVal = 0;



//if pi is pinging then stop reset
ISR(INT0_vect) //Interrupt routine which is called when signal is recieved from Pi
{ //pi is running so reset time and dont reset
  Timer_time = 0; //Reset timer so reset pi not triggered
}

ISR(TIMER0_COMPA_vect)
{
  //Timer interrupt called ever 0.25 seconds
  Timer_time++;
  if (Timer_time == Alarm * 4) //Alarm*4 since called every 0.25 seconds
  {

    reset_pi(); //Resets pi if Alarm time is reached
    Timer_time = 0;

  }
}



void reset_pi() { //WT? Pi is not responding

  float val = analogRead(A0); //pin 1 RESET
  float volVal = val * (3.3 / 1023.0); //=volt to any arduino pin

  if (volVal >= 2.90) { // is it safe to reset/run pi? 12.9v battery volt >
    digitalWrite(resetpi, HIGH);
    delay(2000);
    digitalWrite(resetpi, LOW);
    Timer_time = 0;
     
  }

  //so Pi is not responding could be shutdown, wait is power ok? if not then turn off the Pi
  if (volVal<=2.75  ) {
  digitalWrite(mosf, LOW);
  }
}

// Setup for outputs
void setup()
{
  cli(); // Disable global interrupts

  //set pinmodes to output
  pinMode(mosf, OUTPUT); //physical pin 5 to mosfet ntd5867
  pinMode(redLed, OUTPUT); //physical attiny85 pin 6
  pinMode(resetpi, OUTPUT); //physical attiny85 pin 3 //1k resistor + 2n3904 collector to pin 1 of P6 RESET headere and emitter to pin 2 of P6 header to reset Pi if no interruptss?
  pinMode(softshut, OUTPUT); //phys pin 7 wired to 2n304 + 1k resistor collector and emitter wired to a push button that shutdowns when pressed



  //run the pi
  digitalWrite(mosf, HIGH);
  //digitalWrite(redLed, HIGH);
  //do not reset pi
  digitalWrite(resetpi, LOW); 
  //do not send shutdown signal
  digitalWrite(softshut, LOW);

  //phys pin 4 of attiny is wired to BC547 Collector and Emitter to ground 
  //https://embeddedthoughts.com/2016/06/10/attiny85-debounce-your-pushbuttons/
  PORTB |= (1 << PB4); // enable pullup on pushbutton

   GIMSK |= _BV(PCIE);                     // Enable Pin Change Interrupts
  //Initialize interrupt on DDB2
  //MCUCR = 1<<ISC01;
  //GIMSK = 1<<INT0;
   PCMSK |= _BV(PCINT4);                   // Use PB4 as interrupt pin

  //Initialize timer interrupt to be called every 0.25 seconds
  TCCR0A = 0;
  TCCR0B = 0;
  OCR0A = 243;
  TCCR0A |= (1 << WGM01);
  TCCR0B |= ((1 << CS02) | (1 << CS00));
  TIMSK |= (1 << OCIE0A);


  Timer_time = 0;


  sei();


}

//looping code
void loop() {

 
  float val = analogRead(A0); //pin 1 RESET

  float volVal = val * (3.3 / 1023.0); //=volt to any arduino pin


  //12.9 on to 15v
  //greater than 12.5and less than or equal to 13.70 volts keeps the mosf on and led on steady - hysteries
  if (volVal > 2.90 && volVal <= 3.30) {
    digitalWrite(mosf, HIGH); //pi should be on
    digitalWrite(softshut, LOW); //DNSP
    digitalWrite(redLed,HIGH); //stdy
    digitalWrite(resetpi, LOW); //DNRP
    delay(del);
    
  }

  //13.8 bl
  //13.80 to 14.01 keeps the mosf on and led blinking fast
  if (volVal >= 3.12  ) { //3.02 13.8 but blibnks
    digitalWrite(mosf, HIGH);//pin 0
    digitalWrite(softshut, LOW);
    digitalWrite(resetpi, LOW); //do not reset pi
    // digitalWrite(redLed,HIGH);// pin 1 HIGH ONLY when charged
    //digitalWrite(redLed, HIGH);
      digitalWrite(redLed, LOW);
      delay(200);
      digitalWrite(redLed, HIGH);
      delay(200);
      digitalWrite(redLed, LOW);
      delay(200);
      digitalWrite(redLed, HIGH);
      delay(200);
      digitalWrite(redLed, LOW);
      delay(200);
      digitalWrite(redLed, HIGH);
      delay(200);
      digitalWrite(redLed, LOW);
      delay(200);
      digitalWrite(redLed, HIGH);
      delay(200);
      

  }
  //
  // gives warning to LED that power is getting low
  // when batt is  between 12.15 to 12.50 [2.77 2.85]
  if (volVal > 2.76 && volVal < 2.80) { 
       digitalWrite(redLed, LOW);
       delay(1000);
       digitalWrite(redLed, HIGH);
       delay(1000);
       digitalWrite(redLed, LOW);
       delay(1000);
       digitalWrite(redLed, HIGH);
       delay(1000);
       digitalWrite(redLed, LOW);
       delay(1000);
       digitalWrite(redLed, HIGH);
       delay(1000);
    


  }

  if (volVal < 2.77) { //oops low battery could be pwer fail
    digitalWrite(softshut, HIGH); //send signal to shutdown pi
    //delay(300);
  }

  // 12.15 and below volt turns the mosf and led off
  if (volVal <= 2.75  ) { //2.74

    digitalWrite(softshut, LOW);
    digitalWrite(mosf, LOW);
    digitalWrite(redLed, LOW);


  }
  delay(del);
}
FLOSS enthusiast, Debian user (linux-libre)

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: 12v UPS DIY Help

Mon Oct 30, 2017 4:01 pm

sora03 wrote:
Mon Oct 30, 2017 2:32 pm
it works without disabling the fuse (i don't have a high voltage programmer and I use the Pi to program the attiny85 :) ) I just maintain to not bring the voltage below 2.5v. my only problem is the interrupts implementation in the attiny85.
here is the code. the interrupt section is what i dont understand supposed tobe that the pi will set the gpio to high so the bc547 will activate and atiny85 phys pin 3 will conduct to ground pin to simulate interrupt. the intrrupt now will reset the timer on attiny85 so the reset header wont be armed and not reset the pi. otherwise it will reset the pi if the batery voltage is greater than 12.8V if not then tur off the mosfet that function is the only with issues
It's nice to hear, that such "untypical implementation" works! But I'm afraid, I cannot help you with your code, it's looks like C for me.
(And I'm not really good in this - It would be another thing, if you've asked about ATMEL's assembler.) But it looks interesting ...

Best Regards, FM_81

PS: My approach is a little bit different, I use a ATtiny 13 as power-controller for a portable RPi3 with screen. (One microswitch for ON/startup or shutdown/OFF and an ADC-input as battery-monitor.)
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

sora03
Posts: 193
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: 12v UPS DIY Help

Mon Oct 30, 2017 11:27 pm

FM81 wrote:
Mon Oct 30, 2017 4:01 pm
sora03 wrote:
Mon Oct 30, 2017 2:32 pm
it works without disabling the fuse (i don't have a high voltage programmer and I use the Pi to program the attiny85 :) ) I just maintain to not bring the voltage below 2.5v. my only problem is the interrupts implementation in the attiny85.
here is the code. the interrupt section is what i dont understand supposed tobe that the pi will set the gpio to high so the bc547 will activate and atiny85 phys pin 3 will conduct to ground pin to simulate interrupt. the intrrupt now will reset the timer on attiny85 so the reset header wont be armed and not reset the pi. otherwise it will reset the pi if the batery voltage is greater than 12.8V if not then tur off the mosfet that function is the only with issues
It's nice to hear, that such "untypical implementation" works! But I'm afraid, I cannot help you with your code, it's looks like C for me.
(And I'm not really good in this - It would be another thing, if you've asked about ATMEL's assembler.) But it looks interesting ...


Best Regards, FM_81

PS: My approach is a little bit different, I use a ATtiny 13 as power-controller for a portable RPi3 with screen. (One microswitch for ON/startup or shutdown/OFF and an ADC-input as battery-monitor.)
thanks for your response. however i do not know anything aboht atmels's assembler. your approach is almost the same as mine. the RESET pin is the ADC to monitor the batt voltage, a switch that can be pressed by me is also wired to attiny85 to send shutdown signal to pi if batt volt is low, another is connected to the reset p6 header of pi so if the pi is not responding(halted,freezed) it will reboot the pi only if theres enough batt voltage. the pi will send signal to a pin in attiny85 to reset the timer that will reboot the pi.


heres the circuit schematic it appears to work now but i will monitor if the pi suddenly resets or halts
Image
gpio from pi will send high and low signal for 2 seconds every 5 mjnutes
a gpio has switch wired to a gpio + 1k + 10k to ground
FLOSS enthusiast, Debian user (linux-libre)

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: 12v UPS DIY circuit attiny85 lm317

Tue Oct 31, 2017 8:29 am

The ATtiny 85 has it''s own watchdog. It can be figured to a maximal timeout of 8 seconds; for example to create an interrupt. If you combine this with an additional counter, which reacts only after 38 (8*38=304 which is 5 minutes and 4 seconds) - Could this be a solution?
And the pin-change-interrupt which gets the signal from the raspberry must have done something after these 304 seconds; otherwise the raspberry is probably freezed. Check this "something" in the WDR-interrupt ...

In another example I needed at least 10 or 11 seconds, but the ATtiny gaves me only 8; so I decided, to set the watchdog to 4 seconds and added an counter with 3. The corresponding interrupt-routine (only as example):

Code: Select all

WDT:		; called every 4 seconds
sbis PINB,4	; skip if bit 4 is set !!! THIS IS THE "SOMETHING" IN MY EXAMPLE !!!
WDT_END:
reti		; if cleared, back without action
inc WC		; increase counter
cpi WC,3	; compare with timeout
brne WDT_END	; not reached, back without action
cbi PORTB,0	; switch OFF (MOSFET-output at LOW)
rjmp LOOP	; endless loop
REMARK: This interrupt-routine doesn't save/restore status-register SREG, because the MAIN-loop in this example does NOTHING (not showed here), so there is nothing needed to save. But normally you have to save and restore SREG at the start and end of every ISR.

MfG, FM_81
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

sora03
Posts: 193
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: 12v UPS DIY circuit attiny85 lm317

Thu Nov 02, 2017 10:57 am

FM81 wrote:
Tue Oct 31, 2017 8:29 am
The ATtiny 85 has it''s own watchdog. It can be figured to a maximal timeout of 8 seconds; for example to create an interrupt. If you combine this with an additional counter, which reacts only after 38 (8*38=304 which is 5 minutes and 4 seconds) - Could this be a solution?
And the pin-change-interrupt which gets the signal from the raspberry must have done something after these 304 seconds; otherwise the raspberry is probably freezed. Check this "something" in the WDR-interrupt ...

In another example I needed at least 10 or 11 seconds, but the ATtiny gaves me only 8; so I decided, to set the watchdog to 4 seconds and added an counter with 3. The corresponding interrupt-routine (only as example):

Code: Select all

WDT:		; called every 4 seconds
sbis PINB,4	; skip if bit 4 is set !!! THIS IS THE "SOMETHING" IN MY EXAMPLE !!!
WDT_END:
reti		; if cleared, back without action
inc WC		; increase counter
cpi WC,3	; compare with timeout
brne WDT_END	; not reached, back without action
cbi PORTB,0	; switch OFF (MOSFET-output at LOW)
rjmp LOOP	; endless loop
REMARK: This interrupt-routine doesn't save/restore status-register SREG, because the MAIN-loop in this example does NOTHING (not showed here), so there is nothing needed to save. But normally you have to save and restore SREG at the start and end of every ISR.

MfG, FM_81
sadly i do not know anything about assebly language but will try it at later date.
my code appears to work I just tweaked it further so the pi wont be reseting endlessly.
I plan to add a isolation between the battery and AC, should the AC go out then the battery takes over because the battery in the circuit does not reach full charge because it is somewhat being used by the Pi even if the AC i online. The closest simple solution that I found is using a relay like in this early post: it misses a flyback diode to protect the Pi viewtopic.php?t=26993
but the problem is the cost of the capacitor and the capaciitance that i will use. i am thinking if i can use another attiny to detect power failure and switch power sources but I only have N channel mosfet NTD5867 so I think it won't work. I cannot find any schotty diode to replce the 1n5400 diode... or just maybe I should change the charging circuit of the SLA...
FLOSS enthusiast, Debian user (linux-libre)

BobDodds
Posts: 2
Joined: Sun Jun 03, 2018 6:15 pm

Re: [SOLVED]12v UPS DIY circuit attiny85 lm317

Wed Jun 20, 2018 6:44 pm

How about using the Pi as a microcontroller, taking sensors reads and cutting the whole system off when the battery reaches what we decide is the no-go zone like 20% or whatever, as detected by voltage, I guess? Anyway, use the intelligence of the Pi, and that potential for strategic decision-making to say don't start up until a human comes back and charges batt way beyond Pi's total system shutdown condition.

OK, sounds good, but what combination of relays which are on if powerred, or, if not powerred, will allow us to get to the point where the Pi can take over as microcontroller? Food for thought. A momentarily on push button on a bypass, with human operator, would be an easy way to jump start when Pi is off to begin with, and that just may be good enough if that is the only way we can prioritize running as long as we can but with full protection. Use the Pi in a way that if the PI decides we're in critical bollux, the system will not restart until human operator has manually charged the battery, or, AC power is definitely back on--probably not because one of the posters has pointed out that the AC power being on is not enough of a guarantee so that if Pi then comes in that dangerous mode of brownout condition and Pi detects that relative to charge level of batt then Pi's decision to shut all down will be enforced until the human presses a bypass button.

Here's a solar panel to battery charge controller that does that, and will not allow system restart until human charges the batteries. So we avoid the resetting loop the same way, using Pi and supporting relays:

https://www.amazon.com/ALLPOWERS-Charge ... 3M69RZGATQ
The product can automatically manage the working of solar panel and battery in solar system. It is easy to set up and operate.For protecting the lifespan of your battery, once the voltage of the battery drop below 8V, the solar controller will turn off automatically (LCD will be unavaiable at the same time).

Change the default setting of solar controller, requires:
1. Disconnect the solar panel
2. ensure the remain voltage of battery no less than 12V

(....so it goes into lockdown at 8V, and then won't allow restart until human intervenes and charge is 12v, which of course requires a separate charging system at somewhere 13.5 to 17 volts. We could do that with Pi, maybe nvram "default setting(lockdown requires 12v) but hopefully a simple relay enforced no-start without push button jump start **AND** 12v" then it goes into 12v down to allowable 8.5v or whatever -B)

Return to “Beginners”