PDA

View Full Version : Pic 18F26K40



Alberto
- 9th April 2018, 10:47
I have in mind a new project where I need two uarts com ports, so I did search microchip site and found the pic 18F26k40 to suite my need. As a second step I did check if my pbp3 (ver 3.09.4) was supporting this device and I discover that it doesn't! The closest one is 18F26K80 (wich is obsolete) while my melabs U2 programmer (ver 4.4) does list only 18F26K20.

How can I add this new device to my compiler and programmer?

Any help will be greatly appreciate.

Alberto

mpgmike
- 9th April 2018, 11:22
The easy fix is to spend the $50 and upgrade to PBP3.1. You must use Windows 7 or newer, can't use XP with 3.1.

Ioannis
- 9th April 2018, 11:38
Well, my 3.1.1.4 has support (maybe limited) for the K40 series.

Why not update your older version? If there is any cost I think is not too much.

Ioannis

Dave
- 9th April 2018, 11:54
I would like to ask, Why the 26K40? I would personally use an 18F26K22. It has been supported since PBP 3.0 I believe and it's still in production.

Alberto
- 9th April 2018, 12:16
Thank all for the quick reply! I will check @ melabs site how to update my pbp3. You didn't mention the U2 programmer. Does it upgrade automatically with the pbp3 upgrade?

@ Dave:

I did Selected the pic 18K family @ microchip site and the list obtained doesn't show the device you suggested (pic 18f26k22)

Alberto

tumbleweed
- 9th April 2018, 12:43
The closest one is 18F26K80 (wich is obsolete)No it's not. It's still in production.

The 18F2xK22 is your best bet. Many of the search tools on the mchip site are broken, or they default to showing you "new and popular products". The 18F2xK22 is one of the most popular in the whole K family but it doesn't show up until you "show all".

towlerg
- 9th April 2018, 14:54
Of all the oddities on microchips site one of the more annoying is that seach which only seems to work if you put PIC (like PIC18F26K22), maybe it's just my browser/VPN combo.

mpgmike
- 9th April 2018, 15:44
You didn't mention the U2 programmer. Does it upgrade automatically with the pbp3 upgrade?
Alberto
Yes. You must download it separately, though

Alberto
- 9th April 2018, 15:47
Thank you for pointing out that 18f26k22 is still in production! This will save me the money and trouble to update my pbp3 ( you never know how it will end up the update!). Additionally, the suggeted device has got more memory and is cheaper!

Yes the searching tools at microchip site are very poor indeed. Searching for the single product I found the 18f26k22 as currently in production!

I have placed the order for 10 units and hopefully will arrive to my place in two weeks. Then I will return here for some more help, since I never used two uarts on the same device, and I don't know how to set DT interrupt for the second uart.

So if somebody has a code snippet that shows how to set DT interrupt for the second uart and is willing to post it, I will appreciate it very much!

Soo far so good, thank you to all.

Alberto

Alberto

tumbleweed
- 9th April 2018, 18:06
One thing to watch out for... on the 2xK22 the second uart TX/RX share pins with the ICSP on RB6 and RB7.

On the 4xK22 they're on PORTD, so no conflict there. Just something to be aware of.

Dave
- 9th April 2018, 19:02
I have tried using the 18F27K40 because of the extra memory and they work just fine BUT, There is no longer any boot loader support from Mecanique and I have NOT found any from sources like TinyLoader. Therefor I have stuck with the 18F26K22 and the 18F46K22 as well as the 18F67K22 processors.

Ioannis
- 9th April 2018, 19:06
Why don't you use the ICSP for programming? That is if you have a programmer capable for that chip?

It is much faster than a bootloader.

Ioannis

HenrikOlsson
- 10th April 2018, 06:08
Hmm... My experience is the complete opposite. Using a bootloader is generally much faster than using ISCP (with a PK3 at least) - especially when loading small programs into chips with a lot of flash.

/Henrik.

Ioannis
- 10th April 2018, 07:07
Interesting Henrik. No matter the chip selected?

Ioannis

