Swordfish

Structured BASIC for PIC® Microcontrollers
It is currently Wed May 22, 2019 2:53 am

All times are UTC




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: 18f24K40
PostPosted: Sat Jun 10, 2017 2:20 pm 
Offline

Joined: Sun Feb 03, 2013 2:26 am
Posts: 18
Location: Salmon, Idaho
this is a new chip?? but can SF / pickit2 even deal with it. I see no modules etc such as setalldigital. Am I digging a hole and no way out.
This pic for cost is only $1.50 from Mouser. Only reason I am considering using this pic.
Might run and use the 18f2221 but??
I have no need for lots of bells n whistles just a pic w/ HLVD and limited ram

_________________
I miss backpacking the Sierras


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sat Jun 10, 2017 3:30 pm 
Offline
Registered User
Registered User

Joined: Fri Jan 30, 2009 6:27 pm
Posts: 1087
Location: US
You can get it to work with SF but it'll take downloading mplabx from microchip and doing a little swapping of files.
You can get the device files here (along with an updated SetAllDigital), but you need the assembler from mplabx, which is a huge download just to get mpasmx.

See the following pages for more info if you're interested:
SetDigitalIO
SystemConvert
mpasmx_5.71_device_files.zip

As far as getting it to work with a pickit2 unfortunately I think you're out of luck there. I don't know of any updated files for that. It does work with the pickit3, but you'll need to use all the mplabx programs/utilities and none of the old standalone apps to program it.

All this is a lot of work, and it's hard to recommend doing it unless you're comfortable with messing with all the files.
Personally I'd recommend an 18F2xK22. They're not quite as cheap as the K40, but they're supported by all the existing tools.
They do have a lot of 'bells and whistles' but newer chips tend to be cheaper than the older ones.


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sat Jun 10, 2017 7:14 pm 
Offline

Joined: Sun Feb 03, 2013 2:26 am
Posts: 18
Location: Salmon, Idaho
Thanks Jerry
I have several 18f24K22 that work but seem slow. Why I have no idea. Checked the osscilator setting etc. he nly way I can get it running half way decent is to use INTOSC8.bas. The InternalOscillator.bas won't work, or at least I don't see the device listed in the module.
Will proceed with the 18f24K22 or the 18lf2221.

_________________
I miss backpacking the Sierras


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sat Jun 10, 2017 8:04 pm 
Offline

Joined: Sun Feb 03, 2013 2:26 am
Posts: 18
Location: Salmon, Idaho
It pays to shop
the 18f24K22 at Mouser = $2.50 Digi-key = $2.14
now just need to order and write code for it. Maybe the SetDigitalIO.bas module will work better??

_________________
I miss backpacking the Sierras


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sat Jun 10, 2017 9:17 pm 
Offline
Registered User
Registered User

Joined: Fri Jan 30, 2009 6:27 pm
Posts: 1087
Location: US
That chip will run up to 64MHz using the internal osc, so it's plenty fast.

If you post your copy of InternalOscillator.bas I'll take a look and make sure it'll support the 2xK22 for you. I think that was an older file, maybe from Digital DIY?

The SetDigitalIO page has updated files for the SetAllDigital routine, but that won't do anything for the clock speed. That's a separate issue.


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sat Jun 10, 2017 11:20 pm 
Offline
Registered User
Registered User

Joined: Sat Oct 09, 2010 1:39 pm
Posts: 122
Location: United Kingdom
If it's any help then there is a good article on the wiki which covers how to set the internal OSC, the article is for a 18F25K22 but should be the same for the 18F24K22.

http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.ProgrammingThePIC18F25K22OscillatorWithSwordfish


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sun Jun 11, 2017 12:17 pm 
Offline

Joined: Sun Feb 03, 2013 2:26 am
Posts: 18
Location: Salmon, Idaho
Thanks guys, the link that bitfogav posted a link to shed some light on what and why my project using a K pic seems slow.
Will go back and review what I have as well as the setalldigital.bas.
Yes the setalldigital was from Diy. but looking over the code it has the 24K22
Code:
  // 18FxxK20 family (no LF versions)
  #elseif _device in (18F23K20, 18F24K20, 18F25K20, 18F26K20, 18F43K20, 18F44K20, 18F45K20, 18F46K20)
    ANSEL = $00
    ANSELH = $00
    CM1CON0 = 0
    CM2CON0 = 0
    SLRCON = _SLR               // added V1.8
   

_________________
I miss backpacking the Sierras


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sun Jun 11, 2017 12:44 pm 
Offline

Joined: Sun Feb 03, 2013 2:26 am
Posts: 18
Location: Salmon, Idaho
now I an't get it to compile. I screwed something up??
Code:
DEVICE = 18F24K22     
   CLOCK = 8            '8MHz
   CONFIG FOSC = INTIO7   'internal oscillator
   OSCCON = %01011100     ' how fast to run
#option SWORDFISH_SE = true
INCLUDE "SetDigitalIO.bas"
INCLUDE "Utils.bas" 

 DIM led AS PORT b.0
 
 WHILE true
       led = 1
       DELAYMS(1000)
       TOGGLE (led)
       DELAYMS(500)
 WEND     

_________________
I miss backpacking the Sierras


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sun Jun 11, 2017 1:33 pm 
Offline
Registered User
Registered User

Joined: Sat Oct 09, 2010 1:39 pm
Posts: 122
Location: United Kingdom
The SetDigitalIO library has been updated since the DIY version which is compatible with the 18F24K22 or the K22 series of mcu's..
You need to download the latest version and put that in the same folder as your programme or put it in the Swordfish userLibrary folder.

http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.SetDigitalIO


