One other idea - if battery life is paramount...
Use a ds3231 (or other) RTC to wake the MCU using an alarm every 24 hours. If you only need occasional readings?
KTV sounds fun but good luck getting out with your credit rating intact?
Martin
"sleep" inside a loop
-
- Valued Contributor
- Posts: 1453
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
-
- Posts: 127
- Joined: Wed Dec 02, 2020 3:59 pm
- Has thanked: 24 times
- Been thanked: 9 times
Re: "sleep" inside a loop
Hello,
If the RTC sounds good, the only obstacle is that they are look very low cost, anyway I will consider it, I think I have a DS3231, Thanks Martin.
Lain I'm going to try the options you mentioned, any of the options are supported by the PIC16F1847 with this there is capacity for the RTC and PIC12F1840
I'm going to try both options.
P.D. I didn't know what a KTV was, but speaking of soft drinks, in Mexico there's nothing like a Bohemia, TKT or Corona, without forgetting a glass of good Tequila, obviously accompanied is better
. . . Cheers I say Greetings.
Enrique
If the RTC sounds good, the only obstacle is that they are look very low cost, anyway I will consider it, I think I have a DS3231, Thanks Martin.
Lain I'm going to try the options you mentioned, any of the options are supported by the PIC16F1847 with this there is capacity for the RTC and PIC12F1840
I'm going to try both options.
P.D. I didn't know what a KTV was, but speaking of soft drinks, in Mexico there's nothing like a Bohemia, TKT or Corona, without forgetting a glass of good Tequila, obviously accompanied is better


Enrique
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: "sleep" inside a loop
Hic
Can you try the attached.... Debugging long distance is a nightmare (but no H/W to test
) - this should toggle pin 'Output' (in properties) at a rate set by the pre-scaler passed to Sleep. I used 0 (1ms) but see page 95 of the datasheet for all the allowable values..
I have 'tried' WDT controlled by SWDTEN - but also try Enabled (Build->Properties)
Also used internal clock - change to External (and clock speed) as required.
Martin

