20MHZ External Oscillator Settings


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    I do not use crystals so I can not comment on that.
    Here are the configs to run at 48 MHz with a 4 MHz resonator.
    Code:
    DEFINE OSC 48
        @ __CONFIG   _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
        @ __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
        @ __CONFIG   _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
        @ __CONFIG   _CONFIG2L, _PWRT_ON_2L & _VREGEN_ON_2L
        @ __CONFIG   _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
        @ __CONFIG   _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Apr 2009
    Location
    Boise, Id
    Posts
    44


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    Thanks for the settings, that allowed me to follow the table in the data sheet and make sence of the settings in the .inc files. This is what I have figured out so far:

    I can use DEFINE OSC for 4, 16 and 20Mhz. Anything else I get a compile error, " Integer not previously defined.."

    So I used the old reliable 4Mhz XTAL and configured for 16Mhz CPU instead of the 48Mhz in Mackrackit's reply. That worked, but then my DT timer was running at about 1/4 speed. If I put Define OSC back to 4, my timing was fixed.

    Did a few more tests and found that I could set the configs to 48, 32,24 or16Mhz, the number of A/D conversions seems to be the same. I always seem to need the Define OSC 4.


    Next, was to get the 20Mhz XTAL working, using what I learned from the last 2 hours of testing, I was sure I could plug the 20Mhz in and be set to get back to coding. Nope-not that lucky!

    After more time I got it working, then I connected the scope and it stopped working. Seems that connecting the scope to the 20Mhz signal destroys it, don't know if its the extra capacitance from the probes?

    The tool that was supposed to help me figure out why I wasn't resonating was causing the issue...go figure.

    I also timed the execution speed (number of A/D conversions per second) for different cpu speeds, they all seem the same ( 48, 32 24 and 16Mhz). I left the DEFINE OSC 20 and the DT timer looks spot on.

    Seems that the (CPUDIV1:CPUDIV0) must only affect the USB speed? At least for this model of PIC?

    Here is what I ended up with:

    Code:
    __CONFIG  _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
     __CONFIG  _CONFIG1H, _FOSC_HSPLL_HS_1H
    And it's working, although I'm still confused on the execution speed not changing when changing the (CPUDIV1:CPUDIV0) settings?

    Thanks for your help, let me know if you have any advice regarding my current confusion.

    Shane

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    I am not sure if measuring the ADC time is the best test. There are other things that effect the ADC speed.

    You might try setting up an LED to blink at 1 Hz then test.

    The settings are for the MCU speed, not just USB.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    I guess that no one reads my posts. I have mentioned numerous time that you can do a superb job of measuring your PICS actual speed by
    using a routine such as:

    DEFINE OSC X

    LEDON

    For X = 1 to 60
    PAUSE 60000
    Next X

    LED OFF

    Of course, you don't have to time for a full hour, but the accuracy gets better the longer you wait.
    If have

    If you use DEFINE OSC 20 and the LED stays on for 31 minutes, you are actually running at

    (60/31) * 20MHz = 38.7096Mhz.

    Just make sure you don't have interrupts running when you do the timing.
    Charles Linquist

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    charles I read them with great intrest!!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Apr 2009
    Location
    Boise, Id
    Posts
    44


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    Thanks for the speed test, I'll give it a try and post my results.

  7. #7
    Join Date
    Apr 2009
    Location
    Boise, Id
    Posts
    44


    Did you find this post helpful? Yes | No

    Default Re: 20MHZ External Oscillator Settings

    I tried the speed test to check code execution time at 24Mhz and 48Mhz. I left the DEFINE OSC 20 for both tests. I used pause loops like Charles suggested, and used 10 minute long tests. I know longer would be better, but I think 10 minutes should show any difference. Both times the LED was on for 10 minutes, the best I could measure with a clock second hand.


    I only changed the _CONFIG1L setting "_CPUDIV_OSC1_PLL2_1L" and _CPUDIV_OSC3_PLL4_1L between the tests. So I'm still scratching my head, seems if the CPU was running at 48Mhz but my define is at 20Mhz, it should have taken 4.1 minutes. So it seems the clock speed for code execution is derived directly from the external XTAL?

    My A/D sampling frequency is now fast enough for my needs, as long as I keep the rest of my code in check I should be OK. I'd still like to understand why this is happening (or not happening)???
    Thanks
    Shane

    Here is the code I used:

    Code:
                       '_CPUDIV_OSC1_PLL2_1L '48 Mhz
                        '_CPUDIV_OSC3_PLL4_1L '24 Mhz
                        
    DEFINE LOADER_USED 1
     asm
              __CONFIG  _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
              __CONFIG  _CONFIG1H, _FOSC_HSPLL_HS_1H
              __CONFIG  _CONFIG2L ,_BOR_ON_2L & _BORV_2_2L
         
            
        endasm
        
     DEFINE OSC 20
     
    X VAR  Byte    
      
    TRISC.0 = 0          
              
    Portc.0 = 0
     
    For X = 1 to 10   'Turn LED on for 10 min
     PAUSE 60000
     Next X
     
     Start:
     Portc.0 = 1        'Start Toggling LED
     For X = 1 to 10
     PAUSE 100
     Next X
     Portc.0 = 0
     For X=1 to 10
    Pause 100
    Next X
    Goto START

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