View previous topic :: View next topic |
Author |
Message |
povulon
Joined: 10 Jan 2018 Posts: 4
|
PLL 40 mhz with 18f452 |
Posted: Wed Jan 10, 2018 2:40 pm |
|
|
Hi
I have a 18f452 20 mhz pic.
I want to run it at 40 mhz osc by using 10 mhz crystal.
How I write this program in ccs c ?
Please help me. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Jan 10, 2018 3:06 pm |
|
|
Code: |
#include <18F452.h>
#fuses H4, NOLVP, NOWDT, NOPROTECT
//Add other fuses you need
#USE DELAY (CLOCK=40MHz)
void main(void)
{
//with a suitable 10MHz crystal, chip is now running 40Mhz
while (TRUE)
{
output_toggle(PIN_B0); //test by toggling pin 1/second
delay_ms(1000);
}
}
|
|
|
|
povulon
Joined: 10 Jan 2018 Posts: 4
|
|
Posted: Fri Nov 23, 2018 3:19 am |
|
|
Ttelmah wrote: | Code: |
#include <18F452.h>
#fuses H4, NOLVP, NOWDT, NOPROTECT
//Add other fuses you need
#USE DELAY (CLOCK=40MHz)
void main(void)
{
//with a suitable 10MHz crystal, chip is now running 40Mhz
while (TRUE)
{
output_toggle(PIN_B0); //test by toggling pin 1/second
delay_ms(1000);
}
}
|
|
Thank you for your answer
I loaded this program to 18f452 pic
but led on time is 4 second
led off time is 4 second
there is a problem ?? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Fri Nov 23, 2018 4:08 am |
|
|
You have a 10MHz crystal?.
Most likely thing is your programmer is not setting the fuses.
Depends on what you are using to program, but in CCSLoad, you need the tickbox in 'options', 'config bits', turned on. |
|
|
povulon
Joined: 10 Jan 2018 Posts: 4
|
|
Posted: Fri Nov 23, 2018 5:45 am |
|
|
Ttelmah wrote: | You have a 10MHz crystal?.
Most likely thing is your programmer is not setting the fuses.
Depends on what you are using to program, but in CCSLoad, you need the tickbox in 'options', 'config bits', turned on. |
I use 10 mhz crystal
I use ccs c program version 5.042
I cant see config bit in options |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Fri Nov 23, 2018 6:08 am |
|
|
You need to tell us what program and programmer you're using to actually download your code to the PIC.
IE I use CCS to make the code, MPLAB to send it to the PICKIT3 that the PIC is attached to.
I suspect 'something' is overriding the FUSES settings in your code, either the programmer or the IDE.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 23, 2018 9:02 am |
|
|
povulon wrote: |
I loaded this program to 18f452 pic
but led on time is 4 second
led off time is 4 second
there is a problem ??
|
Turn the power off on the 18F452 board, then turn it on again.
The PLL should now be running. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Fri Nov 23, 2018 9:40 am |
|
|
I must admit I was assuming from the long timescale involved in the thread,
that the board would have been powered down at least once since starting
trying...
Key point being made here is that the PLL only actually loads from the fuses
when the chip is booted. So if the fuses are correctly programmed it needs
then to be switched off before the PLL will start to work... |
|
|
povulon
Joined: 10 Jan 2018 Posts: 4
|
|
Posted: Sun Nov 25, 2018 1:37 am |
|
|
Ttelmah wrote: | I must admit I was assuming from the long timescale involved in the thread,
that the board would have been powered down at least once since starting
trying...
Key point being made here is that the PLL only actually loads from the fuses
when the chip is booted. So if the fuses are correctly programmed it needs
then to be switched off before the PLL will start to work... |
I use pickit 2 programmer
I try to this program on proteus
Led on is 1 second
led off is 1 second
The program works on proteus
but when I loaded my 18f452 pic, the program works very slowly |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Nov 25, 2018 2:00 am |
|
|
'What software' are you using to drive the Pickit2?. MPLAB?. MPLAB-X. PicKitPlus?. MicroChip's old PicKit 2 software?. What release?.
If using MPLAB you need to set this to 'load configuration from code'. This is an option at the top of the 'configuration bits' window. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Nov 25, 2018 6:09 am |
|
|
re: the program works very slowly
What xtal and cap values have you connected to the PIC and on which pins ?
Do you have anything connected to sec. osc pins ?
Also, show us your complete version of the '1Hz LED' program.
The #FUSES line of code is vital to see !!
We need this information to properly help you.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Nov 26, 2018 3:59 am |
|
|
and (preferably), a source/part number for the actual crystal. Ideally also read
the revision ID from the PIC with the programmer, and post this.
The 18F452, is a very old chip. It is 'not recommended for new designs' (has
been superseded by the 4520). Now suggests possibly this has come from
some 'old stock' somewhere. There were hardware issues with the earliest
452's, which meant they would commonly overdrive the oscillator input unless
a series resistor was used. However this only applied to the very earliest chip
revisions. The last erratum update for this chip, was in 2005.
Now if you are working with a really old chip, it is possible yours has this
problem. However these have not been made for years (about 16 years!...).
B1/B2 revision ID's. About 2001/2002 release date. After this time the PLL
became much more reliable, and should work with any normal parallel mode
crystal.
I have to ask 'why' you are trying to use such an old chip, but it should work. |
|
|
|