Putting a PIC16F88 into and out of sleep mode

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Hi all,

Although I personally am using Flowcode v4, I guess the question is not limited to v4 which is why I am posting this here.
In the attachment below, I need to connect a battery (I don't want to use a switch), and after a few seconds of 'settling down' (say 20), the PIC goes into sleep mode (being battery powered I want to keep power requirement to absolute minimum as PIC will be powered for infinitely long periods of time without anything happening). I need the PIC to wake up when a particular switch input is made and continuously output the UART signal of the appropriate switch until power is removed.
Although I have looked through the forums I cant find exactly what I'm after and can't quite understand how I do this. Can anyone help?

Thanks in advance,

Chris
Attachments
AI SUPERSENDER X 88 FINAL.fcf
(9 KiB) Downloaded 536 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by Benj »

Hi Chris,

Sounds like you need to put the chip to sleep by calling the sleep function using a C icon.

I think this is:

Code: Select all

sleep();
Before you put the chip into sleep mode enable an interrupt, either a INT pin or a IOC interrupt on change. Then your switch press can be used to trigger the interrupt which should wake the chip back up.

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Many thanks Benj

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Ahhh - problem is that I want whichever switch is operated to take PIC out of sleep and so would want the IOC availability but I discover it isn't listed/available on the PIC16F88 - is there some way round this in 'custom' perhaps? I cant really start from scratch on the PCB and circuitry as it is all built. I wasn't expecting to have a problem with battery power but a part is taking much more current than I was led to believe and I haven't any room to increase battery capacity with any available alternative. I suppose I could use another chip but it would need to line up with every pin of the F88. Actually I am already using the LF88 to conserve power and lower the nominal supply voltage to 3.6 and that was BEFORE the power problem!
Anyone got a work-round re the lack of IOC on this chip.

Also couldn't get it to work using INT and my lack of knowledge to try to get it to sleep in the first place. I seem to remember reading about it not working in Flowcode simulation until v5 but I only have v4!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by Benj »

Hello Christoph,

The chip does have IOC capabilities on PortB pins 4-7 it just must be unavailable in your v4 definition file. It's certainly included in v6 and v7.

Here is the code to use in a custom interrupt. In the interrupt macro be sure to read the PortB register, probably using an input icon. You need to do this to rearm the interrupt.

Enable:

Code: Select all

st_bit(intcon, RBIE);
Disable:

Code: Select all

cr_bit(intcon, RBIE);
Handler:

Code: Select all

if (ts_bit(intcon, RBIF))
{
FCM_%n();
cr_bit(intcon, RBIF);
}
The sleep function or any other C code will not simulate in Flowcode, including Flowcode 7.

Your custom interrupt also will not simulate.

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Hi Benj, Thankyou for your reply, yes I looked up the data sheet for the F88 and saw those pins had IOC but I needed 5 available but I am using RB6 for UART Tx so couldn't have used IOC after all.
I will use your info to see if I can get round the problem somehow.

Cheers,

Chris

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by Steve »

If for some reason you can't use INT (RB0) or IOC (RB4-7), then an alternative might be to use a TMR1 or WDT interrupt to briefly wake the micro at regular intervals and check the status of other pins (and then go straight back to sleep if necessary. Reception of data on the UART can also wake the device from sleep.

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Hi Steve,
Thankyou for your further info. on this and useful re a received UART signal will do this as I may use this in another part of the project.
No information is wasted - 'Every little helps'!

Regards,
Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Hi Benj,
Can I just clarify in YOUR last post (as I wont be able to simulate) whether it is 'st_bit' or 'ts_bit' ?
Thanks
Regards
Chris

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by Benj »

Hi Chris,

st_bit - Sets a bit in a register.
cr_bit - Clears a bit in a register.
ts_bit - Tests a bit in a register.

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Hi Benj,
Only just been able to get back to project at last - OK thankyou for the clarification.
Much appreciated
Cheers'
Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Hi Benj and all,
I have decided to change the transmitter chip after all, to a PIC16F883 because I want the incoming switch signal on RB0 to RB4 to be the trigger AND send its appropriate UART decimal number as seen in Macro TxUART.
It seems a bit over-kill for what I need but I couldn't see another way and here, the F883 allows for a)the full Port B for IOC interrupts (but doesn't seem to!), b)UART Tx on Port C, c)MCLR on Port C.
I have incorporated the SLEEP function and the INTERRUPTS into this latest Flowchart that is attached.
However, switches B0 to B3 do not even trigger the IOC stage, switch B4 DOES do so and B5 to B7 simply give the binary code for the relevent switch operated (which I am not bothered about as I'm only interested in B0 to B4 and the receiver ignores all other decimal numbers.

I cant fathom out why B0 to B3 doesent work and only B4 does.

PLEASE can anyone see why?

Chris
Attachments
NEW TRANSMITTER.fcf
(15.5 KiB) Downloaded 476 times

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Oh, OK I have been doing a bit of interrupts searching and I see that the PIC family allows for the interrupts on RB4 to RB7 so I will now move my switches to those 4 inputs but I need 5 INPUT SWITCHES.
Can anyone suggest how I could deal with the 5th switch?

Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

HI,
I now see that on some 'old' micros there were only RB4 - RB7 available as is the case with my latest chip selection.
Because of this and to reduce chip physical size, I now want to use a PIC16LF1823 14-pin chip which has RA0, 1,2,4 and 5 IOC leaving RA3 for MCLR (which I guess I leave unmasked) and RC4 for my UART Tx output.
Will this work 'in principle'?

I would like to do a new flowchart but the F1823 is not listed when I click on 'Chip' at the top of the Flowchart, HOWEVER, it IS listed when I switch to 'Expert configuration screen'. BUT it says 'could not find start or end address for PIC16LF1823. So I click on 'OK', then click 'OK' on 'expert config screen' and message says under the title "Matrix PICmicro Programmer", 'Could not set selected chip:, Unrecognised chip: <PIC16LF1823>.

I believe there is a way of getting round this as it has happened a long time ago and this chip has all the properties I need including extreme low power and sleep mode.

PLEASE can someone suggest how to get this chip into my v4 Flowcode and then I can carry on using my posted flowchart and have the 5 inputs I need

Thankyou in anticipation

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by Benj »

Hello Christoph,

This chip is included in Flowcode 7, buying just a single chip pack to allow you to compile to the device should not be too expensive.


As for the configuration in v4, you could try to download the latest PPP and see if it has been added there. If not then you should be able to add the configuration settings by working out the required values using the datasheet and using the supplementary code window. Use another project where the config is present to see what the C code looks like.

PPP - http://www.matrixtsl.com/resources/getr ... .php?id=15


Our mLoader software should allow you to program the 16F1823 on an EB006 board if the PPP software won't let you do it.

mLoader - http://www.matrixtsl.com/resources/getr ... php?id=884

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Hi Benj,

I had the latest PPP but tried 'MS repair' AND re-installation but no good.
I tried mLoader several times but I just get multiple pages one after the other flashing through and task manager cant deal with it so had to turn off PC and re-boot each time.
My development board is a HP488 V3.

I don't know what this is or where I get it from or how it 'works' ? :- "This chip is included in Flowcode 7, buying just a single chip pack to allow you to compile to the device should not be too expensive."

Also is there some way that I can look further back in my postings than I appear able to do at the moment, as I know this business of chip being listed but not able to use has come up before and someone came up with the answer which worked fine at that time.

REALLY DESPERATE for further help in simply being able to get this chip onto a flowchart so I can re-do circuits and PCB prototype again.....

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

OK - I can see all my postings now so there must have been some 'glitch' before.

Not sure what this is or where the supplementary code window is and is it to do with getting the F1823 on board or just the config settings (which I am OK with) :- "....you should be able to add the configuration settings by working out the required values using the datasheet and using the supplementary code window. Use another project where the config is present to see what the C code looks like.

My only BIG QUESTION I need an answer to, is how to get the PIC16LF1823 which IS listed in 'Config (expert) available for my new Flowchart

SORRY - A BIT MORE HELP NEEDED still.....!

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

HOLD EVERYTHING - I have just RE-installed the same updated PPP as I did yesterday and created a new flowchart and on selecting PIC16LF1823 it HAS worked!!! So I will see how it goes for the moment......

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Have posted NEW FLOWCHART as attachment using the PIC16LF1823 and the only snag is that the INTERRUPT refers to PORT B but it should refer to PORT A as there obviously is no port B on this chip. Where is that information coming from because it doesn't even ask for the port OR state it in 'properties' ??

Does 'sleep' look OK for when I reach the 'hardware' stage as I do understand that it wont simulate. I just need to power up then it goes into sleep mode after a few seconds and is woken up by any relevant input from A 0,1,2,4 and 5 which then keeps transmitting the associated UART decimal number until either a reset to MCLR pin 4 or power off.

An answer on these two points asap would be really helpful and will get me moving again - and shut me up for a while too :))

