these K series are a pain

Status
Not open for further replies.

MrDEB

Well-Known Member
need to use an 18F43k20 but can't get an led to blink unless I use a different DEVICE in my code.
Maybe not a big deal but??
seems to work as planned using this header
DEVICE = 18F4321 ' using 18f43K20 but will only work when using device = 18f4321
CLOCK = 8
INCLUDE "IntOSC8.bas"
'INCLUDE "InternalOscillator.bas"
INCLUDE "Utils.bas"
INCLUDE "SetDigitalIO.bas"
not real worried but hopefully just using a blinking led should indicate if code executes correctly.
this is a battery operated project and have a diode in series to lower the Vdd when battery is used (have done this before with no issues).
 
Pretty sure I have the updated module. It has the 18f43K20 in its list. Will download again as it might be the wrong version. and yes I am using internal osc. as seen in my header
INCLUDE "IntOSC8.bas"
I should remove the unused one.
 
The k-series are great parts, and they are cheap (which I am sure is why you are using one of them). As Tumbleweed said, you need the updated include files for Swordfish from the Swordfish forum.

The fact that Swordfish recognizes the device doesn't mean that the device files and include files are up to date.

Please do understand that the device and include files above have nothing to do with the PICkit. That is an entirely different subject.


The difficulty in using K-series parts with Swordfish is because of the way these chips handle certain things. The include files haven't always accounted for these differences. Thanks to the hard work of Jerry and others at the Swordfish forum, many of the include files have been updated. This is a continuing process as problems are found and new parts come out. Swordfish Basic does have the advantage that the include files are written in Swordfish. Technically competent users are able to update the include files when special cases arise.
 
I downloaded the posted new file and hopefully get the project etc. to play nice.
been hassling all morning with cell phone company trying to get our new flip phones activated and purchasing some supples to build a bunch of whirligigs for upcoming craft fair.
 
Well I downloaded the suggested setalldigital v 2.2 & the intosc.bas module as well.
Both have the 18F43K20 listed in the modules
Only way to blink an LED is using18F4321 in the device header using my present code thus a simple striped down code is worth a try.
going to write a simple code just blinking one LED and maybe the orginal code has something wrong in it preventing the 18F43K20 from performing correctly??
 
very simple code for blinking an led
tried 18F4320 = unsupported device
18f43k20 = led does not blink
18f4321 = led blinks correctly
something is really screwy. I wonder if an 18f4321 even exists??
went to microchip and yes an 18f4321 does exist. in the hi-tech compiler it lists both in same paragraph>
could they both be basically same chip but one is a K version???
 
Well, you have somehow managed to select one of the worst of the K-series chips. I don't suppose you happened to set the PICkit 2 to 18F4321 as well? If so, did you happen to notice the PICkit was supplying 5 volts to a 3.3 volt part? So much for magic smoke.

Most assuredly, your software will fail in unique and exciting ways if you've specified the wrong device. You can be certain of this. Also, it's pretty clear you have something wrong. In your code. In the device and include files. Most likely in all of the above - sorry to be brutally blunt, but your previous adventures speak for themselves.

The 18F24/25/26K22 is my goto chip. The 44/45/46K22 is the 40 pin version. Very reliable for me and 60 wake turbulence timers in use in control towers around the northwest will attest to the fact.
 
could they both be basically same chip but one is a K version???
No, they're very different.

As Jon said, using another device selection to program a 43K20 is a disaster waiting to happen (so what else is new?)

Post the EXACT code you tried to use with the 43K20. Quit flopping things around... you'll just make it worse.
 
here is my led blink test code. Can only get it to blink using 18f4321
The pickit2 is on auto detect and outputting 3.3 volts and it says 18f43K20
I looked over the include modules and they include the 18f43K20 in them.
I have another chip I can try as a last resort. Am using a dip for testing but in the final design going to use the TQFP VERSION.
Even wondered if the diode in series with Vdd has an issue??
 
Finally got the correct device to run. I recall my Christmas matrix project and having to include CONFIG BOREN = OFF
This simple include seems to have solved the device issue
 
Include this block for K-series parts. Put it immediately after the device statement, before any includes.

Please don't go mucking about changing things you don't understand.

Code:
Config   'for K-series device
    FOSC = HSHP ,'HS oscillator (high power > 16 MHz)
    PLLCFG = Off ,'Oscillator used directly
    PRICLKEN = Off ,'Primary clock can be disabled by software
    FCMEN = Off ,'Fail-Safe Clock Monitor disabled
    IESO = Off ,'Oscillator Switchover mode disabled
    'PWRTEN = Off ,'Power up timer disabled
    PWRTEN = on ,'Power up timer enabled

    BOREN = Off ,'Brown-out Reset disabled in hardware and software
    'BOREN = on ,'Brown-out Reset enabled
    BORV = 285 ,'VBOR set to 2.85 V nominal
    WDTEN = Off ,'Watch dog timer is always disabled. SWDTEN has no effect.
    WDTPS = 256 ,'1:256
    PBADEN = Off ,'PORTB<5:0> pins are configured as digital I/O on Reset
    HFOFST = Off ,'HFINTOSC output and ready status are delayed by the oscillator stable status
    MCLRE = EXTMCLR ,'MCLR pin enabled, RE3 input pin disabled
    STVREN = On ,'Stack full/underflow will cause Reset
    'LVP = On ,'Single-Supply ICSP enabled if MCLRE is also 1
    LVP = Off ,'Single-Supply ICSP disabled
    XINST = Off ,'Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Debug = Off'Disabled
 
I tried suggestion but won't compile. Makes some sense but can't compile
 
Since you have including not a hint of what went wrong, how do you expect anybody to help you?

You might try the little-known and rarely discussed trick of professional programers. Delete every seventh line of code and try again. The explanation of why this often works is quite complex but it has to do with programmer attention span and compiler latency. I believe there's a detailed reference on ST Mirco's website but it may take some searching to find it. Don't confuse this with the rule of 13s, which applies only to assembly language programming - it's a totally different concept.
 
The clock statement should be above the config block too, not below it.
 
Since you're running on batteries you may want to enable the BOR so that when the voltage drops too low the chip will remain reset.
Setting
Code:
Config
   BOREN = SBORDIS,
   BORV = 18
will turn it on, and reset below 1.8V

What's the diode there for?
 
the diode is to drop the 4.5v down to 3.5v apx. The pic runs on 1.8-3.6v.
any voltage less than say 2v the leds would be pretty dim so drown out might be useless BUT will include in code just in case THANKS
Plan to use the HLVD feature of the chip with two Leds to indicate battery condition.
As for what went wrong (post#15) the code won't compile. Every line comes up an error.
 

And as I said, move the clock statement to just after the device statement.

When troubleshooting, the exact error messages are kind of helpful. You know, essential like.
 
error says "identifier not declared:fosc"
basically the same for all added code.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…