View previous topic :: View next topic |
Author |
Message |
mob1182
Joined: 03 Mar 2016 Posts: 28
|
[Solved] CLKOUT problem on PIC18F47K40 |
Posted: Mon Dec 19, 2016 1:05 pm |
|
|
Hey everyone,
Either I am doing something wrong (most likely) or I have found a bug in the compiler but I wanted to get some opinions from some more experienced people than me. I am trying to use, for the first time, a PIC18F47K40. When I first got the chip I realized I had to upgrade my software as I had IDE v5.055 which didn't support this chip (I'm guessing it's a fairy new chip?). I now have 5.065. I'm also using the ICD-U64 with hardware Rev.3, software 5.035, firmware 3.19.
When I compile the code and program it with CCSLoad I do not get an output on pin 14 and under the file tab of CCSLoad, in the config/ID section, the box for "output clock on OSC2" is unchecked.
If I manually check this check box and re-save the hex it does work but I shouldn't have to be doing this, although it's not much of a problem to do this. But maybe I am overlooking something so here is my code
main.c
Code: |
#include "main.h"
//====================================================================
void main() {
while(1);
} |
main.h
Code: |
#include <18F47K40.h>
#device ADC=10
#FUSES NOEXTOSC //External Oscillator not enabled
#FUSES CLKOUT //Output clock on OSC2
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWDT,NOPROTECT
#use delay(internal=4MHz)
|
The hex file also changes on line 6. 6429 to 6428, and the last digit from 0 to 1(is this just a checksum?)
original hex
Code: |
:1000000002EF00F0818E819CF86AD09E0E01DD6BBC
:10001000DA6BDC6B020EDE6F600ED86F0F01116BB6
:10002000196B216B266B2E6B3A6B3B6B3C6B396B00
:0C003000366B376B386B356BFFD7030065
:020000040030CA
:0C000000642920BF1F3FFF170300FF0210
:00000001FF
;PIC18F47K40
;CRC=6F74 CREATED="19-Dec-16 13:06"
|
After checking the box and resaving
Code: |
:1000000002EF00F0818E819CF86AD09E0E01DD6BBC
:10001000DA6BDC6B020EDE6F600ED86F0F01116BB6
:10002000196B216B266B2E6B3A6B3B6B3C6B396B00
:0C003000366B376B386B356BFFD7030065
:020000040030CA
:0C000000642820BF1F3FFF170300FF0211
;PIC18F47K40
;CRC=950D CREATED="19-Dec-16 13:06" MODIFIED="19-Dec-16 13:07"
:00000001FF
|
The fuse CLKOUT is in the header file for the chip. My concern is that if this fuse isn't setting correctly, can I trust any of the fuse setting.
I am also having a problem programming anything more than 640 instructions of code with this programmer(Pickit 3 works when I load the hex into microchips IPE) but that is for another post.
Last edited by mob1182 on Tue Dec 20, 2016 1:21 pm; edited 2 times in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Mon Dec 19, 2016 1:13 pm |
|
|
As a general comment, since I don't use that PIC or ICD....
Fuses tend to be 'controlled' by the last link in the system, the programmer usually. IF you have 'debug' enabled..fuses get set some way, IF you have an ICD attached, it sets fuses some other way, If you use MPLAB, it deafults to 'debug' and sets them yet another way....
YOU have to tell all these things to 'get along' an do what YOU want.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Dec 19, 2016 1:38 pm |
|
|
I think you will find this is simply because the logic is reversed. The CLKOUT fuse setting, sets the CLKOUTEN bit. However the bit is a -ve logic bit, and actually has to be cleared to enable the clock out. |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Mon Dec 19, 2016 2:03 pm |
|
|
Quote: |
As a general comment, since I don't use that PIC or ICD....
Fuses tend to be 'controlled' by the last link in the system, the programmer usually. IF you have 'debug' enabled..fuses get set some way, IF you have an ICD attached, it sets fuses some other way, If you use MPLAB, it deafults to 'debug' and sets them yet another way....
YOU have to tell all these things to 'get along' an do what YOU want.
Jay
|
I was under the impression that CCSLoad just read the hex file created by the CCS IDE and set fuses according to that? I've never had to manually set the fuses outside the code before, using the menu in CCSLoad.
Quote: |
I think you will find this is simply because the logic is reversed. The CLKOUT fuse setting, sets the CLKOUTEN bit. However the bit is a -ve logic bit, and actually has to be cleared to enable the clock out.
|
So am I right to assume that this is a bug since the hex file created by the compiler should have this bit as a 0 instead of a 1? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Tue Dec 20, 2016 9:50 am |
|
|
Report it.
However never assume any fuse does what you want without checking. Always look at the end of the lst file, which shows exactly what is sent to the chip. There are dozens of fuses being set, and to assume they will have the right value, is a good way to give yourself headaches.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Dec 20, 2016 10:59 am |
|
|
Fuses... sigh... more fuses than PIC instructions these dayze !!
I finally created a 'fuse file' that I include. It has ALL the fuses set as I require, 1 per line that way I KNOW I have them right.....Also it 'cleans up' the 'main' program making it easier to see what's going on.
Once I get them right using the 1Hz LED program I save as a 'baseline' ,'good fuses', 'working fuses' file. Make a copy, then alter the copy for specific projects as required. that way I can ALWAYS go back to 'square one' and get the PIC running again.....
Jay |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Tue Dec 20, 2016 11:50 am |
|
|
That's a very good point I'll follow from now on. Thanks.
So with these fuses...
Code: |
#include <18F47K40.h>
#device ADC=10
#FUSES NOEXTOSC //External Oscillator not enabled
#FUSES CLKOUT //Clockout on Pin 14
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWDT //No Watchdog
#FUSES NOPROTECT
#use delay(internal=4MHz)
|
This is what the lst file has
Code: |
Configuration Fuses:
Word 1: 2964 NOEXTOSC RSTOSC_HFINTRC_4MHZ NOCLKOUT CKS FCMEN
Word 2: BF20 NOMCLR PUT NOLPBOR NOBROWNOUT BORV24 ZCDDIS PPS1WAY STVREN NODEBUG NOXINST
Word 3: 3F1F WDTSW NOWDT WDTWIN_SW WDTCLK_SW
Word 4: 17FF NOWRT NOWRTC NOWRTB NOWRTD SCANE NOLVP
Word 5: 0003 NOPROTECT NOCPD
Word 6: 02FF NOEBTR NOEBTRB
|
so it shows NOCLKOUT in the lst even though I set it in the header to CLKOUT.
I believe 2964 should be 2864.
Is there any way to change this in the IDE? |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
|
Posted: Tue Dec 20, 2016 12:02 pm |
|
|
Hey guess what, I added clock_out to the #use delay() and it now works lol
Code: |
#include <18F47K40.h>
#device ADC=10
#FUSES NOEXTOSC //External Oscillator not enabled
#FUSES CLKOUT //Clockout on Pin 14
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWDT //No Watchdog
#FUSES NOPROTECT
#use delay(internal=4MHz, clock_out)
|
Code: |
Configuration Fuses:
Word 1: 2864 NOEXTOSC RSTOSC_HFINTRC_4MHZ CLKOUT CKS FCMEN
Word 2: BF20 NOMCLR PUT NOLPBOR NOBROWNOUT BORV24 ZCDDIS PPS1WAY STVREN NODEBUG NOXINST
Word 3: 3F1F WDTSW NOWDT WDTWIN_SW WDTCLK_SW
Word 4: 17FF NOWRT NOWRTC NOWRTB NOWRTD SCANE NOLVP
Word 5: 0003 NOPROTECT NOCPD
Word 6: 02FF NOEBTR NOEBTRB
|
Just checked, it doesn't matter what the FUSE is set to at all. Even with NOCLKOUT. Just two different ways the compiler sets it I guess, with only 1 way working. |
|
|
mob1182
Joined: 03 Mar 2016 Posts: 28
|
[Solved] CLKOUT problem on PIC18F47K40 |
Posted: Tue Dec 20, 2016 1:21 pm |
|
|
Here is the response from CCS so it appears I was doing this incorrectly
Quote: |
When you use the internal=x option #use delay() sets the clock related configuration fuses for you, including the CLKOUT and NOCLKOUT fuses. The default setting is NOCLKOUT, to get it to set the CLKOUT fuses you need to specify CLOCK_OUT in the use delay() line. Because you didn't specify CLOCK_OUT in your #use delay() line the compiler over wrote your setting with the default setting.
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Tue Dec 20, 2016 1:56 pm |
|
|
This is the 'problem' of things like these shortcuts and also the wizard. They set things 'for you', with assumptions that may well be right 99% of the time, but for the 1%, then lead to problems....
So it'd have worked if you has specified the RC oscillator, and CLOCK=, rather than using the INTERNAL shortcut.
On your chip there are a whole suite of fuses which are 'relying' on things in the background (like NOXINST for example). Now the big problem with these is that they can change from version to version. Hence the 'set it all' solutions tend to be much less bother 'long term'.... |
|
|
|