CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC16F18856 internal oscillator doesn't start at 32MHZ
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
testman



Joined: 27 Mar 2019
Posts: 8

View user's profile Send private message

PIC16F18856 internal oscillator doesn't start at 32MHZ
PostPosted: Wed Mar 27, 2019 4:59 am     Reply with quote

Hello !
I have a problem.
I can not config the PIC16F18856 with internal osc. to run at 32Mhz.
I am using v5.083.

Is there anyone can help me ?

Thanks in advance!
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 27, 2019 5:15 am     Reply with quote

We need to see your complete test program....
testman



Joined: 27 Mar 2019
Posts: 8

View user's profile Send private message

PostPosted: Wed Mar 27, 2019 5:20 am     Reply with quote

It should to be natural to setup the oscillator :-(

in my header file
Code:

#FUSES NOWDT                   
#FUSES NOEXTOSC           
#FUSES RSTOSC_HFINTRC_32MHZ
#FUSES NOCLKOUT           
#FUSES CKS                   
#FUSES FCMEN                    
#FUSES MCLR                     
#FUSES PUT       

#use delay(internal=32000000,restart_wdt)

in main:
Code:

 setup_oscillator(OSC_HFINTRC_32MHZ ,0);

I have tried a lot of things nothing work properly.
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 27, 2019 8:14 am     Reply with quote

Sorry but you need to post your COMPLETE program NOT just a few lines....
No one can cut/paste/compile/test without a complete program.
testman



Joined: 27 Mar 2019
Posts: 8

View user's profile Send private message

PostPosted: Wed Mar 27, 2019 9:00 am     Reply with quote

OK.. This is simple example. But I realy can not realise where is the real problem :-(

Code:

#include <16F18856.h>
#device ADC=10

#FUSES NOWDT                   
#FUSES NOEXTOSC           
#FUSES RSTOSC_HFINTRC_32MHZ
#FUSES NOCLKOUT           
#FUSES CKS                   
#FUSES FCMEN                   
#FUSES MCLR                     
#FUSES PUT       
#FUSES WRT_200         
#FUSES NOSCANE                    //Scanner module is available for use
#FUSES NOLVP               
#FUSES PROTECT                  //Code protected from reads
#FUSES NOCPD                    //No EE protection

#use delay(internal=32000000,restart_wdt)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)

#pin_select CCP1OUT=PIN_C2
#pin_select CCP2OUT=PIN_C1

void main(){
       
    setup_oscillator(OSC_HFINTRC_32MHZ ,0);
    //OSCFRQ = 0x06;
    set_tris_a(0b00000000);
    set_tris_b(0b00110111);
    port_b_pullups(0b00000111);
    set_tris_c(0b10010000);
    disable_interrupts(GLOBAL);
    //
    delay_ms(10); 
    setup_ccp1(CCP_OFF);
    setup_ccp2(CCP_OFF);
//
   //setup_lcd(LCD_DISABLED);
//   
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);   //65.5 ms overflow
   setup_timer_2(T2_CLK_INTERNAL | T2_DIV_BY_64, 255, 1);         
//
   setup_ccp1(CCP_PWM);
        set_pwm1_duty((int16)0);
   setup_ccp2(CCP_PWM);
   set_pwm2_duty((int16)0);
// 
    disable_interrupts(INT_IOC);   
    disable_interrupts(INT_RB0_H2L|INT_RB0_L2H);
    disable_interrupts(INT_RB1_H2L|INT_RB1_L2H);
    disable_interrupts(INT_RB2_H2L|INT_RB2_L2H);
    disable_interrupts(INT_RB3_H2L|INT_RB3_L2H);
    disable_interrupts(INT_RB5_H2L|INT_RB5_L2H);
    enable_interrupts(INT_RB4_H2L|INT_RB4_L2H);
   
      
     setup_wdt(WDT_ON|WDT_2S);      //~2.0 s reset   
//.........................................................................
    while(TRUE){
       output_toggle(PIN_B3);
       delay_ms(250);
     }
//...........................................................................

}// end main
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Mar 27, 2019 9:25 am     Reply with quote

So what does it actually do?.
You have FSCM enabled, so even if the oscillator is not starting, it ought
to run, just at the fail safe rate.

As a comment _do not use protect when developing_. Doing so
uses extra chip lives (the programmer has to perform a bulk erase of
the whole chip to change even one byte). Never use this until you are
at the final 'must be protected' run time code.

You could try setting the oscillator with:
Code:

#include <16F18856.h>
#device ADC=10


#FUSES NOWDT                   
#FUSES NOEXTOSC           
#FUSES RSTOSC_HFINTRC
#FUSES NOCLKOUT           
#FUSES CKS                   
#FUSES FCMEN                   
#FUSES MCLR                     
#FUSES PUT   

#use delay(CLOCK=32000000)
#FUSES RSTOSC_HFINTRC

#define OSC_HFINTRC32MHZ            0x00000606

void main()
{
   setup_oscillator(OSC_HFINTRC32MHZ);



This forces it to use the oscillator at 32MHz, without the PLL. The compiler
is defaulting to using 16MHz, with the 2*PLL enabled.

The settings do look correct, with all the registers set right. Question:

What compiler version?.

If yours is an early release for this chip the settings may be wrong, and
we can't tell unless you say what version you are running.
testman



Joined: 27 Mar 2019
Posts: 8

View user's profile Send private message

PostPosted: Wed Mar 27, 2019 9:42 am     Reply with quote

Unfortunately it is not work.
Compiler version is 5.081 and I have updated it to 5.083.
I am agree with you about protect bit but this is working project just want to change the microcontroler :-(

It seems that in my configuration hardware works at 32MHZ but the compiler doesn't calculate correct delays.

Very strange problem.
I still don't know what to do.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 27, 2019 1:32 pm     Reply with quote

I have a 16F18857 (same family as the '56 - just more memory). I can
work on it later this afternoon, in a few hours.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Mar 27, 2019 2:37 pm     Reply with quote

OK. PCM_Programmer will have a look, but in the meantime, what clock rate
does it run?.
If you do the classic 'flash an LED' test, you can see what delays it does
give versus what you are asking for. This will give us a huge hint, as to
what is actually happening.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 27, 2019 8:28 pm     Reply with quote

I was able to make an LED blink at 1 Hz (timed it with a stopwatch) with
the following program. I also looked at the CLKOUT pin with a scope and
it's running at 8 MHz, which is correct for a 32 MHz oscillator.

The CLKOUT fuse by itself didn't work. It's possible that it's being
over-ridden by the #use delay internal. I don't know. I was in a hurry so
I over-rode it with a separate #fuses 1 line.

To get a clean signal on CLKOUT, I had to set it to fast slew rate.

This was tested with PCM vs. 5.083.
Code:

#include <16F18857.h>
#fuses NOWDT, CLKOUT
#use delay(internal=32M)
#fuses 1=0xFE9C

#byte SLRCONA=getenv("SFR:SLRCONA")
#byte SLRCONB=getenv("SFR:SLRCONB")
#byte SLRCONC=getenv("SFR:SLRCONC")

//========================================
void main()
{
SLRCONA=SLRCONB=SLRCONC=0;
         
while(TRUE)
  {
   output_high(PIN_B0);
   delay_ms(100);
   output_low(PIN_B0);
   delay_ms(900);
  }
testman



Joined: 27 Mar 2019
Posts: 8

View user's profile Send private message

PostPosted: Thu Mar 28, 2019 1:19 am     Reply with quote

Hello !
Thanks for support. You are put manual value for CONFIG1. Is there any problem with CCS tools for setup hardware.
After a lot of reading posts and combination this setup configuration looks working config.
But still I fill strange why so natural task as setting oscillator with CCS info tools become nightmare :-(

I am using v5.081 because in v5.083 there is no FUSE PROTECT and I again should read how to setup fuse -> protect :-( .
Working version :-)
Code:

#include <16F18856.h>
#device ADC=10

#FUSES NOWDT                      
#FUSES NOEXTOSC                 
#FUSES RSTOSC_HFINTRC_32MHZ
    //#FUSES RSTOSC_HFINTRC_PLL       //
#FUSES CLKOUT                 
#FUSES CKS                      
#FUSES FCMEN                    
#FUSES MCLR                     
#FUSES PUT                    
#FUSES NOLPBOR                  
#FUSES NOBROWNOUT               
#FUSES BORV24                   
#FUSES ZCDDIS                   
#FUSES PPS1WAY                  
#FUSES STVREN                   
//#FUSES WDTSW                    
//#FUSES WDTWIN_SW                
//#FUSES WDTCLK_HFINTRC           
#FUSES WRT_200                  
#FUSES NOSCANE                    
#FUSES NOLVP                    
#FUSES PROTECT                  
#FUSES NOCPD                    
//


#use delay(clock=32000000,restart_wdt)
//#FUSES RSTOSC_HFINTRC
#FUSES RSTOSC_HFINTRC_32MHZ

void main()
{
     delay_cycles(100);
     output_toggle(PIN_B3);
}


Last edited by testman on Thu Mar 28, 2019 4:32 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 28, 2019 2:17 am     Reply with quote

It's not a nightmare. It worked right away for me, with this
short little program:
Code:

#include <16F18857.h>
#fuses NOWDT
#use delay(internal=32M)

//========================================
void main()
{
         
while(TRUE)
  {
   output_toggle(PIN_B0);
   delay_ms(500);
  }

}


All the rest of the code I posted was just for testing purposes.
CLKOUT is not normally needed.
testman



Joined: 27 Mar 2019
Posts: 8

View user's profile Send private message

PostPosted: Thu Mar 28, 2019 2:35 am     Reply with quote

Thanks again. In fact I have never tested only with one line (#use delay(internal=32M) ), because I need to setup all registers for this microcontroller.

It is working project that I just need to change CPU.

But ... Personal for me if there is tools for hardware configuration it should work properly :-)
Never mind.
Thanks for spending your time.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Mar 28, 2019 3:39 am     Reply with quote

Some comments:

If you build PCM_Programmers simple test, and look at the fuses, and the
code, then compare with the non working version, what is 'odd', is that it
is all identical. Fuses the same, and clock setup the same:
Code:

//PCM's code gives
.................... void main()
0019:  MOVLB  11
001A:  CLRF   OSCTUNE
001B:  CLRF   OSCCON3
001C:  CLRF   OSCEN
001D:  MOVLW  05
001E:  MOVWF  OSCFRQ
001F:  MOVLW  10
0020:  MOVWF  OSCCON1
0021:  MOVLB  3E
0022:  CLRF   38
0023:  CLRF   43
0024:  CLRF   4E
0025:  MOVLB  13
0026:  CLRF   CM1CON1
0027:  CLRF   CM1NSEL
0028:  CLRF   CM1PSEL
0029:  CLRF   CM1CON0
002A:  CLRF   CM2CON1
002B:  CLRF   CM2NSEL
002C:  CLRF   CM2PSEL
002D:  CLRF   CM2CON0

Configuration Fuses:
   Word  1: 3F9C   NOEXTOSC RSTOSC_HFINTRC_PLL NOCLKOUT CKS FCMEN
   Word  2: 3FFD   MCLR PUT NOLPBOR BROWNOUT BORV24 ZCDDIS PPS1WAY STVREN NODEBUG
   Word  3: 3F9F   WDTSW NOWDT WDTWIN_SW WDTCLK_SW
   Word  4: 1FFF   NOWRT SCANE NOLVP
   Word  5: 3FFF   NOCPD

//Building with your original clock settings gives:
.................... void main()
001D:  MOVLB  11
001E:  CLRF   OSCTUNE
001F:  CLRF   OSCCON3
0020:  CLRF   OSCEN
0021:  MOVLW  05
0022:  MOVWF  OSCFRQ
0023:  MOVLW  10
0024:  MOVWF  OSCCON1
0025:  MOVLB  3E
0026:  CLRF   38
0027:  CLRF   43
0028:  CLRF   4E
0029:  MOVLB  13
002A:  CLRF   CM1CON1
002B:  CLRF   CM1NSEL
002C:  CLRF   CM1PSEL
002D:  CLRF   CM1CON0
002E:  CLRF   CM2CON1
002F:  CLRF   CM2NSEL
0030:  CLRF   CM2PSEL
0031:  CLRF   CM2CON0

Configuration Fuses:
   Word  1: 3F9C   NOEXTOSC RSTOSC_HFINTRC_PLL NOCLKOUT CKS FCMEN
   Word  2: 3FFD   MCLR PUT NOLPBOR BROWNOUT BORV24 ZCDDIS PPS1WAY STVREN NODEBUG
   Word  3: 3F9F   WDTSW NOWDT WDTWIN_SW WDTCLK_SW
   Word  4: 1FFF   NOWRT SCANE NOLVP
   Word  5: 3FFF   NOCPD

Exactly the same fuses and configuration.
Your setup_oscillator line also gives the same setup.

I think you are running at 32MHz.

Now you carefully don't use delay_ms, or delay_us in your test. You do
realise that a PIC CPU running at 32MHz Fosc, only executes 8MIPS.
So 'delay_cycles(100)', will correspond to 12.5uSec. What clock rate
are you actually seeing on this test?.

Looking at the device with device editor, you can see that what has
happened is that CCS have changed how the fuses are actually generated.
In the past if you had an entry like CPD, there was a line defining the
CPD fuse and a second line defining the NOCPD setting. Now fuses
like this are defined with the syntax [NO]CPD', and only a single entry
giving the two possible settings. Their code that has generated the
new syntax has obviously missed the line for 'PROTECT'. When you
think how many tens of thousands of entries are actually involved, it
is not surprising that a few errors will appear, and you are probably
just the first person to have found one...
testman



Joined: 27 Mar 2019
Posts: 8

View user's profile Send private message

PostPosted: Thu Mar 28, 2019 4:29 am     Reply with quote

Hi Ttelmah.
Thanks spending your time with this problem.

I know very well that 1 instructions need 4 clocks ( this design of the Microchip is maybe since 20-25 years ).

I see 13uS because I have toggle_pin instructions and goto back to delay_cycles. So everything is OK.

In fact at the end of the third day I just set manual CONFIG1 as PCM_Programmer did. And realise where is the problem.

But as I wrote when I have tools for configuration of the CPU in my opinion it should work properly. Just an example I am working with v5.081 . I upgraded it to v5.083 because of this problem and #FUSES PROTECT disappear magically. So I should to start research (losing time) is this bit set or NO. and etc.

Yes I always can override configuration as PCM_Programmer has done. But when we have tools why should to spend times to read every detail. :-)

Never mind. I appreciate your effort to solve the problem. Thanks to you and PCM_Progrmmer and wish us less bugs like this, because we need more free time for fun :-)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group