As for your code you need to change it to this: (note I've not tested the code, but it compiles).
Code:
Device = 18F24K22     
   Clock = 8            '8MHz
   Config FOSC = INTIO7   'internal oscillator   

#option SWORDFISH_SE = true
Include "SetDigitalIO.bas"
Include "Utils.bas" 

 Dim led As Portb.0              ' <- changed this for correct port
 
 OSCCON = %01100100          ' <- moved this here and changed this for 8Mhz Int clock
 
 While true
       led = 1
       DelayMS(1000)
       Toggle (led)
       DelayMS(500)
 Wend


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sun Jun 11, 2017 1:57 pm 
Offline
Registered User
Registered User

Joined: Fri Jan 30, 2009 6:27 pm
Posts: 1087
Location: US
You're mixing up the order of executable statements, includes, and variable declares.
Some of those have to be done before any executable statements.

1). make sure you're using the SetDigitalIO file from here:
http://www.sfcompiler.co.uk/wiki/wiki-uploads/SwordfishUser/SetDigitalIO/SetDigitalIO_v22.zip

inside the zip file you'll find SetDigitalIO.bas
put it in your user library folder

when you go to use it you must add a 'SetAllDigital' statement

2). I've attached a zip file with an updated version of "InternalOscillator.bas" that supports the K22
inside the zip you'll find "intosc.bas" (I've renamed the file as "intosc.bas" so it won't overwrite your old original DDIY one).

put it in your user library folder

(NOTE: the zip file has been updated and moved to http://www.sfcompiler.co.uk/wiki/pmwiki ... ser.IntOSC)

to use it all you have to do is add
Code:
include "intosc.bas"
to the start of your code

Unlike setalldigital, it'll add all the code to setup the osc automatically.

3). try this test code:
Code:
DEVICE = 18F24K22     
CLOCK = 8            '8MHz

INCLUDE "intosc.bas"
INCLUDE "SetDigitalIO.bas"

 DIM led AS PORTb.0

 SetAllDigital()

output(led)
 
 WHILE true
       TOGGLE (led)
       DELAYMS(1000)
 WEND   


Last edited by Jerry Messina on Sat Jun 17, 2017 3:15 pm, edited 1 time in total.
remove zip file... now on wiki IntOSC page


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sun Jun 11, 2017 5:47 pm 
Offline

Joined: Sun Feb 03, 2013 2:26 am
Posts: 18
Location: Salmon, Idaho
Thanks, I thought I didn't have the INCLUDE modules in the right folder but after looking at your example I see my mistake.
Now to order the 10 chips SMD and one in a dip for testing my code for proper functioning HLVD etc.
was slightly worried why it wouldn't compile. Need to make some changes to the code for the 18f22k20 boards I have. Could be why it starts slow.

_________________
I miss backpacking the Sierras


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Sun Jun 11, 2017 8:54 pm 
Offline

Joined: Sun Feb 03, 2013 2:26 am
Posts: 18
Location: Salmon, Idaho
Looks like a slight change in part number. Instead of the 18f24K22 going with the 18f24K20. Cheaper at mouser for 10 units plus I happen to have several of these puppies on hand.
Onward to locating white leds and writing code to include the HLVD

_________________
I miss backpacking the Sierras


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Mon Jun 12, 2017 12:37 am 
Offline

Joined: Sun Feb 03, 2013 2:26 am
Posts: 18
Location: Salmon, Idaho
got the "simple" code done involving the HLVD section but got to wondering if the HLVDCON value be changed using a sub route. Is what I am contemplating is having the LOW voltage detect LED0 blink at a faster rate as the battery goes lower. In this code (haven't calibrated the pickit2 voltage but the led0 starts blinking at 3.1 volts).
I could use the external voltage input but pcboards are in the mail.
Going to experiment using a subroutine to change the HLVDCON value
Code:
 DEVICE = 18F24K20   
CLOCK = 8            '8MHz

INCLUDE "intosc.bas"
INCLUDE "SetDigitalIO.bas"
INCLUDE "Utils.bas"
DIM led0 AS PORTb.0
dim led1 as portb.1

OUTPUT(led0)
output (led1) 
hlvdcon= %00011100
pir2.bits(2)=0
pie2.bits(2)=1
intcon.bits(7)=1
led0= 0
SetAllDigital()


 
 WHILE true
 if pir2.bits(2)=1 then // check hlvd interrupt
    led0 = 0
    delayms(500)
    led0=1
    delayms(500)
    pir2.bits(2) =0  //clr interrupt
    else
    led0=1
    endif
    toggle(led1)
             DELAYMS(1000)
 WEND         

_________________
I miss backpacking the Sierras


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Mon Jun 12, 2017 9:39 am 
Offline
Registered User
Registered User

Joined: Fri Jan 30, 2009 6:27 pm
Posts: 1087
Location: US
Two suggestions...

Since you're polling the HLVDIF and not using interrupts, don't mess with the interrupt enable bits.
You can still poll the PIR flags to see if they get set.

Secondly you want to call SetAllDigital before you start using the IO pins.
Code:
SetAllDigital()     <<<< put this first
OUTPUT(led0)
output (led1)
hlvdcon= %00011100
pir2.bits(2)=0
pie2.bits(2)=1       <<<<< remove this
intcon.bits(7)=1    <<<<<< and this
led0= 0


Quote:
I could use the external voltage input
When you use the external HLVDIN pin you can't change the trip point. In this mode the voltage at the pin is compared to a fixed 1.2V reference. To change it you have to use external resistors to divide the input voltage.


Top
 Profile  
Reply with quote  
 Post subject: Re: 18f24K40
PostPosted: Mon Jun 12, 2017 2:34 pm 
Offline

Joined: Sun Feb 03, 2013 2:26 am
Posts: 18
Location: Salmon, Idaho
Thanks Jerry.
Will make suggested changes

_________________
I miss backpacking the Sierras


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group