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

16LF18426 - OSC_HFINTRC_4MHZ makes the PIC run at 8MHz

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Synthex



Joined: 07 Oct 2009
Posts: 5

View user's profile Send private message

16LF18426 - OSC_HFINTRC_4MHZ makes the PIC run at 8MHz
PostPosted: Mon Oct 14, 2019 11:54 am     Reply with quote

With the instruction :
setup_oscillator( OSC_HFINTRC_4MHZ );
The PIC runs at 8MHz

In 16LF18426.h :
Code:
#define OSC_HFINTRC_1MHZ             0x00000060
#define OSC_HFINTRC_2MHZ             0x00000160
#define OSC_HFINTRC_4MHZ             0x00000360     
#define OSC_HFINTRC_8MHZ             0x00000460     
#define OSC_HFINTRC_12MHZ            0x00000560     
#define OSC_HFINTRC_16MHZ            0x00000660     
#define OSC_HFINTRC_24MHZ            0x00000500     
#define OSC_HFINTRC_32MHZ            0x00000600     
#define OSC_EXTOSC_PLL               0x00000010     
#define OSC_SOSC                     0x00000030     
#define OSC_LFINTRC                  0x00000040     
#define OSC_EXTOSC                   0x00000070


For example, in 16LF18876.h :
Code:
#define OSC_HFINTRC_1MHZ             0x00000060
#define OSC_HFINTRC_2MHZ             0x00000160
#define OSC_HFINTRC_4MHZ             0x00000260
#define OSC_HFINTRC_8MHZ             0x00000360
#define OSC_HFINTRC_12MHZ            0x00000460
#define OSC_HFINTRC_16MHZ            0x00000560
#define OSC_HFINTRC_24MHZ            0x00000410
#define OSC_HFINTRC_32MHZ            0x00000510
#define OSC_EXTOSC_PLL               0x00000020
#define OSC_SOSC                     0x00000040
#define OSC_LFINTRC                  0x00000050
#define OSC_EXTOSC                   0x00000070


With the instruction :
setup_oscillator( 0x00000260 );
The PIC runs well at 4MHz

I think there is a bug in the 16LF18426.h file and others 16LF184XX.h files
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 15, 2019 3:30 am     Reply with quote

Yes, it's a bug in the .h file values. The 16F18426 data sheet shows
that 0x02 is the correct value for the OSCFRQ register to get 4 MHz.

I suspect that someone at CCS was typing in the oscillator table and
and they made a typo and skipped a value. This also caused all values
after that one to be wrong.

You could hand edit the values in the .h file to match the PIC data sheet
table on page 118 of the data sheet.
http://ww1.microchip.com/downloads/en/DeviceDoc/Microchip-8-bit-PIC-MCU-PIC16%28L%29F18426_46-Datasheet-40001985A.pdf

The 16F18446.h is also incorrect.

A work-around is to let the #use delay() statement set the frequency.
That works. It's using an internal table in the PIC database file.
(Though, I was led to believe that the .h files were auto-generated from
the internal database. I guess not always the case).
Don't put in any oscillator fuses when you use this method.
The #use delay(internal=4M) statement does it all.
Example:
Code:

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


//=========================
void main(void)
{

   
while(TRUE);   
}


You should inform CCS support of the bugs in the two .h files.
Synthex



Joined: 07 Oct 2009
Posts: 5

View user's profile Send private message

PostPosted: Tue Oct 15, 2019 8:54 am     Reply with quote

Yes, I informed the CCS Support.

Ok, for the #use delay() statement, but I use this function to make a delay in low power consumption.

Code:
// Delay in Low power
setup_oscillator( OSC_HFINTRC_1MHZ | OSC_CLK_DIV_BY_512 ); // =>  1953 Hz
delay_us(2); // about 14ms
setup_oscillator( 0x00000260 ); //  OSC_HFINTRC_4MHZ


I can not use the sleep() features with WDT or Timers for wait times of less than 20ms.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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