EmbeddedRelated.com
Forums

Maximum speed, all ports as I/O

Started by Unknown March 6, 2008
At the moment I'm using the following with my PIC16F684:

__CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN &
WDTDIS & INTIO);

With this setting, the CPU clock is running at 4 MHz. I've heard tho
that it can run at 16 MHz. (I'm not using an external clock).

Does anyone know what I've to do to get it running at its top speed,
and with all pins set to I/O?

(I've looked over the datasheet but it's too cryptic for me to make
any sense of it)


> At the moment I'm using the following with my PIC16F684: > > __CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & > WDTDIS & INTIO); > > With this setting, the CPU clock is running at 4 MHz. I've heard tho > that it can run at 16 MHz. (I'm not using an external clock). > > Does anyone know what I've to do to get it running at its top speed, > and with all pins set to I/O?
Look at fig 3-1 of the datahsheet. You'll see the internal HF osc is 8 MHz. You can't get it any higher than that without an external clock source. So if the CPU clock is one half of the in HF osc, then you'll need a 32 MHz external clock or crystal to achieve a CPU clock of 16 MHz. You'll need to make sure your part is graded to run at that speed. You'll also need to become comfortable with reading the data sheets. You won't be able to do much with the device if you can't read the data sheet. JJS
John Speth wrote:
>> At the moment I'm using the following with my PIC16F684: >> >> __CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & >> WDTDIS & INTIO); >> >> With this setting, the CPU clock is running at 4 MHz. I've heard tho >> that it can run at 16 MHz. (I'm not using an external clock). >> >> Does anyone know what I've to do to get it running at its top speed, >> and with all pins set to I/O? > > Look at fig 3-1 of the datahsheet. You'll see the internal HF osc is 8 MHz. > You can't get it any higher than that without an external clock source.
Correct.
> So if the CPU clock is one half of the in HF osc, then you'll need a 32 MHz > external clock or crystal to achieve a CPU clock of 16 MHz.
The internal clock runs at the HF rate, but the instruction cycle is 4 clock cycles on a PIC. Bottom line is 2 M ins cycles/sec with internal 8 MHz clock, 5 M ins cycles/sec with external 20 MHz (max datasheet frequency).
> You'll also need to become comfortable with reading the data sheets. You > won't be able to do much with the device if you can't read the data sheet.
Amen. I find Microchip to have some of the better data sheets. -- Thad
Thanks for the replies.

Firstly, here's why I think my chip is running at 4 MHz: I downloaded
some delay routine code from the Microchip website. In the header of
the code, they give the following assurance: "You can trust these
routines - these delay routines were used successfully in a commercial
product with over 2 years of development and 7000 lines of code". In
order to use the code, you've to define a preprocessor directive
called PIC_CLK. I had to set this to 4000000 to get the timing right
(I tested it with a Piezo speaker).

Anyway, since the internal oscillator is 8 MHz, and since the CPU runs
at the clock rate, shouldn't I be able to get it to run at 8 MHz? If I
indeed *can* get it to run at 8 MHz, then would this be done in the
configuration flags, or would I do it in the code in main?

One thing I'm curious about: Since the microcontroller only has two
internal oscillators (one being the 8 MHz, and another being 31 kHz),
how could it be that I'm getting the chip to run at 4 MHz? I was
wondering if maybe the delay routine code assumed that an instruction
took 2 cycles (rather than one cycle)? I'll look into it.

I've also been reading about the OSCTUNE register, which I can use to
get a 12% boost on the 8 MHz oscillator. I think it has to be set a
runtime tho, (as opposed to in static storage like the configuration
flags):

int main(void)
{
    OSCTUNE = 0b1111;   /* Run the oscillator at maximum */

    return 0;
}

(Yes I realise I'll have to tweak the dealy routines if I tweak the
clock)


Tom�s � h�ilidhe wrote:
> Thanks for the replies. > > Firstly, here's why I think my chip is running at 4 MHz: I downloaded > some delay routine code from the Microchip website. In the header of > the code, they give the following assurance: "You can trust these > routines - these delay routines were used successfully in a commercial > product with over 2 years of development and 7000 lines of code". In > order to use the code, you've to define a preprocessor directive > called PIC_CLK. I had to set this to 4000000 to get the timing right > (I tested it with a Piezo speaker). > > Anyway, since the internal oscillator is 8 MHz, and since the CPU runs > at the clock rate, shouldn't I be able to get it to run at 8 MHz? If I > indeed *can* get it to run at 8 MHz, then would this be done in the > configuration flags, or would I do it in the code in main? > > One thing I'm curious about: Since the microcontroller only has two > internal oscillators (one being the 8 MHz, and another being 31 kHz), > how could it be that I'm getting the chip to run at 4 MHz? I was > wondering if maybe the delay routine code assumed that an instruction > took 2 cycles (rather than one cycle)? I'll look into it. > > I've also been reading about the OSCTUNE register, which I can use to > get a 12% boost on the 8 MHz oscillator. I think it has to be set a > runtime tho, (as opposed to in static storage like the configuration > flags): > > int main(void) > { > OSCTUNE = 0b1111; /* Run the oscillator at maximum */ > > return 0; > } > > (Yes I realise I'll have to tweak the dealy routines if I tweak the > clock) > >
It is set to 4Mhz because that is what the data sheet says is the default. You can play with OSCTUNE. OSCCON is the one you want you can set set the chip to 8Mhz. The internal OSC has a divider control That is how it gets 4Mhz ( or 2 or 1 or .5mhz) "INTIO" as I recall gives you Internal OSC with IO. There is an Oscillator section in the Data sheet. Since your config looks like Hi-tech C Not that any delay loop whitten in C may change with different versions of the compiler. Either faster or slower. Or, they may not.
Neil wrote:

> It is set to 4Mhz because that is what the data sheet says is the > default.
I would have thought that a microcontroller manufacturer would want their chips to run at maximum speed by default?
> You can play with OSCTUNE. =A0OSCCON is the one you want you can > set set the chip to 8Mhz. =A0The internal OSC has a divider control That > is how it gets 4Mhz ( or 2 or 1 or .5mhz) "INTIO" as I recall gives you > Internal OSC with IO. =A0There is an Oscillator section in the Data sheet.=
Here's what I've got so far: #define CrankTheSpeed() ((void)(OSCCON |=3D 0b1110000,OSCTUNE =3D 0b1111)) I wonder if there's anything else I can do to get maximum speed out of it (using the internal clocks, that is).
> Since your config looks like Hi-tech C Not that any delay loop whitten > in C may change with different versions of the compiler. =A0Either faster > or slower. =A0Or, they may not.
Yeah I might try find delay routines written in assembler.
<SNIP>
> > > Yeah I might try find delay routines written in assembler. >
Or you could just write a little code on your own... RB
Tom&#4294967295;s &#4294967295; h&#4294967295;ilidhe wrote:
> Neil wrote: > >> It is set to 4Mhz because that is what the data sheet says is the >> default. > > > I would have thought that a microcontroller manufacturer would want > their chips to run at maximum speed by default? > > >> You can play with OSCTUNE. OSCCON is the one you want you can >> set set the chip to 8Mhz. The internal OSC has a divider control That >> is how it gets 4Mhz ( or 2 or 1 or .5mhz) "INTIO" as I recall gives you >> Internal OSC with IO. There is an Oscillator section in the Data sheet. > > > Here's what I've got so far: > > #define CrankTheSpeed() ((void)(OSCCON |= 0b1110000,OSCTUNE = 0b1111)) > > I wonder if there's anything else I can do to get maximum speed out of > it (using the internal clocks, that is). > > >> Since your config looks like Hi-tech C Not that any delay loop whitten >> in C may change with different versions of the compiler. Either faster >> or slower. Or, they may not. > > > Yeah I might try find delay routines written in assembler. >
No they wanted backward compatibility in this case. I am sure the C delays work, They rock solid statement is a little much. Microchip makes or CPUs with a faster internal clock.