Can you try the attached.... Debugging long distance is a nightmare (but no H/W to test

I have 'tried' WDT controlled by SWDTEN - but also try Enabled (Build->Properties)
Also used internal clock - change to External (and clock speed) as required.
Martin
- Attachments
-
- PIC12Sleep.fcfx
- (8.57 KiB) Downloaded 97 times
-
- Posts: 127
- Joined: Wed Dec 02, 2020 3:59 pm
- Has thanked: 24 times
- Been thanked: 9 times
Re: "sleep" inside a loop
Haha, off topic
Ok let me try this, I really appreciate it, I'm running out of time to show it
Saludos !!

Ok let me try this, I really appreciate it, I'm running out of time to show it

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
Did you hear about the Mexican fireman? His wife had twins and they called them Hose-A and Hose-B.......
I think we all have a "tequila" story, usually ending up in a baaaad way.....
Glad Martin is able to help with some hardware testing. Theory is all good and well but you can't beat seeing what happens with the silicon.
Good luck!
Did you hear about the Mexican fireman? His wife had twins and they called them Hose-A and Hose-B.......
I think we all have a "tequila" story, usually ending up in a baaaad way.....

Glad Martin is able to help with some hardware testing. Theory is all good and well but you can't beat seeing what happens with the silicon.
Good luck!
-
- Posts: 127
- Joined: Wed Dec 02, 2020 3:59 pm
- Has thanked: 24 times
- Been thanked: 9 times
Re: "sleep" inside a loop
Hello,
Jajaja, with tequila you drink it, you relax and in a moment you're talking to yourself... right now would be a good time for me to enjoy an Agavero.
I feel like a child who can barely walk and already wants to run.
I don't understand many terms or programming processes, we are learning along the way, it takes time, I understand, right now I was presented with an opportunity that I wouldn't want to miss, I don't have enough time to finish learning the "sleep" mode abusing your knowledge, do you think you can help me to insert the sleep mode, no matter how hard I try the program crashes, without the "sleep" it works perfectly the function is achieved correctly, the problem appeared when adding the batteries.
I have the original program, I added what has worked for me, could you see it, I would be very grateful
Best Regards
Enrique
Jajaja, with tequila you drink it, you relax and in a moment you're talking to yourself... right now would be a good time for me to enjoy an Agavero.
I feel like a child who can barely walk and already wants to run.
I don't understand many terms or programming processes, we are learning along the way, it takes time, I understand, right now I was presented with an opportunity that I wouldn't want to miss, I don't have enough time to finish learning the "sleep" mode abusing your knowledge, do you think you can help me to insert the sleep mode, no matter how hard I try the program crashes, without the "sleep" it works perfectly the function is achieved correctly, the problem appeared when adding the batteries.
I have the original program, I added what has worked for me, could you see it, I would be very grateful

Best Regards
Enrique
- Attachments
-
- 1847QcaudWDT.fcfx
- (25.67 KiB) Downloaded 104 times
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: "sleep" inside a loop
Hope Iain's not about to hit super-typhoon Man-Yi. Sounds bad. We have 60 mph winds today and that's enough to stop the planes and ferries running (and flatten the chicken run
though fortunately the chickens were in their winter quarters)
Enrique - what is your program trying to do? Int0 is caused by what?. You have a timer - interrupt on timer 1 will wake MCU at 75Hz - so sleep seems unnecessary.
I've ordered a couple of 12f1840 chips (had a CPC order to send) so testing will be easier. However - it's a good use case for Flowcode's excellent simulation - just use 'delay' instead of sleep. Obviously still need to test on hardware - but good for getting your algorithm right.
One thing - you goto A (at the start of the program) and re-initialise the interrupts - which shouldn't be needed. Also I'd suggest getting the rid of the gotos (the goto B especially makes the code very hard to follow...)
Martin

Enrique - what is your program trying to do? Int0 is caused by what?. You have a timer - interrupt on timer 1 will wake MCU at 75Hz - so sleep seems unnecessary.
I've ordered a couple of 12f1840 chips (had a CPC order to send) so testing will be easier. However - it's a good use case for Flowcode's excellent simulation - just use 'delay' instead of sleep. Obviously still need to test on hardware - but good for getting your algorithm right.
One thing - you goto A (at the start of the program) and re-initialise the interrupts - which shouldn't be needed. Also I'd suggest getting the rid of the gotos (the goto B especially makes the code very hard to follow...)
Martin
-
- 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
Man-Yi is over the Philippines just now and seems to be moving north west, so Taiwan shouldn't be affected.
The Friday night beer drinking contest did affect me.....
I can maybe have a look at your chart tomorrow, but I echo Martin's comment that you shouldn't need both TMR1 and WDT as TMR1 really makes the WDT redundent.
I'm guessing that you are using a scope or an analyser, as trying to see a 50mS flash on a LED would be a struggle
Regards
Man-Yi is over the Philippines just now and seems to be moving north west, so Taiwan shouldn't be affected.
The Friday night beer drinking contest did affect me.....
I can maybe have a look at your chart tomorrow, but I echo Martin's comment that you shouldn't need both TMR1 and WDT as TMR1 really makes the WDT redundent.
I'm guessing that you are using a scope or an analyser, as trying to see a 50mS flash on a LED would be a struggle

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
Are you really talking about a typhoon?
I live in Monterrey, Mx; here we are protected by the Sierra Madre very close to Cerro de la Silla, surrounded by hills that fortunately avoid hurricanes or typhoons, only torrential rains on occasions
The task is to open a valve with a small pulse, at the same time the tmr1 starts to keep track of the time that passes, in the first 4 hours you can have water up to a limit of 200 liters and the water valve will close, either after 4 hours or after consuming the 200 liters of water, whichever occurs first, after 24 hours it will start the cycle again.
With a flow meter connected to B0 int0 interrupt, we measure the liters and tmr1 the time, the batteries are to avoid the circuit being restarted when the electricity goes out or if someone cuts the power.
Add a transistor (for the flow meter) A2 as a switch so that when the water valve is closed for the remaining 20 hours after the 4 hours have passed or after consuming the 200 liters, the transistor disconnects the flow meter to avoid unnecessary energy consumption, it consumes 5 mA, that's why I changed to the pic 16F1847, I needed more pins.
The project is interesting
Saludos
Are you really talking about a typhoon?

The task is to open a valve with a small pulse, at the same time the tmr1 starts to keep track of the time that passes, in the first 4 hours you can have water up to a limit of 200 liters and the water valve will close, either after 4 hours or after consuming the 200 liters of water, whichever occurs first, after 24 hours it will start the cycle again.
With a flow meter connected to B0 int0 interrupt, we measure the liters and tmr1 the time, the batteries are to avoid the circuit being restarted when the electricity goes out or if someone cuts the power.
Add a transistor (for the flow meter) A2 as a switch so that when the water valve is closed for the remaining 20 hours after the 4 hours have passed or after consuming the 200 liters, the transistor disconnects the flow meter to avoid unnecessary energy consumption, it consumes 5 mA, that's why I changed to the pic 16F1847, I needed more pins.
The project is interesting
Saludos