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

Please, help me run pic16f1827 at 32 MHz

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



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

Please, help me run pic16f1827 at 32 MHz
PostPosted: Tue Oct 30, 2012 12:28 am     Reply with quote

Hello!

I Have a pic16f1827(http://ww1.microchip.com/downloads/en/DeviceDoc/41391D.pdf) microcontroller. I'm new to CCS and this controller. According to examples and datasheet, I can run it on 8MHz from internal oscillator.

I wrote this configuration for my case (resistor to Vdd on MCLR pin, two adc inputs, internal oscillator, nothing more, interrupt for Timer0 and minimal oscillator divider):
Code:

#include <16F1827.h>
#device adc=8

#FUSES NOWDT, INTRC_IO, PUT, NOPROTECT, MCLR, NOCPD, BROWNOUT, IESO, FCMEN,
#FUSES NOCLKOUT, NOWRT, STVREN, BORV25, NODEBUG, NOLVP, RESERVED
#use delay(clock=8000000)

#int_TIMER0
void  TIMER0_isr(void)
{
    //Some code would be there
}

void initHardware()
{
   setup_adc_ports(sAN0|sAN1);
   setup_adc(ADC_CLOCK_DIV_16);

   setup_spi(FALSE);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1|RTCC_8_bit);

   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
}

void main()
{
   initHardware();

   while(true)
   {
      output_toggle(PIN_B7);
      delay_ms(1000);
   }
}


I have a led on PIN_B7, and it changes its state every second, as you see. Also I have some code in interrupt body.

My microcontroller can be run at 32 MHz from internal oscillator using 4x frequency multiplier, but I don't know how to use it.
Please, help me to do this!
Thank you!
Ttelmah



Joined: 11 Mar 2010
Posts: 19544

View user's profile Send private message

PostPosted: Tue Oct 30, 2012 2:44 am     Reply with quote

Code:

#include <16F1827.h>
#device adc=8

#FUSES NOWDT, INTRC_IO, PUT, NOPROTECT, MCLR, NOCPD, BROWNOUT, IESO, FCMEN,
#FUSES NOCLKOUT, NOWRT, STVREN, BORV25, NODEBUG, NOLVP, RESERVED
#use delay(clock=32000000)

#int_TIMER0
void  TIMER0_isr(void)
{
    //Some code would be there
}

void initHardware() {
   setup_oscillator(OSC_8MHZ | OSC_INTRC | OSC_PLL_ON);
   setup_adc_ports(sAN0|sAN1);
   setup_adc(ADC_CLOCK_DIV_32); //Remember to change this as well

   setup_spi(FALSE);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1|RTCC_8_bit);

   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
}

void main()
{
   initHardware();

   while(true)
   {
      output_toggle(PIN_B7);
      delay_ms(1000);
   }
}

Note the clock setting, and the first line in your 'init_hardware' function. Note also the change to the ADC clock (/32 or /64 are the legal clocks at 32MHz).

The exact constants may (unfortunately) change with compiler version. Look in the .h file for the processor to see the ones for your compiler. The ones posted are correct for the current (4.137) compiler.

Best Wishes
KT315



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

PostPosted: Wed Oct 31, 2012 12:12 am     Reply with quote

Ttelmah, thank you very much!
There's a strange behavior, 32 MHz reach only when OSC_16MHZ set in oscillator setup. Datasheet says 8 should be. Not a matter.
Once more, thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19544

View user's profile Send private message

PostPosted: Wed Oct 31, 2012 2:16 am     Reply with quote

If you look, at the oscillator diagram, you shouldn't have to set the OSC divider at all (I put it in just for 'being there'). If the PLL is selected, it only comes from the 8MHz route. The divider selection bits come 'after' the clock is already 'en route' to the PLL.
OSC_16MHz, sets these bits to all 1's, and nothing is actually said about the effect of these when using the PLL. I'd guess an oddity in the way the CCS code handles this, or an actual oddity in the chip. If you wanted to 'know' which, I'd go manual, and test the effect of changing just these bits.

Best Wishes
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