Menu

Oscillator problems on 16F18346

Help
2019-10-15
2019-10-16
  • David Stephenson

    I have made a LED clock and it works nicely with a 16F1509. I am trying to make another using a 16F18346 and I can't seem to get the chip to run off the 32768 Hz crystal oscillator.
    Here's the relevant parts of the two programs

    #chip 16lf1509, .032768
    #config fosc_lp, wdte=off,boren=off, mclre_off
    t1con=b'00110001'
    osccon=b'00000000'
    
    #chip 16f18346, .032768
    #config fextosc=lp,boren=off, mclre_off, WDTE=off, CLKOUTEN_OFF, CP_OFF, WRT_OFF
    t1con=b'00110001'
    OSCEN.7=1
    

    So the top one works and the bottom one ticks off 2hours in 15 seconds.

     
  • Jim giordano

    Jim giordano - 2019-10-15

    For those chips, using a 32k clock crystal, here's what I've been using-

    #chip 16F18324,32
    #config RSTOSC=HFINT32, MCLRE=OFF, FEXTOSC=OFF , CLKOUTEN=OFF
    
    DIR PORTA.4 IN  ' 32k crystal
    DIR PORTA.5 IN  ' 32k crystal
    
    InitTimer1 sosc,0 ' 32768 crystal time keeper
    
    On Interrupt Timer1Overflow Call CheckClock
    
    etc.
    
     
  • David Stephenson

    Thanks for the reply Jim. I am actually running the whole thing at 32kHz (including the processor). Because the whole thing is running on batteries I am trying to keep the current down. The LED multiplexing is fine at this clock rate and it keeps the current low.
    I just had a thought that it may be Timer1 that is the problem, but I could see no obvious differences in the datasheets between the two chips.
    I will attach the full program (the one that works for the 16F1509).

     
  • Jim giordano

    Jim giordano - 2019-10-16

    Thanks for the program, I'm learning new stuff from your code. I'm going to wire it up a play :)

    Hopefully someone more knowledgeble will answer your question. (Evan???)

     
  • Anobium

    Anobium - 2019-10-16

    Check the demos. There are examples for the 156. And, there a long thread discussing the issues with the new chip architecture and these types of clocks.

     
  • David Stephenson

    Can you point me to the relevant demos. Most seem to be using RTCs and running the chip at 32 MHz.
    Just to summarize I am trying to get the processor to run at 32768Hz using a clock crystal. The Timer1 is taking this divided by 4 (Fosc/4) then a 8:1 prescaler. This should cause the timer to roll-over every 64 seconds and generate an interrupt (setting TMR1H to 00010000 reduces this to 60 seconds).
    It works great on a 1509 (its been running for almost a year on 2xAAA), but the oscillator settings on the 18324 don't seem to work in the same way.

     
  • David Stephenson

    Slight progress I have set OSCCON1 bits to external OSC and now timer1 overflows in 45 seconds (should be 60) then the program stalls.
    ~~~~~~

    config fextosc=lp,rstosc=ext1x, mclre_off, WDTE=off, CLKOUTEN_OFF

    'extosc=lp on reset use fextosc for osc
    t1con=b'00110001'
    osccon1=b'01110000' 'select fextosc
    oscen.7=1 'enable extosc
    ~~~~~~~

     

    Last edit: David Stephenson 2019-10-16
  • David Stephenson

    The configuration I posted above does in fact work. The stalling was due to a light sensor not being fitted (the clock is intended for nightime use so the display switches off when it is too light to see).
    So the key is to set osccon1.
    Strangely the first "minute" is still 45 sec, but subsequent minutes are all exactly 60 secs.
    This does not matter as the time will have to be set after power-up, but it is none less curious anomaly.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.