
"sleep" inside a loop
-
- Posts: 127
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 02, 2020 3:59 pm
- Has thanked: 24 times
- Been thanked: 9 times
Re: "sleep" inside a loop
With that consumption of 0.012 mA, in your practical experience using batteries, how long do you think they can last with 3 or 4 AA batteries 

-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: "sleep" inside a loop
Hi
Funny you should mention but Agavero and its friends help me sleep too...... Not usually in my bed though.... more likely under a tree or on a beach chair.....
Glad you are finding success, and as you say you will always find a way to save more.
When you say you are drawing 12uA that is indeed good going. I am assuming during sleep. However what is the current when the valve is active and receiving data from flow meter? That will have more bearing.
Most manufacturers have discharge tables and I've attached one I have for a Duracell AA (other brands are available). In it you will see discharge curves at various currents. Note that these assume a constant current. The lowest documented in this chart is 5mA and will take 700 hours (about 30 days) to reach a voltage of 0.8v. At 10mA it's about half of that. You at micro-amps are in the territory of self-discharge / shelf life or "forget about them"
Measure draw with active valve and sensor. That will be far more relevant as you can pretty much forget about what the PIC is doing when asleep.
Regards
PS
Also attached is a sheet for a "Lithium" from another well known brand
Funny you should mention but Agavero and its friends help me sleep too...... Not usually in my bed though.... more likely under a tree or on a beach chair.....

Glad you are finding success, and as you say you will always find a way to save more.
When you say you are drawing 12uA that is indeed good going. I am assuming during sleep. However what is the current when the valve is active and receiving data from flow meter? That will have more bearing.
Most manufacturers have discharge tables and I've attached one I have for a Duracell AA (other brands are available). In it you will see discharge curves at various currents. Note that these assume a constant current. The lowest documented in this chart is 5mA and will take 700 hours (about 30 days) to reach a voltage of 0.8v. At 10mA it's about half of that. You at micro-amps are in the territory of self-discharge / shelf life or "forget about them"

Measure draw with active valve and sensor. That will be far more relevant as you can pretty much forget about what the PIC is doing when asleep.
Regards
PS
Also attached is a sheet for a "Lithium" from another well known brand
- Attachments
-
- Energizer L91 Datasheet.pdf
- (327.3 KiB) Downloaded 106 times
-
- MN1500 AA.pdf
- (1.17 MiB) Downloaded 108 times
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: "sleep" inside a loop
Hi
You mentioned earlier that batteries were to avoid issues with the "Mains" so that means you do have access to an AC derived supply.
You could easily create a mains derived circuit to actuate the valve, possibly being controlled by a simple "Flip-Flop". This way your battery powered controller would in reality last many years depending on battery choice.
Again just thinking aloud.
Create an A/C derived circuit to switch valve On and Off controlled from a Flip-Flop. Many examples available. The output of the Flip-Flop is either On or Off (1 or 0) and this via appropriate transistor activates the valve.
The Flip-Flop will change state upon receiving a pulse from your PIC controller. So the controller pulses once to start and once to stop (sleeping pretty much all other times). PIC also monitors output state of Flip-Flop, possibly using the complementary output. PIC therefore knows which state Flip-Flop is in and therefore if valve is on or off.
Mains derived circuit has a 3v or 5v connection to IOC pin on PIC, interrupting on rising edge. If mains fails, PIC under battery power doesn't care. When power is restored, IOC activates on rising edge and the PIC then checks to see if valve should be open or closed etc.
I think it would be easy to implement the electronics for this and FC can easily handle the code for your PIC.
Regards
You mentioned earlier that batteries were to avoid issues with the "Mains" so that means you do have access to an AC derived supply.
You could easily create a mains derived circuit to actuate the valve, possibly being controlled by a simple "Flip-Flop". This way your battery powered controller would in reality last many years depending on battery choice.
Again just thinking aloud.
Create an A/C derived circuit to switch valve On and Off controlled from a Flip-Flop. Many examples available. The output of the Flip-Flop is either On or Off (1 or 0) and this via appropriate transistor activates the valve.
The Flip-Flop will change state upon receiving a pulse from your PIC controller. So the controller pulses once to start and once to stop (sleeping pretty much all other times). PIC also monitors output state of Flip-Flop, possibly using the complementary output. PIC therefore knows which state Flip-Flop is in and therefore if valve is on or off.
Mains derived circuit has a 3v or 5v connection to IOC pin on PIC, interrupting on rising edge. If mains fails, PIC under battery power doesn't care. When power is restored, IOC activates on rising edge and the PIC then checks to see if valve should be open or closed etc.
I think it would be easy to implement the electronics for this and FC can easily handle the code for your PIC.
Regards
-
- Posts: 127
- Joined: Wed Dec 02, 2020 3:59 pm
- Has thanked: 24 times
- Been thanked: 9 times
Re: "sleep" inside a loop
Hello,
It is a good option to extend the life of the batteries, I think I will take it into account in projects, the problem with this circuit is that it would be encapsulated in a box, with no way to be altered or the start time changed, so if it was installed at 8:00 am every day you would have water until 12:00 without failing. Without a way to alter the time.
This way you would have a way to control the person so that they respect the schedules and are punctual.
Saludos
It is a good option to extend the life of the batteries, I think I will take it into account in projects, the problem with this circuit is that it would be encapsulated in a box, with no way to be altered or the start time changed, so if it was installed at 8:00 am every day you would have water until 12:00 without failing. Without a way to alter the time.
This way you would have a way to control the person so that they respect the schedules and are punctual.

