View previous topic :: View next topic |
Author |
Message |
Andreas
Joined: 25 Oct 2004 Posts: 136
|
PIC16F1718 Oscillator |
Posted: Tue Oct 06, 2015 12:31 pm |
|
|
Hello Friends
I'm changing the PIC to the PIC16F1718 and having trouble with the oscillator settings.
I am doing this:
Code: |
#use delay(clock=8000000)
void main()
{
setup_oscillator(OSC_8MHZ| OSC_INTRC );
output_low(Mode);
while(TRUE)
{
output_low(LED1);
output_low(Mot1A);
delay_ms(100);
output_high(Mot1A);
output_high(LED1);
delay_ms(100);
}
}
|
This will create a perfect 100ms output pulse !
BUT when changing to this:
Code: | #use delay(clock=32000000)
setup_oscillator(OSC_8MHZ| OSC_INTRC | OSC_PLL_ON); |
I get a 400ms output pulse !
BUT this works also ok !
Code: | #use delay(clock=16000000)
setup_oscillator(OSC_16MHZ| OSC_INTRC ); |
Any idea what I am doing wrong ?
Best regards
Andreas |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19792
|
|
Posted: Tue Oct 06, 2015 1:11 pm |
|
|
Look at the oscillator diagram.
Note how if you select the PLL, the input that needs to be selected using SCS1:0, is the '00' OSC input (the normal oscillator input), _not_ the internal oscillator input!.
You can't retro select this if you have booted with another primary oscillator. It has to be setup as the primary oscillator. |
|
 |
Andreas
Joined: 25 Oct 2004 Posts: 136
|
|
Posted: Tue Oct 06, 2015 11:52 pm |
|
|
Hello Ttelmah
Thank you for the fast reply!
I found one mistake, I was setting the FUSE RC at the beginning, so I couldn't change the osc type.
I tried your suggestion, but this gives me a 400ms Delay ????:
Code: |
#use delay(clock=32000000)
setup_oscillator(OSC_8MHZ| OSC_NORMAL | OSC_PLL_ON);
|
It looks like the PLL is not enabled.
One idea more ???
best regards
Andreas |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19792
|
|
Posted: Wed Oct 07, 2015 1:37 am |
|
|
You need the INTRC_IO fuse. This should work:
Code: |
#include <16F1718.h>
#fuses INTRC_IO
#fuses NOWDT
#fuses NOMCLR
#fuses NOWDT
#fuses NOCLKOUT
#fuses NOLVP
#use delay (INTERNAL=32MHz)
void main(void)
{
setup_oscillator(OSC_8MHZ| OSC_NORMAL | OSC_PLL_ON);
while(TRUE)
{
output_toggle(PIN_A0);
delay_ms(100);
}
}
|
Basically if you look at figure 6-1 in the data sheet, you need the line that gives PRIMUX=1, and PLLMUX=1. This only happens when you have OSCCON=0b11110000, and FOSC<2:0> (in the config fuses) has to be 0b100. I've compiled this, and it sets both these registers correctly on the current compilers. |
|
 |
Andreas
Joined: 25 Oct 2004 Posts: 136
|
|
Posted: Wed Oct 07, 2015 4:18 am |
|
|
Hello Ttelmah
Thanks a lot for your suggestion, that was the trick !!!
It looks that in the CCS Compiler this is not covered with the OSC settings line.
For my opinion this should be automatically set if I want 8Mhz with 4x PLL.
Many thanks and best regards.
Andreas |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19792
|
|
Posted: Wed Oct 07, 2015 4:29 am |
|
|
It is difficult, since most CPU's that allow this, allow it either to be fully setup in the fuses, or at run time. It's an 'awkwardness' that instead on this CPU it automatically selects this, only if all the other options are setup (this is the point about the diagram in the oscillator diagram), so you have to work out how to do all the settings shown. I'm sure once it's been around a little longer, it'll do it automatically if you just select 'internal=32MHz'. I'd suggest you point it out to CCS, and they'll probably implement it in the next release.  |
|
 |
Andreas
Joined: 25 Oct 2004 Posts: 136
|
|
Posted: Thu Oct 08, 2015 12:38 pm |
|
|
Hello Ttlemah
Thanks for Your help, it worls now in the correct frequency.
I will send a request to ccs about this Problem.
best regards
Andreas |
|
 |
|