PDA

View Full Version : DEFINE OSC for 31 khz



gunayburak
- 11th July 2015, 02:04
Hello everyone

Is there a way to run a pic at 31khz osc with picbasic pro ?

As far as I read the user manual , the compiler allows only minimum 3 Mhz define osc setting ...

I need that osc speed for only extreme low power comsumption ..

Thanks .

rmteo
- 11th July 2015, 02:21
I need that osc speed for only extreme low power comsumption ..

Thanks .
Wrong approach to the problem. Answered this question here http://www.picbasic.co.uk/forum/showthread.php?t=20136

gunayburak
- 17th July 2015, 19:53
Thanks for the answer but in the datasheet of 12F683 it simply states


Operating Current:
-11μA @ 32 kHz, 2.0V, typical

Is it not true ?

AvionicsMaster1
- 21st July 2015, 13:43
If you're going for low power consumption you need to use either sleep and/or IOC. I've gotten into the nano Amps using those features.

gunayburak
- 22nd July 2015, 08:01
What is IOC ?

HenrikOlsson
- 22nd July 2015, 09:31
IOC is Interrupt On Change.
It can be used to trip an interrupt (and wake the PIC up if it's sleeping) when the state of a pin changes.

PBP will not support 32kHz operation. It will RUN the code of course but anything software timed (PAUSE, SEROUT, PULSIN, whatever) will be off by a factor of a lot.
You can DEFINE OSC 4 while still running the PIC at 32kHz but a PAUSE 100 for example will in fact turn into a 12500ms delay. If that's not an issue then it's perfectly fine.

Another option is to use 32kHz for the most part and then switch to 4MHz (or whatever) when you need to actually do something important. But of course, if you're not doing anything and you're looking for the lowest possible current consumption then you need to put the PIC into sleep mode and only wake it up when needed.

/Henrik.

gunayburak
- 24th July 2015, 13:32
Thank you Henrik you're the one after Darrel ...

rmteo
- 25th July 2015, 03:54
...looking for the lowest possible current consumption then you need to put the PIC into sleep mode and only wake it up when needed.

/Henrik.
What I said from the very beginning. :rolleyes:

MikeSinclair
- 2nd October 2015, 23:38
Re: Low power, PICs, PBP - tips

I just finished a very low power PBP project that I had to wade through and do a little PBP hacking. I thought I’d share some results with the forum.

Processor – a generic PIC16LF876A – not the lowest power or fastest but it’s working at an average running power of 3v @ 30 microamps. I use a 32KHz crystal, the onboard ADC, SEROUT2 at 150 baud (!), onboard EEPROM and internal PORTB pull-ups to read a hex switch plus a lot of I/O. I don’t use SLEEP as I need accurate timing and continuous processing for 9 months on a couple of AA cells. I also wanted to use plain vanilla PBP(3) as is without a lot of extra programming considerations.

Concessions made:
1. I used OSC 3 (there is no OSC 32K) as this was the lowest PBP offered (bummer)
2. Commands with implied timing like Pause and PauseUS are ~ 100x (actually 93.75x) slower than expected. IE ‘pause 10’ pauses for ~1 second. Just have to remember this but not a big concession.
3. You have to remember to turn things off after you use them like the ADC and Pull-Ups

Problems remaining:
1. Sometimes touching a pin on the processor may reset it. Spraying both sides of the PCB with a clear conformal coating like HumiSeal (almost) eliminates this problem.
2. Bringing a finger close to the chip (not even touching it) will cause a drastic increase in current consumed by the processor (??).
3. Sometimes I program a new (blank) Processor in-circuit and then check the supply current to find a >10x increase in expected supply current (~400 ua instead of 30 ua). I can "usually" permanently correct this problem by re-programming it with the same hex file (!!???). I use a meLabs USB EPIC programmer.

Notes:
- I used an meProg USB programmer with OSC = LP, WatchDog and PowerUp timers enabled, BrownOut and LV programming disabled.
- Unless you have an old computer with a built-in serial port, you may have to use something like a USB2Serial adapter that works at 150 baud – hard to find. Adapters with legitimate Prolific USB USB2Serial ICs will work.
- SEROUT2 (a lucky hack) works at 150 baud with a MODE value = 16399.
- If you use resources like ADC and internal pull-ups, you need to turn them off when not in use (they consume lots of power).
- You need to make all unused pins as outputs and set them to a (convenient) value like ‘0’. This includes in-circuit programming pins, if used.
-

Basic code (This is my much larger coder…much simplified. Hope I didn’t impose any errors):


Define OSC 3 ‘the lowest PBP will go. OSC is really a 32KHz external crystal.
INCLUDE "modedefs.bas" 'mainly for serout2 commands

‘[misc variable assignments as usual … ]

Define ADC_BITS 8 ‘ I only need 8 bits of precision
TRISA = %00000001 ‘AN0 is needed for input for ADC CHL-0
TRISB = %00001111 ‘Need lower 4 bits to read hex switch using internal PORTB pull-ups
TRISC = %01000000 ‘Misc output and input bits. PortC.7 is the serout2 bit and
‘PortC.6 is the serial input bit at 150 baud
ADCON0 = %00000000 ‘FOSC/2, CHL 0, make sure ADC is off for low power (B0 = 0 -> ADC=OFF)
ADCON1 = %00001110 ‘ADC chl 0 only, use Vdd-Vss as ref
OPTION_REG.7 = 1 ‘make sure PortB pull-ups are off (for now) for low power
Serout2 PORTC.7,16399, [“Start of Program”,10,13] ‘use serout2 MODE = 16399 for 150 baud with 32 KHz clock. A lucky value that works.

‘[Initialize misc variables]

For I = 1 to 5 ‘blink the LED 5 times at 1 sec period
LED = 1 ‘turn LED on
Pause 5 ‘actually pauses for ~ 0.5 sec
LED = 0 ‘turn LED off
Pause 5 ‘pause ~0.5 sec
Next I

Main: ‘main program
Gosub GetADCval
GOSUB GetHexSw
Goto Main ‘repeat loop

GetADCval:
ADCIN 0, ADCval ‘get AN0 analog value into ADCval (ADCIN will automatically turn on internal ADC function)
ADCON0 = %00000000 ‘turn off ADC after the conversion
Serout2 PORTC.7,16399,[“ADCval = “,DEC ADCval, “ “] ‘print ADCval @ 150baud
RETURN

GetHexSwBits:
OPTION_REG.7 = 0 ‘turn on PORTB pull-ups
HexSw = PORTB & %00001111 ‘read LS4 bits of PORTB
OPTION_REG.7 = 1 ‘turn off PORTB pull-ups for low power
Serout2 PORTC.7,16399,[“HexSw = “,DEC HexSw, 10, 13] ‘print HexSw with carriage-return, line-feed
RETURN

Good luck,

Mike Sinclair

MikeSinclair
- 3rd November 2015, 05:06
Correction to the below thread.

-> Use DEFINE OSC 4 instead of DEFINE OSC 3 <-

I accidently set the Editor Options in MicroCode Studio (View/Editor Options.../Highlighter) to "LowerCase All" instead of "Default". The Define options are CASE SENSITIVE (!!!) so

define osc 3

is ignored and defaults to DEFINE OSC 4

DEFINE OSC 4 sets the OCS value to 4 Mhz (in this case a fudge factor so, when combined with a 32 KHx xtal and the weird serout2 Mode value, it works for 150 baud.

IMHO, there shouldn't be a LowerCase All as an option in CodeStudio as it prohibits you from using DEFINE (uppercase) which is case sensitive! AAARRRRRG

HenrikOlsson
- 3rd November 2015, 06:16
Hi,
It's starting to feel like beating a dead horse but since this apparently STILL causes confusion we'll do it one more time:

It's what you put AFTER the define keyword, ie OSC in this case, that IS case sensitive. The keyword define can be written UPPER CASE, lower case, MixED CAsE, whatever.

So it's perfectly fine to have the Reserved Word Formatting in MicroCode Studio set to Lowercase all since only DEFINE is a reserved word and IT IS NOT case sensitive.
define osc 8 will not work, define OSC 8 will and MicroCode Studio will only change the case of the reserved word, ie define, not OSC. So, the problem was not that you had it set to Lowercase all but that you wrote osc instead of OSC.

/Henrik.

MikeSinclair
- 4th November 2015, 00:23
So sorry for the error.

I read the manual and thought I understood (ha!). I also searched the forum and couldn't find what I might have done wrong. Thanks for the correction. Yes.....still very confusing IMHO.

Mike