Pic16f18857 clock setup


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2010
    Posts
    19

    Default Pic16f18857 clock setup

    I'm hitting my head against the wall now. I can't seem to figure out this new chip. I just want to get it up and running with the internal oscillator at 32Mhz. When I blink an led with a 1 sec interval it's way to fast. If anyone can give me a walk through that would be great.

  2. #2
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Pic16f18857 clock setup

    If it is blinking too fast, that would point to your clock speed being too high which is extremely unlikely. Are you absolutely sure your code is correct? Perhaps you should post your blink code.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Pic16f18857 clock setup

    Yes, it's not very likely that the PIC is running faster than 32MHz.
    There's two parts to it. Get the PIC to actually run at the desired frequency and inform the compiler what that speed is so it can get its timing calculations correct. If you don't tell the compiler that you're running the PIC at 32MHz it defaults to 4MHz and your PAUSE 1000 will in effect become a PAUSE 125.

    /Henrik.

  4. #4
    Join Date
    Jan 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Pic16f18857 clock setup

    I was following the data sheet and it must be set for 32Mhz because when I used a pause of 1000 and hooked up the oscilloscope to it I was getting 125ms. I used the define 32 in PBP but it doesn't seem to work. I've never used a chip like this, the oscon register is different. I'll try again tomorrow.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Pic16f18857 clock setup

    Code:
    define OSC 32
    OSC is case sensitive, the rest is not.

    /Henrik.

  6. #6
    Join Date
    Jan 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Pic16f18857 clock setup

    I've tried so many thing now with no luck. Here is the config setup in 16f18857.inc file. A pause 1000 led on & off program is giving me 125ms on the scope.
    #CONFIG
    __config _CONFIG1, _FEXTOSC_HS & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
    __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
    __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
    __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
    __config _CONFIG5, _CP_OFF & _CPD_OFF

    #ENDCONFIG

    It's my understanding that on reset the internal clock will be running at 32Mhz with these fuses set. I've tried simply setting Define OSC 32, and adding OSCFRQ = %00000110.
    There are three OSCCON registers and OSCEN register. I'm off in the weeds and don't know which way to go at this point.

    I did notice that when I program the chip with meProg that the configuration HFINTOSC WITH 2X PLL was set instead of HFINTOSC like the fuse is set for. I changed that and my blink program goes from 125ms to 2sec. For what it's worth. Any help would be appreciated thanks.

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Pic16f18857 clock setup

    Why is it so hard to post the code - as in everything? Not just the code, not just the config, not bits, pieces and snippets for us to piece together and extract information from. You think it's hard at your end, how do you think it is for us?

    A pause 1000 led on & off program is giving me 125ms on the scope.
    That tells me that the PIC is actually running 8 times faster than the compiler thinks it is. You tell it to pause for 1000ms but in reallity it only pauses for 125ms, 1000/125=8. As have been said before it's not very likely that the PIC is running faster than 32MHz (or in this case 8 times faster = 256MHz) it's much more likely that it IS actually running at 32MHz but you haven't properly told the compiler that so it thinks it's running at 4MHz (32 / 4 = 8).

    I don't have that chip here but if you post the code, within code tags, which is giving you the 125ms pause when it should be 1000ms I'll see if I can spot the problem.

    /Henrik.

  8. #8
    Join Date
    Jan 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Pic16f18857 clock setup

    Sorry HenrikOlsson for the frustration. I figured it out just now, it wasn't the code. It was my anti-virus software, I had ransom ware protection on. This somehow allowed some of the pic to be programmed but would act screwy. I checked off ransom ware protection and reprogrammed the chip same code, everything works as it should now. Thank you for your help.

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Pic16f18857 clock setup

    Wow, that's the first time I've heard of anything like that. An antivirus program on a PC messing up code on a PIC.
    I'm glad you figured that out because I certainly would not have done it from where I'm sitting :-)

    /Henrik.

  10. #10
    Join Date
    Jan 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Pic16f18857 clock setup

    I don't know if I would have figured it out without your last post wanting all my code. I just updated to PBP 3.1, on my system I have to disable ransom ware protection to install programs. I started my program file in PBP when it was still off, then I turned it back on.

    To post code for you I started a new file with just the clock info TRIS registers and simple led loop. This time though it would compile but not bring up the programmer. I tried opening the hex manually but the programmer said it couldn't find the file. Hmmmm If it couldn't find the new file something is blocking it was my thinking, that's when I remembered the antivirus software. It lets somethings pass and others not.

    So we'll just call this a collaborative effort

Similar Threads

  1. external clock / internal clock
    By grounded in forum General
    Replies: 4
    Last Post: - 31st May 2008, 18:44
  2. Use Button For setup
    By tump in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 21st November 2007, 20:43
  3. LCD setup
    By ruijc in forum General
    Replies: 11
    Last Post: - 19th November 2007, 10:04
  4. pic12f683 setup
    By erice1984 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th July 2007, 12:48
  5. How to setup Bootloader
    By koossa in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th January 2006, 20:52

Members who have read this thread : 2

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