Thankyou in advance

Chris
Attachments
NEW_16F1823-CHIP.fcf
(11.5 KiB) Downloaded 407 times

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Hi,
I have small update on the previous attachment to show the correct number of PORT A inputs which is 6 in number.
The MCLR RA3 at pin 4 will be 'tied' to +ve to enable the PIC16F1823.

I have only 2 questions:-

1) Why is 'INTERRUPT ENABLE' in 'Main' showing Port B?? (I have tried everything I can think of to solve this).

2) Does 'sleep' LOOK ok in principle??

Chris
Attachments
NEW_16F1823-CHIP.fcf
(11.5 KiB) Downloaded 400 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by Benj »

Hi Christoph,

Please be aware that Flowcode v4 is well out of support which is why you're not getting many answers.

I'm not sure why the interrupt icon is saying PORTB, it could be a limitation or assumption that was made in Flowcode 4. As long as the C code behind the scenes is correct the chip shouldn't care but the simulation probably will.

In your C icon you currently have this.

Code: Select all

/*Enter C code below these comments
Alternatively, to enter assembly code,
use the asm operator in front of each instruction, e.g.
asm movlw 5
or enclose several statements within an asm block:
asm
{
	sleep():
}
*/
So everything is inside a comment

Code: Select all

/* Comment */
You also have the sleep instruction inside the assembler directive which I don't think is needed.

