DEFINE OSC for 31 khz


Results 1 to 12 of 12

Threaded View

  1. #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

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 : 0

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