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 CCS Technical Support

32MHz internal clock not working with PIC16F1827

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



Joined: 21 Aug 2010
Posts: 4

View user's profile Send private message

32MHz internal clock not working with PIC16F1827
PostPosted: Sat Aug 21, 2010 11:12 am     Reply with quote

Hi,

I am programming a PIC16F1827, and using PCM compiler V4.109, 53252.
I want to operate at 32 MHz with internal oscillator, but I am obtaining behavior of 8MHz. I suspect PLL 4x is not working...
I am using the following directives / programming:
Code:

#include <16F1827.h>
#device adc=8
#fuses  INTRC_IO,PLL,WDT,PUT,PROTECT,CPD,BROWNOUT,NOMCLR
#fuses  NOIESO,NOFCMEN,NOCLKOUT,NOLVP,NODEBUG,BORV25,NOSTVREN
#use delay(CLOCK=32000000,RESTART_WDT)
#use fast_io(A)
#use fast_io(B)
//...
setup_oscillator(OSC_8MHZ  |  OSC_PLL_ON  |  OSC_INTRC);

What am I doing wrong and what else can I do ?

Thank you all.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 21, 2010 10:40 pm     Reply with quote

Post a little program that blinks an LED, that you use to prove that it's
not running at 32 MHz.

This thread has examples of LED blinking programs:
http://www.ccsinfo.com/forum/viewtopic.php?t=42223

Also, don't use WDT, PROTECT, and CPD in the test program. They are
not needed.
jcec



Joined: 21 Aug 2010
Posts: 4

View user's profile Send private message

OSCCON bits manually set up
PostPosted: Sun Aug 22, 2010 10:38 am     Reply with quote

Hi,

I used the following program
Code:

#include <16F1827.h>
#device adc=8
#fuses  INTRC_IO,PLL,PUT,BROWNOUT,NOMCLR
#fuses  NOIESO,NOFCMEN,NOCLKOUT,NOLVP,NODEBUG,BORV25,NOSTVREN
#use delay(CLOCK=32000000,RESTART_WDT)
#use fast_io(A)
#use fast_io(B)
//====================================
void main()
{
  //Program pin direction
  set_tris_a(0x00);
  //Program oscillator
  setup_oscillator(OSC_8MHZ  |  OSC_PLL_ON  |  OSC_INTRC);
  // Blink an LED on pin A2. (PIN_A2 == pin 1 on 16F1827 DIP)
  while(1)
    {
     output_high(PIN_A2);     
     delay_ms(500);
     output_low(PIN_A2);     
     delay_ms(500);
    }
}


This resulted in a period of 4 seconds (2s low, 2s high) of the output and not 1s as desired.
Then I added the following code line configuring SCS bits of OSCCON:
Code:
 
OSCCON = OSCCON & 0xFC;           //  OSCCON.1 = OSCCON.0 = 0;

and, voila, the output period worked fine (1s as expected for a 32 MHz)
Good, this is a solution, but I wonder what would be the right configuration to be done using only CCS C functions...

Thanks.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Aug 22, 2010 11:12 am     Reply with quote

Sometimes you don't need the SETUP_OSC(); if the fuses/USE DELAY is.

See, the fuses (and then #USE DELAY) set up those config items already and then you set them again in code using SETUP_OSC();

So try this and let me know if it works:

#use delay (clock=32M, INT=8M)

Check the LST output at the CONFIG words (at the bottom of the .LST file)

If that works, then you may not even need the #FUSES PLL line.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
jcec



Joined: 21 Aug 2010
Posts: 4

View user's profile Send private message

PostPosted: Sun Aug 22, 2010 5:34 pm     Reply with quote

bkamen:

I tried what you suggested;

Code:

#include <16F1827.h>
#device adc=8
#fuses  INTRC_IO,PLL,PUT,BROWNOUT,NOMCLR
#fuses  NOIESO,NOFCMEN,NOCLKOUT,NOLVP,NODEBUG,BORV25,NOSTVREN
////////#use delay(CLOCK=32000000,RESTART_WDT)
#use delay (clock=32M,int=8M)
#use fast_io(A)
#use fast_io(B)
//====================================
void main()
{
  //Program pin direction
  set_tris_a(0x00);
 
  //Program oscillator
////////  setup_oscillator(OSC_8MHZ  |  OSC_PLL_ON  |  OSC_INTRC);
 
  // Blink an LED on pin A2. (PIN_A2 == pin 1 on 16F1827 DIP)
  while(1)
    {
     output_high(PIN_A2);     
     delay_ms(500);
     output_low(PIN_A2);     
     delay_ms(500);
    }
}


but it did not work, the PLL enable bit in the configuration word does not get enabled!

Thanks.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Aug 22, 2010 6:13 pm     Reply with quote

jcec wrote:
bkamen:

I tried what you suggested;

Code:

#include <16F1827.h>
#device adc=8
#fuses  INTRC_IO,PLL,PUT,BROWNOUT,NOMCLR
#fuses  NOIESO,NOFCMEN,NOCLKOUT,NOLVP,NODEBUG,BORV25,NOSTVREN
////////#use delay(CLOCK=32000000,RESTART_WDT)
#use delay (clock=32M,int=8M)
#use fast_io(A)
#use fast_io(B)
//====================================
void main()
{
  //Program pin direction
  set_tris_a(0x00);
 
  //Program oscillator
////////  setup_oscillator(OSC_8MHZ  |  OSC_PLL_ON  |  OSC_INTRC);
 
  // Blink an LED on pin A2. (PIN_A2 == pin 1 on 16F1827 DIP)
  while(1)
    {
     output_high(PIN_A2);     
     delay_ms(500);
     output_low(PIN_A2);     
     delay_ms(500);
    }
}


but it did not work, the PLL enable bit in the configuration word does not get enabled!

Thanks.


Ok, I've dug deeper for you...

PLL doesn't seem to be a valid fuse.
PLL_SW is the only fuse that's valid.

Using #use delay(clock=32M, int=8M) doesn't set the PLLEN bit in Config2 either.

The datasheet states that if CONFIG2.8 == 1
Then OSCCON.7 is ignored and the PLL is enabled.
However, there's no fuse to set CONFIG2.8 (as I readily see)

If everyone else agrees, then this is a CCS database bug and you should submit it.

You should also read the datasheets more carefully as you would have seen this.

For now, if you want your code to work the way it should, you can fuss with the software or you could set the ROM location of the config2 word to 0x19FF (which is PLL enabled)

This works: (according to MPLAB)

#rom 0x8008 = {0x19ff}

And tell CCS to look again at this device...

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
jcec



Joined: 21 Aug 2010
Posts: 4

View user's profile Send private message

PostPosted: Sun Aug 22, 2010 8:07 pm     Reply with quote

Hi bkamen,

Thanks for your hints and for your time on this issue.
I´ll do as you suggest and also submit a bug report to CCS.

Best regards.
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