Help with SLEEP and WAKE UP PIC16F648A

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
electron67
Posts: 323
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 106 times
Been thanked: 48 times

Help with SLEEP and WAKE UP PIC16F648A

Post by electron67 »

Hello please can someone help me,
I'm trying to make a small circuit that uses 3 AA batteries and I need to send the pic to SLEEP mode, when checking the current consumption in the PIC I realize that the current drops considerably, but I can't get the switch to do the process programmed, the program is frozen from the beginning, I have added a timer interrupt, but I can't get the PIC to enter WAKE UP mode.

Thanks
Enrique
Attachments
SENSORv5a.fcfx
Flowchart
(16.65 KiB) Downloaded 365 times

electron67
Posts: 323
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 106 times
Been thanked: 48 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by electron67 »

Hello

I have done many different tests, I used the PIC16F1847, I was able to enter the SLEEP mode and later to WAKE UP, but when the PIC wakes up, it just starts the program sequence, it interrupts and starts from the beginning, it does not finish the sequence started; for example, in the published program, 2 outputs are activated for 50 mS, then there is a 12 second delay, another 2 outputs are activated for 50 mS and at the end of that period they turn off.
The problem is that when the sequence begins it does not end.

As I believed, once the PIC was awakened, the program continued until the end of the sequence, until it again entered the block containing SLEEP :?:

I think that maybe the program that I made has something wrong or it requires knowledge of C language and this cannot be solved with block diagrams !!!


Thank you anyway
Enrique

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by stefan.erni »

Hi Enrique

Yes, after the PIC sleeps hi wake up on this place.
I suspect your PIC is crashing because of the delay in the interrupt
It's not a good idea to use a delay in an interrupt. Better do you something there like turn on a led for test( turn it off the before you let the PIC sleep) or just remove the delay in the interrupt .


regards
Stefan

electron67
Posts: 323
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 106 times
Been thanked: 48 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by electron67 »

Hi Stefan,

I appreciate the help, I will eliminating the delay, to see if I can sleep and wake up the PIC correctly without interrupting the correct sequence in the programming.

Thank you very much
Enrique

electron67
Posts: 323
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 106 times
Been thanked: 48 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by electron67 »

Hi, I still can't handle SLEEP () mode

I'm still trying to work with SLEEP () mode; and if it goes into sleep mode, but I can't wake up, with INT or IOC interrupts; When I add 10 mS to it in the MACRO interrupt it shows me error when compiling

and when I use to WDT :

WDT MX_CLEAR_WATCHDOG;
WDTCONbits.WDTPS = 0b01110; (16 seconds)

but the program is activated and restarted continuously and does not allow the completion of the PIC programming sequence.
Someone who can please see the flow chart and see where I'm wrong.
With interruption the program falls sleep and does not wake up and with WDT it is continuously restarted without the program ending.
In the flow chart I included the 2 options I am dealing with. Under project options, select :
HS,
WDT Enabled
MClr Enabled
and the other options Disabled

Thanks in advance
Enrique
Attachments
SENSORv7.fcfx
FLOWCHART
(12.23 KiB) Downloaded 389 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by chipfryer27 »

Hi

Can't seem to download your most recent file but regarding your initial post, my comments.

Your config looks OK but I have had on occasion issues with LVP enabled. Not saying it may help but I usually disable anything not needed.

Not sure I'm seeing the bigger picture with your chart. What is it you intend to happen? If I'm reading it correctly:-

Your program starts and flashes an LED on A2 for one second. You then enable an interrupt on INT0 but I don't see anything in your chart to indicate how this will be triggered i.e. I don't see anything connected to the pin (RB0), so I assume you do have something connected to the pin that will take it High when not held Low (if floating you will have many issues).

You then enter your main loop and immediately put it to sleep (not sure if it should be capitalised or not, but if not you would probably get an error compiling). I don't know how you wake it up as I don't see anything connected to INT pin (nor is WDT enabled). However assuming you do wake it up you switch off all LEDs before initialising your sensor. You should have that initialisation before your main loop as it only needs to be called once.

You then sample your sensor and branch accordingly.

If Yes you switch off LEDs B6 and A0, wait 50ms then switch on A0, wait 50ms then switch B6 off again (why?) then switch off A0. Would you notice this brief A0 led flash or are the LEDs symbolising something else? You then wait 12 seconds before switching B6 and A0 off again (were not on). After a 10ms delay you switch on B6 for 50ms before switching B6 and A0 off (again). You then wait two seconds before returning to the beginning of the loop.

If No you sample your button on A1. If Low you return to the beginning of your main loop. If High you flash B6, put A2 low before entering an endless loop that sets A2 High. It then has no means to escape.

In your ISR you only have a 100ms delay. I don't know how you are triggering the interrupt (nothing on B0) but if a switch, bouncing could cause multiple triggers. Perhaps disable upon entering and re-enable as you exit?

Hope this is of some small help

Regards

electron67
Posts: 323
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 106 times
Been thanked: 48 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by electron67 »

Hi,

Thank you very much for your help, use the pic12F1840 just need to configure the programming options window, select the
automatic Watchdog mode and enable the Watchdog; With these options selected, I choose the time in which the Watchdog enters; performs the complete program sequence and the PIC is not reset in the middle of the process.

Thanks !!!

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by chipfryer27 »

Hi

WDT when enabled will cause the chip to "reset" after a preset time has elapsed unless cleared. Depending on settings and chip this can be from a few milliseconds to a few minutes.

If triggered whilst your program is running it will cause the program to immediately start execution again from the beginning, ie jump back to the very start. If you have put the chip to sleep, then the WDT will wake up the device after the preset time and continue with operation. However unless continuously cleared within each time period (or disabled) it will then reset the chip.

Is this what you intend or are you looking for a repeatable interrupt that will trigger on for example a pin change or preset time and then perform some other duty?

Regards

electron67
Posts: 323
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 106 times
Been thanked: 48 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by electron67 »

Hi,

Yes, the idea is to put the chip to sleep, the WDT will activate the device after the preset time and continue the operation, erasing continuously in each period of time.

Best Regards !!!

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by chipfryer27 »

Hi

With WDT enabled and appropriate period set, unless cleared the program will start from the beginning after each time period has elapsed. To prevent this constant "restart" you need to insert C-code boxes throughout the program specifically placed to clear before the period has elapsed. The command is MX_CLEAR_WATCHDOG;

Say for example WDT is set for one second. Once enabled, unless cleared before one second has elapsed, or again before one second has elapsed since the last clear, then the program will jump back to the beginning.

When put to sleep, the chip will then be awakened after one second has elapsed by the WDT, the program will then continue in its operation but the WDT must be cleared again before one second has elapsed as per above or it will restart.

You must ensure that your program finishes what it is supposed to do within the WDT period or you need to insert clears until it completes or you disable WDT completely.

Start
Sleep
Do something
Goto Start

If "Do something" takes longer than the WDT period then the program will never complete "Do something" as it will constantly restart.

Hope this helps
Regards

electron67
Posts: 323
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 106 times
Been thanked: 48 times

Re: Help with SLEEP and WAKE UP PIC16F648A

Post by electron67 »

Hi,

Thanks a lot, now I understand the sleep mode better, you clarified my doubts, I will do more tests, the PIC12F1840 contains the features you mention.

Best Regards !!!

Post Reply