In the C icon you should just be able to use this text i.e. delete everything else inside the icon. Note the semi colon vs the colon you have in your current code.

Code: Select all

sleep();
You should also have the Sleep instruction inside your loop. i.e. you go to sleep, an interrupt wakes you up to do the other code in the loop. Then you loop and go back to sleep....

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Many thanks Benj,

I have no issues with the answering side of things at all - you fellows do a sterling job even with 'old versions' like mine and my queries have always been answered by someone in the end, but I was concerned that these chips might be no good regarding the insistence of PORT B interrupt which it hasn't got.

On the issue of the 'sleep' - yes my typo I'm afraid as I know it should be a ; but many thanks for your comments to put the rest of it right.

Sorry to bother you through the office but I just have (unusually!) a whole day free of commitments and as neither of my two queries can be simulated and I also have the chips, I wanted to get it onto hardware to check it out.

Thanks again,

Cheers,

Chris

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by Benj »

No Worries Chris,

Let us know how you're getting on.

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by christoph »

Ahh, Sorry Benj but it wont compile.

I have been trying to sort out Osccon at the beginning but to no avaail and it mentions 2 errors anyway and I cant see another possibility.

Wonder if you can just spot what is being referred to - see attachment

Chris
Attachments
ERROR on Compiling.jpg
(306.84 KiB) Downloaded 6698 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Putting a PIC16F88 into and out of sleep mode

Post by Benj »

Hi Chris,

Please can you post your current project file and I will have a look for you.

Post Reply