DEFINE OSC for 31 khz


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103

    Default DEFINE OSC for 31 khz

    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 .

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    Quote Originally Posted by gunayburak View Post
    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
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  3. #3
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    Thanks for the answer but in the datasheet of 12F683 it simply states

    Code:
    Operating Current:
    -11μA @ 32 kHz, 2.0V, typical
    Is it not true ?

  4. #4
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    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.

  5. #5
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    What is IOC ?

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    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.

  7. #7
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    Thank you Henrik you're the one after Darrel ...

  8. #8
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    Quote Originally Posted by HenrikOlsson View Post
    ...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.
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  9. #9
    Join Date
    Oct 2015
    Location
    Redmond, WA
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    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):
    Code:
    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
    Last edited by Archangel; - 3rd October 2015 at 02:50. Reason: code tags

  10. #10
    Join Date
    Oct 2015
    Location
    Redmond, WA
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    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

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    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.

  12. #12
    Join Date
    Oct 2015
    Location
    Redmond, WA
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: DEFINE OSC for 31 khz

    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

Similar Threads

  1. DEFINE OSC too limited
    By mytekcontrols in forum PBP Wish List
    Replies: 18
    Last Post: - 28th July 2015, 02:32
  2. 'DEFINE OSC 8' seems to be ignored by PBP ?
    By mr.sneezy in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 26th May 2010, 11:50
  3. Define osc 1
    By ronsimpson in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st October 2009, 06:35
  4. Define osc
    By jderson in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd July 2009, 06:05
  5. Define Osc Not Working
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd February 2005, 11:23

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts