Hot!16F88 cannot set internal oscillator frequency beyond 31.25kHz

Page: 12 > Showing page 1 of 2
Author
M84AB1
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2013/05/15 06:23:43
  • Location: 0
  • Status: offline
2018/12/25 21:17:57 (permalink)
0

16F88 cannot set internal oscillator frequency beyond 31.25kHz

Hi all,
 
I have been a long time reader but first time poster. As the title suggests, I am not able to get the internal oscillator to work at any frequency beyond 31.25kHz. The below configuration bits is what I am using in order to get the 16F88 to oscillate internally at 4Mhz.
 

#CONFIG

  __config _CONFIG1, _INTRC_IO & _WDT_OFF & _PWRTE_ON & _MCLR_OFF & _LVP_OFF & _CP_OFF
 
#ENDCONFIG
 
OSCCON = %01101110    '4Mhz - does not work
OSCCON = %00001110    '31.25kHz - does work
 

 
I have tried to get other frequencies to work but without luck. What am I doing wrong? Or is perhaps the MCU faulty?
 
Also, worthwhile mentioning is that the MCU works perfectly fine with an external clock eg. 4Mhz, 8Mhz...etc.
 
I am also using PICBASIC PRO, not C to program.
 
 
post edited by M84AB1 - 2018/12/26 05:58:00
#1

26 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9236
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/25 22:28:43 (permalink)
    +1 (1)
    HOW are you determining that it does not work?
     
    #2
    M84AB1
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2013/05/15 06:23:43
    • Location: 0
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/25 22:45:08 (permalink)
    0
    Two flashing LEDs. Sorry I should have pasted the rest of the code
     

    CMCON  = 7 'COMPARATORS OFF
        
    TRISA = %00000000 'ALL OUTPUTS
    TRISB = %00000000 'ALL OUTPUTS

    PORTA = 0 'PORTA LOW
        
    MAIN:
        
    PORTA.1 = 0
    PORTA.0 = 1  
     
    Pause 1000
        
    PORTA.0 = 0
    PORTA.1 = 1

    Pause 1000

    GoTo MAIN
        
    END

     
    When I configure OSCCON for 31.25kHz the LEDs flash. When I configure OSCCON for any other frequency the LEDs don't flash. The microcontroller is simply doing nothing. I am checking this on my oscilloscope too.
    post edited by M84AB1 - 2018/12/26 05:59:45
    #3
    qhb
    Superb Member
    • Total Posts : 9236
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/25 23:49:53 (permalink)
    +1 (1)
    You're probably suffering from RMW (read-modify-write) effects at higher clock speeds.
    You should also be writing zero to the ANSEL register.
    Try adding a Pause between every write to PORTA.
    e.g.
    MAIN:
        
    PORTA.1 = 0
    Pause 10
    PORTA.0 = 1  
     
    Pause 1000
        
    PORTA.0 = 0
    Pause 10
    PORTA.1 = 1

    Pause 1000
    GoTo MAIN

    Or, write the entire value to PORTA rather than individual bits.
    MAIN:
    PORTA = %00000001
    Pause 1000
    PORTA = %00000010
    Pause 1000
    GoTo MAIN

     
    #4
    AMPS
    Super Member
    • Total Posts : 347
    • Reward points : 0
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/26 00:34:33 (permalink)
    -2 (2)
    Can you test sample code. if u have logical analzer check output waveform pulse width.

    #include <pic.h>
    #include <htc.h>
    #define LED RB2
    __CONFIG(WDTE_OFF & PWRTE_OFF & CP_OFF & BOREN_OFF & LVP_OFF & CPD_OFF & DEBUG_OFF);
    void Timer0_Intialize();
    static int count=0;
     
    void interrupt isr(void)
    {
    if(T0IF==1)
    {
    T0IF=0;
    TMR0=194;
    count=count+1;
    if(count>5)
    {
    LED=!LED;
    count=0;

    }

    }
    }
    void main()
    {
    LED=1;
    OSCCON=0b01100000;
    PORTA=0X00;
    TRISA=0X00;
    PORTB=0X00;
    TRISB=0X00;
    ANSEL=0X00;
    ADCON0=0X00;
    Timer0_Intialize();
    GIE=1;
    PEIE=1;
    T0IE=1;
    while(1)
    {

    }
     
    }
     
    void Timer0_Intialize()
    {
    INTCON=0X00;
    OPTION_REG=0b00000011;
    TMR0=194;
    }
     


    Amps
    *.*.*.*.*.*.*.*.*.*.*.*.*
    #5
    qhb
    Superb Member
    • Total Posts : 9236
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/26 00:36:41 (permalink)
    +7 (7)
    Why post a block of C code when the OP has already stated they are working with PICBASIC PRO?
    Please stop interfering in topics that are already getting good answers.
     
    #6
    M84AB1
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2013/05/15 06:23:43
    • Location: 0
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/26 05:52:01 (permalink)
    0
    qhb
    You're probably suffering from RMW (read-modify-write) effects at higher clock speeds.
    You should also be writing zero to the ANSEL register.
    Try adding a Pause between every write to PORTA.
    e.g.
    MAIN:
        
    PORTA.1 = 0
     
    Pause 10
    PORTA.0 = 1  
     
    Pause 1000
        
    PORTA.0 = 0
     
    Pause 10
    PORTA.1 = 1

    Pause 1000
    GoTo MAIN

    Or, write the entire value to PORTA rather than individual bits.
    MAIN:
    PORTA = %00000001
     
    Pause 1000
    PORTA = %00000010
     
    Pause 1000
    GoTo MAIN

     



    Thanks for that qhb, I have tried both suggestions but without much luck. Wondering if there is a way to check whether or not the PIC is perhaps faulty? I don't have another one I could use to test. I guess one way to check if my 16F88 is in working order would be for somebody else to compile my code (below) and try and see if it works. If it does work, upload the HEX file so that I can then flash my PIC and see what we get.
     

     
    #CONFIG
     
      __config _CONFIG1, _INTRC_IO & _WDT_OFF & _PWRTE_ON & _MCLR_OFF & _LVP_OFF & _CP_OFF
     
    #ENDCONFIG

     '   OSCCON = %00001110            '31.25 khz
       OSCCON = %01101110              '4 mhz
     
        pause 1
        ANSEL  = 0 'ALL DIGITAL
        ADCON0 = 0
        ADCON1 = 0
        CMCON  = 7 'COMPARATORS OFF
       
        TRISA = %00000000 'ALL OUTPUTS
        TRISB = %00000000 'ALL OUTPUTS

        PORTA = 0 'PORTA LOW

        Pause 1 'SETTLE DOWN
       
        MAIN:
        
        PORTA = %00000001
        Pause 1000
        PORTA = %00000010
        Pause 1000

        GoTo MAIN
        
        END
     

    post edited by M84AB1 - 2018/12/26 06:01:26
    #7
    qhb
    Superb Member
    • Total Posts : 9236
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/26 14:11:22 (permalink)
    0
    Sorry, I don't have PICBASIC PRO or a PIC16F88 handy.
     
    #8
    cobusve
    Super Member
    • Total Posts : 456
    • Reward points : 0
    • Joined: 2012/04/02 16:15:40
    • Location: Chandler
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/26 15:58:03 (permalink)
    +1 (1)
    It would be strange if the PIC was faulty but it worked at some frequencies.
     
    It does look like you have it running from 31kHz instead of the 8MHz internal clock
     
    Is it possible for you to try setting
    OSCCON = %01111100
    And also making sure the configuration bits in config word 1 - CONFIG1 = 0xFFB8? 
     
     
    #9
    M84AB1
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2013/05/15 06:23:43
    • Location: 0
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/28 20:09:15 (permalink)
    0
    cobusve
    Is it possible for you to try setting
    OSCCON = %01111100




    I have tried that but still nothing. I managed to get my hands on a new 16F88 but still no luck. As a matter of fact I have tried every single OSCCON 4Mhz combination and nothing works except for 31.25kHz.

       osccon = %01101100             
       osccon = %01101101              
       osccon = %01101110              
       osccon = %01101111              
     
       osccon = %01101000              
       osccon = %01101001              
       osccon = %01101010              
       osccon = %01101011              
     
       osccon = %01100100              
       osccon = %01100101              
       osccon = %01100110              
       osccon = %01100111              
     
       osccon = %01100000              
       osccon = %01100001              
       osccon = %01100010              
       osccon = %01100011

     
    On another thread I discovered that if no config bits are set and the OSCCON register is not configured the microcontroller will default to 31.25kHz which is exactly what I am seeing. At this point I am out of ideas and am not able to get the 16F88 to oscillate at anything other than 31.25kHz.
     
    I have tried using the 18F1330 and it works flawlessly. Configuring the internal oscillator is no problem at all.
    #10
    qhb
    Superb Member
    • Total Posts : 9236
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/28 21:24:37 (permalink)
    0
    I'm running out of ideas.
    Few of the people answering will be using PICBASIC PRO.
    How about trying a hex file from this C code

    // PIC16F88 Configuration Bit Settings

    // 'C' source line config statements

    // CONFIG1
    #pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin)
    #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
    #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
    #pragma config MCLRE = OFF      // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital I/O, MCLR internally tied to VDD)
    #pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
    #pragma config LVP = OFF        // Low-Voltage Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
    #pragma config CPD = OFF        // Data EE Memory Code Protection bit (Code protection off)
    #pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off)
    #pragma config CCPMX = RB0      // CCP1 Pin Selection bit (CCP1 function on RB0)
    #pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

    // CONFIG2
    #pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
    #pragma config IESO = OFF       // Internal External Switchover bit (Internal External Switchover mode disabled)

    // #pragma config statements should precede project file includes.
    // Use project enums instead of #define for ON and OFF.

    #include <xc.h>

    #define _XTAL_FREQ 8000000
     
    void main(void)
    {
        OSCCON=0b01110000;  //8MHz
        PORTA=0x00;
        PORTB=0x00;
        TRISA=0x00; //all pins output
        TRISB=0x00; //all pins output
        ANSEL=0x00; //all pins digital
        while(1)
        {
            PORTB = 0b11111111; //all pins high
            __delay_ms(500);
            PORTB = 0b00000000; //all pins low
            __delay_ms(500);
        }
    }

    I have attached the hex file to this message.
     
    #11
    M84AB1
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2013/05/15 06:23:43
    • Location: 0
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/28 21:43:31 (permalink)
    0
    qhb
    I'm running out of ideas.
    Few of the people answering will be using PICBASIC PRO.
    How about trying a hex file from this C code
     
    I have attached the hex file to this message.



    Thank you for your help qhb. I have tried that hex file and still nothing. This leads me to believe that it may be somehow PICKit4 or MPLAB IPE related?
     
    I don't think PICBASIC Pro has anything to do with it as it works with other MCUs and the fact that this HEX file does not work either although it was written in C and compiled on another machine leads me to believe that something is not going right during the programming process?
     
     
    post edited by M84AB1 - 2018/12/28 22:19:13

    Attached Image(s)

    #12
    cobusve
    Super Member
    • Total Posts : 456
    • Reward points : 0
    • Joined: 2012/04/02 16:15:40
    • Location: Chandler
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/28 23:47:09 (permalink)
    +1 (1)
    Have you tried logging a support ticket with Microchip? This may be a bug in MPLAB-X for that device...
    #13
    JorgeF
    Super Member
    • Total Posts : 3340
    • Reward points : 0
    • Joined: 2011/07/09 11:56:58
    • Location: PT/EU @ Third rock from the Sun
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/29 12:34:44 (permalink)
    0
    Hi
     
    Set FOSC options with a clock output active, and measure it with the scope on pin RA5.
     
    FOSC = INTIO1 should output Fosc/4 at pin RA5.
     
    My suggested configuration of OSCCON for 4MHz internal is:

    // Oscillator configuration
    // ------------------------
    //
    // Internal oscillator (see FOSC pragma)
    //
    // Set 4MHz on internal oscillator
    //
    // OSCCON
    // x--- ---- don't care (unimplemented))
    // -110 ---- IRCF - 4MHz
    // ---- x--- don't care (read only))
    // ---- -0-- IOFS
    // ---- --00 SCS - Clock source defined by FOSC bits
    #define OSCCON_INIT 0x60

     
     
    HIH
     

    Best regards
    Jorge
     
    I'm here http://picforum.ric323.com too!
    And it works better....
    #14
    piticbogdan
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2018/12/02 17:58:02
    • Location: 0
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/29 18:12:07 (permalink)
    0
    Please use the

    DEFINE OSC x

    to inform the pbp(3?) compiler the osc value

    Those infos are in the pbp manual... also I recommend to ask for help in the pic basic forum (very friendly people there too)

    Thank you
    #15
    AMPS
    Super Member
    • Total Posts : 347
    • Reward points : 0
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/30 20:01:07 (permalink)
    0
    why cant you try c code once. QHB and i have posted code in c . Let me know clock width for timer interrupt whre we can recalculate the frequency adjusted.

    Amps
    *.*.*.*.*.*.*.*.*.*.*.*.*
    #16
    1and0
    Access is Denied
    • Total Posts : 8744
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/30 22:16:14 (permalink)
    +1 (1)
    ajitnayak87
    why cant you try c code once. QHB and i have posted code in c . 

    Why can't you read the posts in this thread? ;) In Post #12, OP has tried a C-generated hex file provided by Qhb from Post #11.
    #17
    PStechPaul
    Super Member
    • Total Posts : 2135
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: online
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2018/12/31 02:36:48 (permalink)
    +1 (1)
    Maybe try using MPLAB 8.92 for this legacy device. But that might not support the PICkit4, or PIC basic.

     
    #18
    Jams100001
    Starting Member
    • Total Posts : 47
    • Reward points : 0
    • Joined: 2018/04/12 13:37:33
    • Location: MCHP Chandler
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2019/01/02 14:00:22 (permalink)
    0
    M84AB1
    Hi all,
     
    I have been a long time reader but first time poster. As the title suggests, I am not able to get the internal oscillator to work at any frequency beyond 31.25kHz. The below configuration bits is what I am using in order to get the 16F88 to oscillate internally at 4Mhz.
     

     
    #CONFIG

      __config _CONFIG1, _INTRC_IO & _WDT_OFF & _PWRTE_ON & _MCLR_OFF & _LVP_OFF & _CP_OFF
     
    #ENDCONFIG
     
     
     
    OSCCON = %01101110    '4Mhz - does not work
     
    OSCCON = %00001110    '31.25kHz - does work
     
     

     
    I have tried to get other frequencies to work but without luck. What am I doing wrong? Or is perhaps the MCU faulty?
     
    Also, worthwhile mentioning is that the MCU works perfectly fine with an external clock eg. 4Mhz, 8Mhz...etc.
     
    I am also using PICBASIC PRO, not C to program.
     
     


    I'm pretty confident I found out why you can't get the INTOSC with the different frequencies.
    Your configuration word shows INTRC_IO which is the Internal RC oscillator which only runs at 31.25Khz.
    This part has two different Internal Oscillators INTRC and INTOSC (31.25Khz and 8Mhz). the adjustment of the INTOSC is done using a postscaler to get 125Khz, 250Khz, 500Khz, 1Mhz, 2Mhz, and 4Mhz.
     
    your code for setting up the configuration word should look like this
     
      __config _CONFIG1, _FOSC_INTOSCIO & _WDT_OFF & _PWRTE_ON & _MCLR_OFF & _LVP_OFF & _CP_OFF
     
    by using _FOSC_INTOSCIO for the configuration word it uses the INTOSC and you can change the OSCCON to adjust the frequency of the internal oscillator. 
     
    Jams10001
     
     
    #19
    M84AB1
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2013/05/15 06:23:43
    • Location: 0
    • Status: offline
    Re: 16F88 cannot set internal oscillator frequency beyond 31.25kHz 2019/01/02 21:22:10 (permalink)
    0
    thank you all for your input guys!! I really appreciate it.
     
    This is the weirdest thing. Not sure what to make of it. So I ordered 3 samples of 16F88 directly from microchip and I had the original 16F88, one more from a local electronics store and another one I had forgotten I had used on another project which I pulled out to test, so in total six 16F88s. When the 3 samples arrived I thought I give my old programmer ( a cheap JDM programmer from China) and PICPgm software a shot using the LED blinking HEX file that qhb provided. Here are the results
     
    - Sample 1 from microchip programs successfully using JDM Programmer and PICPgm and internal oscillator works.
    - Sample 1 from microchip programs successfully using PICKit4 and MELAB IPE and internal oscillator works.
    - Sample 2 from microchip programs successfully using JDM Programmer and PICPgm and internal oscillator works.
    - Sample 2 from microchip programs successfully using PICKit4 and MELAB IPE and internal oscillator now does not work. So I give JDM Programmer and PICPgm a shot again and this sample can no longer set the internal oscillator to anything other than 31.25kHz. Did it somehow break all of a sudden!?!
    - Sample 3 from microchip programs successfully using JDM Programmer and PICPgm and internal oscillator does not work.
    - Sample 3 from microchip programs successfully using PICKit4 and MELAB IPE and internal oscillator does not work
    - Original 16F88, well you guys know the story
    - The 16F88 I bought from local store programs successfully using JDM Programmer and PICPgm and internal oscillator does not work. I then of course try PICKit4 and MELAB IPE and of course the internal oscillator does not work
    - The 16F88 I pulled from an old project programs successfully using JDM Programmer and PICPgm and internal oscillator works.
    - The 16F88 I pulled form an old project programs successfully using PICKit4 and MELAB IPE and internal oscillator works.
     
    I have tried many different ways to set the config bits ranging from using IPE config bits window, to setting it in the code to setting it in the .inc file itseself and the ones that work, work regardless of method and the ones that don't, don't work no mater what I try.
     
    Worthwhile to note is that ALL of the six 16F88s work flawlessly when an external clock is used. I am wondering if somehow some config bits are set and then somehow "locked" in permanently eg. the Oscillator config bit!?! Or are perhaps four out of the six microcontrollers some how faulty as far as internal oscillator or perhaps OSCCON register goes?
     
    I will log a support call with microchip as has been suggested and see what they have to say.
     
    The picture below is the actual breadboard and circuit (Thermometer) with one of the two working 16F88
     
    post edited by M84AB1 - 2019/01/02 21:31:03

    Attached Image(s)

    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5