PIC18F4620 frequency

Discussion in 'Embedded Systems and Microcontrollers' started by sakishrist, Dec 4, 2009.

  1. sakishrist

    Thread Starter New Member

    Dec 4, 2009
    26
    0
    Hello,

    I have a problem setting the frequency of the 18F4620 PIC. In the datasheet it's written that if I do not have a crystal I can select one of the following frequencies: 8 MHz,4 MHz,2 MHz,1 MHz,500 kHz,125 kHz,250 kHz,31 kHz. The problem is: how do I choose one? I have set the OSC to internal but anything else I try to modify (e.g.OSCCON) I get an error from mplab that it can't recognize it.

    Thanks
     
  2. eng1ne

    Member

    Dec 4, 2009
    97
    3
    Post the line of code you are using to define the OSCCON register; not really sure what you are asking.

    If you haven't already, look at page 30 of the datasheet, and alter bits 6-4 depending on your desired frequency.
     
  3. sakishrist

    Thread Starter New Member

    Dec 4, 2009
    26
    0
    Thanks for the reply. That is the page I'm on. I'm setting theese values in the code:
    Code ( (Unknown Language)):
    1. #pragma config PWRT = OFF, WDT = OFF, LVP = OFF
    The rest of them are set from the "Configuration Bits" windows (shown in the attachment). So how do I set the OSCCON bits? When I attempt to I get a weird error message: "Error [1224] configuration setting 'OSCCON' not recognized". So how should I change the Frequency of the PIC?

    Thanks :)
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Configuration bits are written into the PIC at programming time and can't be changed.
    OSCCON is just an ordinary register that you set from within the program.
    I don't understand C but in ASM it would be
    movlw b'00000000' ;(or whatever bits you want to set)
    movwf OSCCON
     
  5. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    OSCCON = 0x72;

    will set it to 8MHz. Change the 7 to 0-7
     
  6. sakishrist

    Thread Starter New Member

    Dec 4, 2009
    26
    0
    Aha! I see what my mistake was. Thanks :)
     
Loading...