Saludos
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: "sleep" inside a loop
Hi
I thought a button was pushed to indicate the "start" of the 4 / 24 hour cycle? If not, when does the 24hrs run from and how is the valve started?
Regards
I thought a button was pushed to indicate the "start" of the 4 / 24 hour cycle? If not, when does the 24hrs run from and how is the valve started?
Regards
-
- Posts: 127
- Joined: Wed Dec 02, 2020 3:59 pm
- Has thanked: 24 times
- Been thanked: 9 times
Re: "sleep" inside a loop
Hello Lain,
The battery holder, I'm going to add a cardboard or plastic that isolates a battery from a terminal of the battery holder that comes out of the box, when stretching and removing that plastic the battery will make contact and start the circuit;
Until the batteries are exhausted the box will not open, for now I lowered the consumption with the recommendations that you told me, grounding and deactivating the unused pins, removed the crystal, selected the internal clock and lowered the frequency from 19 to 4 mhz, used transistors to activate or turn off the components, and extended a few more days and continue doing tests with the sleep; one stage works and another stops working, it seems that I solved the problem and another one appears, but I'm moving forward
In the 20 hours of waiting it remained at 0.16mA, and the flow sensor in the 4 hours remained at 2.4mA, but in these days I hope to be able to use the sleep mode and for now with these values and using 3 batteries, I think it will work for 2 months taking into account the Duracell table.
Saludos.

The battery holder, I'm going to add a cardboard or plastic that isolates a battery from a terminal of the battery holder that comes out of the box, when stretching and removing that plastic the battery will make contact and start the circuit;
Until the batteries are exhausted the box will not open, for now I lowered the consumption with the recommendations that you told me, grounding and deactivating the unused pins, removed the crystal, selected the internal clock and lowered the frequency from 19 to 4 mhz, used transistors to activate or turn off the components, and extended a few more days and continue doing tests with the sleep; one stage works and another stops working, it seems that I solved the problem and another one appears, but I'm moving forward

In the 20 hours of waiting it remained at 0.16mA, and the flow sensor in the 4 hours remained at 2.4mA, but in these days I hope to be able to use the sleep mode and for now with these values and using 3 batteries, I think it will work for 2 months taking into account the Duracell table.
Saludos.
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: "sleep" inside a loop
Hi
2.4mA running and 0.16 sleeping gives a rough average of 0.53mA over a 24hr period which using the Alkaline would be more like nine or ten months of life, longer with Lithium.
When I'm next in my evil lab I'm going to experiment with sleep and timers
Regards
2.4mA running and 0.16 sleeping gives a rough average of 0.53mA over a 24hr period which using the Alkaline would be more like nine or ten months of life, longer with Lithium.
When I'm next in my evil lab I'm going to experiment with sleep and timers

Regards
-
- Posts: 127
- Joined: Wed Dec 02, 2020 3:59 pm
- Has thanked: 24 times
- Been thanked: 9 times
Re: "sleep" inside a loop
Hello
Thank you for your help, I was thinking about adding a RESET at the end of the 24 hours. A few hours ago I was doing some tests, the program started and everything was fine when it started, but on the first restart when the 24 hours ended, I noticed that the liter counter did not close the valve.
I think it saves some information, Maybe adding the RESET at the end and starting the program from the beginning would be the solution.
Tomorrow I will do the test. (For now I know that the base program with the hardware fixes would keep the circuit running for more than 3 months.)
Saludos
Thank you for your help, I was thinking about adding a RESET at the end of the 24 hours. A few hours ago I was doing some tests, the program started and everything was fine when it started, but on the first restart when the 24 hours ended, I noticed that the liter counter did not close the valve.
I think it saves some information, Maybe adding the RESET at the end and starting the program from the beginning would be the solution.
Tomorrow I will do the test. (For now I know that the base program with the hardware fixes would keep the circuit running for more than 3 months.)
Saludos
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: "sleep" inside a loop
Hi
Can you share your chart? I'm not a great fan of using reset unless really necessary.
Regards
Can you share your chart? I'm not a great fan of using reset unless really necessary.
Regards
-
- Posts: 127
- Joined: Wed Dec 02, 2020 3:59 pm
- Has thanked: 24 times
- Been thanked: 9 times
Re: "sleep" inside a loop
Hello
Sure, I'll send it to you.
Regards
Sure, I'll send it to you.
Regards
- Attachments
-
- 1847tickB.fcfx
- (33.88 KiB) Downloaded 83 times