View previous topic :: View next topic |
Author |
Message |
jmaudley
Joined: 01 Feb 2011 Posts: 32 Location: 53
|
Clock speed issue PIC18F46K22 at power-up |
Posted: Tue Sep 09, 2014 4:31 am |
|
|
I have a problem with the clock speed after power-up.
I have a simple flashing LED program 50ms on and 400ms off.
When I program using the ICD programmer everything is fine. The LED flashes at the correct frequency and I can send debug messages via RS232.
When I power off/on it would appear that the clock frequency doesn't set correctly which results in my 50ms LED on period changing to 500ms (x10).
This also messes up the baud rate and corrupts the RS232 debug messages.
My fuses are:
#fuses ECL,NOLVP,NOWDT,PLLEN,PUT
#use delay (clock=10M, oscillator=2.5M)
I'm taking an external clock from an MCP2515 CAN chip which provides 2.5Mhz (divided by 8 from 20mhz).
I'm using the PLL x4 clock.
I have SPI and CAN on the board and this all works when programmed but not after a power-up.
I'm clearly not understanding something about the clock configuration at power-up but I'm struggling to understand what the difference is between a power-up and a re-program.
Any assistance would be appreciated. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Sep 09, 2014 5:22 am |
|
|
Probably need to recompile your program with the 'build configuration' set to 'release' NOT 'debug' when using MPLAB.
You can set the default to 'release' to avoid this..
hth
jay |
|
|
neochrome32
Joined: 09 Jun 2013 Posts: 153
|
|
Posted: Tue Sep 09, 2014 6:10 am |
|
|
try this...
Code: |
#include <18F46k22.h>
#DEVICE *=16
#FUSES MCLR
#FUSES PRIMARY_ON
#FUSES NOWDT
#FUSES NOPROTECT
#FUSES NODEBUG
#FUSES PLLEN //Ineternal 16MHz + PLL(4)
#FUSES INTRC_IO
#fuses NOIESO
#FUSES NOSTVREN //Stack full/underflow will cause reset
#FUSES NOPBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPB //No Boot Block code protection
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NODEBUG
#FUSES NOXINST
#use delay(clock=64M)
|
Just ensure you have a good Volt Reg, this turned out to be a deal breaker |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Tue Sep 09, 2014 7:29 am |
|
|
The PLL is only designed to accept 4MHz - 16MHz in. Check section 2.8 of the data sheet. |
|
|
jmaudley
Joined: 01 Feb 2011 Posts: 32 Location: 53
|
Explanation of ICD=TRUE |
Posted: Tue Sep 09, 2014 10:09 am |
|
|
Thanks for your responses.
I seem to have it working but I'm just trying to understand why this has seemingly fixed it.
I've added #device ICD=TRUE which makes it work.
What is ICD=TRUE doing that fixes my timing issues?
By the way I'm not using microchips ICD debugger.
I'm using the ICD-U64 CCS programmer and CCS compiler.
I'm up and running but I would like to understand why. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 09, 2014 10:36 am |
|
|
Quote: | What is ICD=TRUE doing that fixes my timing issues? |
If you were compiling in Release mode, adding #device ICD=TRUE will
change it to Debug mode. This will automatically change some of the
fuse settings to be compatible with Debug mode. You can see these
fuse differences by looking at the compiled fuse settings at the end of
the .LST file.
But as previously mentioned, if you are still putting 2.5 MHz into the PIC
from the MCP2515 and using the PLL, you are violating the spec. The
18F46K22 data sheet says:
Quote: |
2.8.1 PLL IN EXTERNAL OSCILLATOR MODES
The PLL can be enabled for any of the external
oscillator modes using the OSC1/OSC2 pins by either
setting the PLLCFG bit (CONFIG1H<4>), or setting the
PLLEN bit (OSCTUNE<6>). The PLL is designed for
input frequencies of 4 MHz up to 16 MHz. The PLL then
multiplies the oscillator output frequency by four to
produce an internal clock frequency up to 64 MHz.
Oscillator frequencies below 4 MHz should not be used
with the PLL. |
These comments are reiterated in the table in this section:
Quote: | TABLE 27-8: PLL CLOCK TIMING SPECIFICATIONS |
18F46K22 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/41412F.pdf
Quote: | When I power off/on it would appear that the clock frequency doesn't set correctly which results in my 50ms LED on period changing to 500ms (x10). |
This suggests that the PIC is switching to the internal oscillator, most
likely because it doesn't like your out-of-spec PLL input frequency. |
|
|
jmaudley
Joined: 01 Feb 2011 Posts: 32 Location: 53
|
|
Posted: Wed Sep 10, 2014 1:37 am |
|
|
Understood.
I clearly need to resolve my clock issue.
Thank you. |
|
|
|