mpgmike
- 10th April 2018, 09:13
So if somebody has a code snippet that shows how to set DT interrupt for the second uart and is willing to post it, I will appreciate it very much!
Alberto


DEFINE OSC 32
DEFINE HSER1_RCSTA 90h ;OBD
DEFINE HSER1_TXSTA 24h
DEFINE HSER1_BAUD 57600
DEFINE HSER1_CLROERR 1
DEFINE HSER2_RCSTA 90h ;Master
DEFINE HSER2_TXSTA 24h
DEFINE HSER2_BAUD 57600
DEFINE HSER2_CLROERR 1

INCLUDE "DT_INTS-18.pbp"
INCLUDE "ReEnterPBP-18.bas"

;Interrupt Processor:
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT1_INT, _OK, PBP, yes ;USART2 (Main) CS
INT_Handler RX1_INT, _Grab_ELM, PBP, yes ;USART1 (ELM) Transmission Received
INT_Handler RX2_INT, _Grab_Main, PBP, yes ;USART2 (MAIN) Transmission Received
endm
INT_CREATE ;Creates the interrupt processor
ENDASM

; -=- *** USART SFRs *** -----------------------------------------------------------------------------------------------
TXSTA1 = %00100100 ;24h, Yields 57,600 Baud, ELM327
RCSTA1 = %10010000 ;90h
BAUDCON1 = %01000000
SPBRG1 = 34 ;57,600 Baud @ 48MHz, 0.16%
PIE3.5 = 1 ;RC1IE
PIE3.4 = 0 ;TX1IE
TXSTA2 = %00100100 ;24h, Master Controller
RCSTA2 = %10010000 ;90h
SPBRG2 = 34 ;57,600 Baud @ 48MHz, 0.16%
BAUDCON2 = %01000000
PIE3.7 = 1 ;RC2IE
PIE3.6 = 0 ;TX2IE
; -=- *** Interrupt Related SFRs *** -----------------------------------------------------------------------------------
INTCON = %01000000 ;.7 = GIE, .1 = INT1 Falling Edge
PIE0.1 = 1 ;INT1IE

Start:
INTCON.7 = 1 ;Enable Global Interrupts
@ INT_ENABLE RX1_INT
@ INT_ENABLE RX2_INT

MainLoop:
DO
PAUSE 10
LOOP

; -=-=-=- RX1 Interrupt Handler -=-=-=-
Grab_ELM:
Ebyt0 = REREG1
ElmCt = ElmCt + 1
@ INT_RETURN

; -=-=-=- RX2 Interrupt Handler -=-=-=-
Grab_Main:
IF Mbit = 0 THEN
Byt0 = RCREG2
GOTO Grab_Main2
ELSEIF Mbit = 1 THEN
Byt1 = RCREG2
ENDIF
@ INT_RETURN

I have a project I originally designed around the PIC18F26K22 that does some work, communicates with an ELM327 OBD-II Interpreter, and reports back to a Master PIC18F25K50 connected to USB. It uses both UART Functions along with SPI for a digital pot. I recently changed over to the PIC18F27K40. Here is the code you requested.

HenrikOlsson
- 10th April 2018, 16:18
Interesting Henrik. No matter the chip selected?

Ioannis
I'd say yes. But then again, my programs are usually not near the size of the memory size of the part in question and IIRC the bootloader does not reprogram the FULL memory while an ICSP device programmer usually does, even if the content is all $FF. I may be mistaken there though so don't quote me.

I suspect that the ICSP programmer used might have a fairly big impact on the programming speed as well and I believe that's part of where the "not to be used for production" label for the PK3 comes from - but again, that's me speculating.

If I find the time I'll do some tests and report back.

/Henrik.

Alberto
- 10th April 2018, 17:05
Thank you mgpmike for posting the code. That's just what I needed to understand how to use the 2nd uart (this is my first time)

I noted that you define the uarts prior to include the DT interrupt. Does it make any difference if you include the DT int. prior to defining the uarts?

Alberto

mpgmike
- 10th April 2018, 19:01
Just so both are defined before you try to use them, the order doesn't seem to matter. I believe DT said to place the INT section close to the top...maybe it does matter?!?