Menu

Oscillator Stuff

Help
Moto Geek
2018-06-03
2018-06-04
  • Moto Geek

    Moto Geek - 2018-06-03

    I'm working with a new to me pic, 18f23k22 and I'm trying to understand the OSC settings and how they corolate to the data sheet. The data sheet says...

    The primary clock module can be configured to provide
    one of six clock sources as the primary clock.
    1. RC External Resistor/Capacitor
    2. LP Low-Power Crystal
    3. XT Crystal/Resonator
    4. INTOSC Internal Oscillator
    5. HS High-Speed Crystal/Resonator
    6. EC External Clock
    The HS and EC oscillator circuits can be optimized for
    power consumption and oscillator speed using settings
    in FOSC<3:0>. Additional FOSC<3:0> selections
    enable RA6 to be used as I/O or CLKO (FOSC/4) for
    RC, EC and INTOSC Oscillator modes.
    Primary Clock modes are selectable by the
    FOSC<3:0> bits of the CONFIG1H Configuration
    register. The primary clock operation is further defined
    by these Configuration and register bits:
    1. PRICLKEN (CONFIG1H<5>)
    2. PRISD (OSCCON2<2>)
    3. PLLCFG (CONFIG1H<4>)
    4. PLLEN (OSCTUNE<6>)
    5. HFOFST (CONFIG3H<3>)
    6. IRCF<2:0> (OSCCON<6:4>)
    7. MFIOSEL (OSCCON2<4>)
    8. INTSRC (OSCTUNE<7>)
    The HFINTOSC, MFINTOSC and LFINTOSC are
    factory calibrated high, medium and low-frequency
    oscillators, respectively, which are used as the internal
    clock sources.
    

    The chip data file says...

    [ConfigOps]
    OSC=LP,XT,HSHP,HSMP,ECHP,ECHPIO6,RC,RCIO6,INTIO67,INTIO7,ECMP,ECMPIO6,ECLP,ECLPIO6
    PLLCFG=OFF,ON

    How does one figure out how to set the OSC settings? I don't see how the data sheet and the chip data make sense with each other and how to dicipher the OSC settings against the data sheet. For instance, if I'm using an external crystal, which of the above settings would I use? What do thingss like INTIO7 mean, and when would I set that? What does HSHP mean? I am sure to a seasoned pro this makes sense, and I would like to know how to figure out when to us what. Can anyone stear me in the right direction on this please. I am super willing to learn, just need to know where to start.

    Thanks!!!!!

     
    • stan cartwright

      stan cartwright - 2018-06-03

      It's all too hard for me to, microchip info, so I don't bother-
      :#chip 18f25k22 ,64 works for me.

       
  • Anobium

    Anobium - 2018-06-03

    Start here - http://microchipdeveloper.com/8bit:ec

    The design intent of Great Cow BASIC is set the internal oscillator for you (we do not always get this correct... so, let us know) but you have a very valid question and the Microchip Developer Help does help.

    Maybe... we should develop a tool for this. As this is the second time in one day I have discussed. :-)

     
    • stan cartwright

      stan cartwright - 2018-06-03

      setting up pics can be complicated-i2c finder to terminal demos/i2csolutions/
      ~~~
      #chip 16F1938, 32
      #config Osc = intOSC, MCLRE_ON, PLLEN_ON, VCAPEN_OFF
      ;

      chip 18f45k50, 16

      #config OSC = INTOSCCLKO
      ;

      chip 12F1840, 32

      #config Osc = intOSC, MCLRE_ON, PLLEN_ON
      ;
      #chip mega328p,16
      'nuff said

      ~~~

       
      • Anobium

        Anobium - 2018-06-04

        That is more down the quality of the demos than the issue of the clock parameters in the configuration.

        The design intent is to NOT require the use to specify any parameters for the internal clock. If the demo has the OSC specified it would good that as these demos (with OSC specified) are identified they are quickly tested with the OSC removed and then GitHub is updated. There may be times where we do specify #config to set other parameters or where the part does not have an internal oscillator (these demos should be updated to state very clearly that the #config is required to setup an external oscillator).

        Those shown above should be as follows - to improve the quality. Each demo is setting up the part differnently to meet specific requirements,

        'default to internal osc at 32mhz
        #chip 16F1938
        'set master clear on and turn vcap off.
        #config MCLRE_ON, VCAPEN_OFF
        
        'use 16mhz clock speed rather than the max of 48mhz
        #chip 18f45k50, 16
        'set the internal osc and enable the clock out on the clock port.
        #config OSC = INTOSCCLKO
        
        'default to the internal osc at 32 mhz
        #chip 12F1840
        'set master clear on
        #config MCLRE_ON
        
        'default to the internal osc at 16 mhz which is set by the fuses during bootloader programming.  Restated frequency to ensure clarity.
        #chip mega328p,16
        
         
        • kent_twt4

          kent_twt4 - 2018-06-04

          Bit of a dilemma there. Always nice to have the ChipMHz viewable, even if it is the default.

           
          • Anobium

            Anobium - 2018-06-04

            We could use that as the standard going forward. To make things clearer.

            :-)

             
          • Chris Roper

            Chris Roper - 2018-06-04

            Why?

            I think that by using an internal oscillator, rather than trying to get an external Xtal oscillating on a breadboard, has attracted far more people to microcontrollers. Now GCBASIC takes that one step further by hiding the complexity of setting up the PLL.

            Most of the time you don't need to know what your clock speed is as the compiler has already adjusted your delays, and any peripheral timing registers, to to suite. But if you do need it it is available as a constant in your program anyway.

            Allowing the option to specify the Clock Speed is good but enforcing it is a step backwards.

            It will put off a lot of potential beginners who will now have to research acceptable clock speeds and as such be exposed the the Datasheet, before even attempting to flashing an LED.

            Let it always default to the maximum, as it does now, and let the user come back to the complexity of timing when they have more experience and a valid need to use other than the default.

            Just because we had to learn it the hard way does not justify us forcing others to do so.

             

            Last edit: Chris Roper 2018-06-04
            • kent_twt4

              kent_twt4 - 2018-06-04

              Because of code review? Can one remember default clocks, if it matters for serial comms, or device libraries? Or maybe it is just coding style or personal preference, I am good with that.

               
  • Moto Geek

    Moto Geek - 2018-06-04

    Maybe it would be a cool thing to have tool like the great PPS tool dedicated to the setting of OSC. Like enter the chip, then internal or external OSC., what baud rate you are trying to accomplish with what amount of allowable error, etc. I could only image what a task this would be, but I felt same way when saw the PPS tool and I said to myself, what a wonderful world... Its really amazing what can be done with GCB and the incredible support system (people).

     
  • stan cartwright

    stan cartwright - 2018-06-04

    When I use a 18f25k22 I knew from picaxe it's 64Mhz so I used that as no 18f25k22 examples at the time.
    With picaxe..beginners was mentioned...timed functions like pulsout/in,servo,pwm is based on 32mhz clock so using 28x2 at 64mhz means timing is half value...if my memory is right.

    I presume that gcb timed function work the same at different clock freq.
    The only time I changed the clock to lower was to get low pwm frequency.
    Why did my 20 year ago pic boards have a xtal or 3pin resonator?

    Quote Chris Roper
    "It will put off a lot of potential beginners who will now have to research acceptable clock speeds and as such be exposed the the Datasheet, before even attempting to flashing an LED."
    I think you can flash a led with xpress board without using pps tool...not much else though.
    Yes,pps tool helps to implement microchip data info but it's as technical as setting up osc on pics.
    Recommending a new user to use express board - not. And you run out of memory.
    The more gcb users the better. I don't understand frustrated picaxe users not switching to gcb ...It's too complicated was one response.
    When I flashed my first uno program with gcb I was hooked. That was 18 months ago.
    Now gcb has more features to allow more pics and use their new features but it's not for a beginner like me.
    Who would new gcb users be
    c++ prgrammers who used mplab or avr system?
    people who think asm is not fun?
    arduino users who can't do c++?
    frustrated picaxe user?
    someone who can't crack mikrobasic?
    rapsberry pi user who can't do python for gpio?
    someone who saw a youtube video?
    ;
    Please keep it simple for beginners. For beginners it's a past time/hobby...and hobbies are supposed to be fun.
    Wiring up a glcd and seeing it work so easy first time was so encouraging.
    ;
    When I first used the forum it seemed like lots of clever people discussing complicated stuff and I thought out of my league. What was others feeling first visit?
    just feedback--- my recommendation is include every device there's an arduino/rpi lib for.
    one thing arduino has the edge.
    the requests for floats is maybe people wanting to convert c++.

    .

     

Log in to post a comment.