DEFINE OSC Serout problem


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2004
    Location
    Scarborough UK
    Posts
    77

    Question DEFINE OSC Serout problem

    Hi all

    Im having a problem doing serout @ 9600 with 20mhz osc on 18f4550 (sending garbage chars)

    I have the 18f4550 set up for usb operation pll*5 (20mhz osc in) and also want to use a pin for serout.

    but even if i put DEFINE OSC 20 top of listing it sends garbage out the serout pin, BUT, if i change the DEFINE to "DEFINE OSC 12" it sends the correct chars out the pin EVEN though it has a 20mhz xtal attached ???, and of course the usb wont work with this define.

    Any idea whats going on ?

    Thx
    Reading the datasheet & understanding it are two different things.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink Not all CPU freq are available ....

    Hi, Bonxy

    the Question is ...

    Which freq do you want to run the CPU ??? ... here we just know you use a 20 Mhz external XTAL ...

    BUT which is YOUR " CPUDIV_OSCx_PLLy _1L setting ???


    note you can't run the CPU@ 20 Mhz ... using PLL and USB ( 16 or 24 Mhz only - PLL x4 or x6 ... ).
    The ONLY available CPU freq are 48, 32, 24 and 16 Mhz, when using USB

    20Mhz need using only HS oscillator ... no USB then !!!

    Soooo ... nothing strange ...

    Try 24 Mhz ... and do not forget the " DEFINE "...

    Alain
    Last edited by Acetronics2; - 9th April 2010 at 16:17.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Take a look at table 2-3 in the data sheet to see the different options.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Dec 2004
    Location
    Scarborough UK
    Posts
    77


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Bonxy

    the Question is ...

    Which freq do you want to run the CPU ??? ... here we just know you use a 20 Mhz external XTAL ...

    BUT which is YOUR " CPUDIV_OSCx_PLLy _1L setting ???


    note you can't run the CPU@ 20 Mhz ... using PLL and USB ( 16 or 24 Mhz only - PLL x4 or x6 ... ).
    The ONLY available CPU freq are 48, 32, 24 and 16 Mhz, when using USB

    20Mhz need using only HS oscillator ... no USB then !!!

    Soooo ... nothing strange ...

    Try 24 Mhz ... and do not forget the " DEFINE "...

    Alain

    Hi Alain

    I am using (and want to use) 20mhz xtal and the usb is working fine at that speed (pll x5)

    but serout will not work at that speed, but if i change speed to "define osc 12" serial works, (although it should not as osc is still 20mhz) & usb wont work.
    So it seems its one or the other ?.
    Reading the datasheet & understanding it are two different things.

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    @ __CONFIG   _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @ __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
    DEFINE OSC 48
    Should work?

    The external OSC does not matter to PBP here. The above should have the MCU running at 48MHz. That is what PBP cares about.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Dec 2004
    Location
    Scarborough UK
    Posts
    77


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by mackrackit View Post
    Code:
    @ __CONFIG   _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @ __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
    DEFINE OSC 48
    Should work?

    The external OSC does not matter to PBP here. The above should have the MCU running at 48MHz. That is what PBP cares about.

    Hey mackrackit

    The DEFINE OSC 48 works!, although I dont understand why (the crystal is still 20mhz), but who cares, both usb and serout are working now.

    Thanks dude
    Reading the datasheet & understanding it are two different things.

  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default configs, configs

    Quote Originally Posted by Bonxy View Post
    The DEFINE OSC 48 works!, although I dont understand why (the crystal is still 20mhz), but who cares, both usb and serout are working now.
    It is because you have to have the OSC configuration settings correct. And with so many options with these PIC18 chips, you have to read the data sheet a lot of times to get them right. (At least that is speaking for myself!) If you have (almost) any one of them set incorrectly, you will be running at the wrong speed, or worse, not run at all. But it does give you great flexibility.

    Here are your config options just for the oscillator on a pic18f4550:

    Code:
    ;----- CONFIG1L Options --------------------------------------------------
    _PLLDIV_1_1L         EQU  H'F8'    ; No prescale (4 MHz oscillator input drives PLL directly)
    _PLLDIV_2_1L         EQU  H'F9'    ; Divide by 2 (8 MHz oscillator input)
    _PLLDIV_3_1L         EQU  H'FA'    ; Divide by 3 (12 MHz oscillator input)
    _PLLDIV_4_1L         EQU  H'FB'    ; Divide by 4 (16 MHz oscillator input)
    _PLLDIV_5_1L         EQU  H'FC'    ; Divide by 5 (20 MHz oscillator input)
    _PLLDIV_6_1L         EQU  H'FD'    ; Divide by 6 (24 MHz oscillator input)
    _PLLDIV_10_1L        EQU  H'FE'    ; Divide by 10 (40 MHz oscillator input)
    _PLLDIV_12_1L        EQU  H'FF'    ; Divide by 12 (48 MHz oscillator input)
    
    _CPUDIV_OSC1_PLL2_1L EQU  H'E7'    ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
    _CPUDIV_OSC2_PLL3_1L EQU  H'EF'    ; [OSC1/OSC2 Src: /2][96 MHz PLL Src: /3]
    _CPUDIV_OSC3_PLL4_1L EQU  H'F7'    ; [OSC1/OSC2 Src: /3][96 MHz PLL Src: /4]
    _CPUDIV_OSC4_PLL6_1L EQU  H'FF'    ; [OSC1/OSC2 Src: /4][96 MHz PLL Src: /6]
    
    _USBDIV_1_1L         EQU  H'DF'    ; USB clock source comes directly from the primary oscillator block with no postscale
    _USBDIV_2_1L         EQU  H'FF'    ; USB clock source comes from the 96 MHz PLL divided by 2
    
    ;----- CONFIG1H Options --------------------------------------------------
    _FOSC_XT_XT_1H       EQU  H'F0'    ; XT oscillator, XT used by USB
    _FOSC_XTPLL_XT_1H    EQU  H'F2'    ; XT oscillator, PLL enabled, XT used by USB
    _FOSC_ECIO_EC_1H     EQU  H'F4'    ; External clock, port function on RA6, EC used by USB
    _FOSC_EC_EC_1H       EQU  H'F5'    ; External clock, CLKOUT on RA6, EC used by USB
    _FOSC_ECPLLIO_EC_1H  EQU  H'F6'    ; External clock, PLL enabled, port function on RA6, EC used by USB
    _FOSC_ECPLL_EC_1H    EQU  H'F7'    ; External clock, PLL enabled, CLKOUT on RA6, EC used by USB
    _FOSC_INTOSCIO_EC_1H EQU  H'F8'    ; Internal oscillator, port function on RA6, EC used by USB
    _FOSC_INTOSC_EC_1H   EQU  H'F9'    ; Internal oscillator, CLKOUT on RA6, EC used by USB
    _FOSC_INTOSC_XT_1H   EQU  H'FA'    ; Internal oscillator, XT used by USB
    _FOSC_INTOSC_HS_1H   EQU  H'FB'    ; Internal oscillator, HS used by USB
    _FOSC_HS_1H          EQU  H'FC'    ; HS oscillator, HS used by USB
    _FOSC_HSPLL_HS_1H    EQU  H'FE'    ; HS oscillator, PLL enabled, HS used by USB
    
    _FCMEN_OFF_1H        EQU  H'BF'    ; Fail-Safe Clock Monitor disabled
    _FCMEN_ON_1H         EQU  H'FF'    ; Fail-Safe Clock Monitor enabled
    
    _IESO_OFF_1H         EQU  H'7F'    ; Oscillator Switchover mode disabled
    _IESO_ON_1H          EQU  H'FF'    ; Oscillator Switchover mode enabled
    Walter

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


    Did you find this post helpful? Yes | No

    Default

    And...
    The OSC is not running the chip, it is running the PLL, That is why the 48MHz works.
    With the correct config settings you can run at 48MHz with a 4MHz external.

    Another cool thing is the different voltages this allows. Normally you have to use 5 volts to run a chip at 20MHz, with a 4MHz and the correct configs you can run this chip with 2 volts at 48MHz. For USB though you will not want to go lower than 3.3 volts, so that way the whole system can run at "low" voltages at "high" speeds. Really nice when using things like SD cards, some RTC, and other things that only run on ~3 volts.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by Acetronics View Post
    Hi, Bonxy

    Not all CPU freq are available ....
    ...
    The ONLY available CPU freq are 48, 32, 24 and 16 Mhz, when using USB

    Try 24 Mhz ... and do not forget the " DEFINE "...

    Alain
    You had the answer @ post 2 ...

    But why do I loose my youth here ??? I really wonder why ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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