PDA

View Full Version : ICP via optocouplers?



Norbert
- 1st March 2016, 18:24
Anyone with experience of ICP of 18F... (or 16F...) via optocouplers?
I need electrical isolation for safety reasons between the PIC circuit and a permanently-connected-PC-with-Internet.
Can use LVP or an onboard source of higher voltage for MCLR pin.
I realize this is not a hardware forum, but it is the kind of place where someone might have tried something like this...

Tips, suggestions etc. appreciated!

HenrikOlsson
- 1st March 2016, 19:01
Never tried, don't know if it's straight forward or tricky as hell (since the PGD-pin is bi-directional for example) but if I were to try it I'd probably try with one of ADUM series digital isolators or something like that.

But what's the application? Why is there a permanently connected PC to the programming port of the PIC?
Is it perhaps possible to initially program the PIC with a bootloader and then, instead of trying to isolate the ICSP pins, use an isolated RS232 connection to the PC? That way you have isolated serial AND programming at the same time.

/Henrik.

towlerg
- 2nd March 2016, 03:46
between the PIC circuit and a permanently-connected-PC-with-Internet

I don't understand why you want to use ICSP (which I assume is what you meant). Surley it would be easier to use either USB and RS232, which could both be connected via optocouplers. Your optocouplers would have to be real fast to use USB 2.0

Sorry in advance if I've misunderstood.

George

pedja089
- 2nd March 2016, 08:58
There is somewhere documentation for this
http://www.microchipdirect.com/productsearch.aspx?Keywords=AC244005
So you can take a look how they did that.
But I also don't understand why you need this...
EDIT: http://ww1.microchip.com/downloads/en/DeviceDoc/50002085B.pdf
Page 130-133

Dave
- 2nd March 2016, 11:43
Why not just use a bootLoader? That way you can update the firmware via. the rs232 connection.

Norbert
- 22nd March 2016, 16:48
Thanks for all the replies, apologies for the late response.
Yes, it would make a lot more sense to use a bootloader, and although I will take a look at the adapter described in the link sent by Pedja089, it is probably not certified for the 10kV isolation that the application demands.

The application is for an existing piece of hardware built around a 18F67K22 - production changes to the hardware itself would be expensive.
That's why I was considering using an external optocoupler-based adapter and connecting it permanently to the ICSP port on the existing hardware.

The problem with using a bootloader is that there is no remotely-accessible reset function on the existing hardware. If it were a new design, I could use an output pin from the MCU to drive a one-shot pulse circuit which would pull down the MCLR pin causing a reboot and the option of entering the bootloader via the existing (already optoisolated to 10kV!) RS485 port (goes to the USART of the MCU). Are the any pre-coded bootloaders for this MCU that can be accessed from the main (PBP) code - i.e. post-boot, WITHOUT a reset button? Suggestions on how to do a reboot without reset button, and without pulling MCLR low? Maybe by using the WDT and with a USART command calling a timeout?

Norbert
- 22nd March 2016, 16:58
... and for the curious:

The application is existing PIC-based hardware used for environmental monitoring in grain storage silos.
Because of the potentially explosive atmosphere, there are strict requirements on the hardware used. Thus the opto-isolation on all ports to the "outside world".
The hardware is already in use in several places around the world, including places where it would be very expensive to go to do a firmware update on site. But because of new items of associated hardware, changes to the code in the controller MCU are occasionally needed.

pedja089
- 22nd March 2016, 17:33
You don't need reset for bootloader. Why bootloader must start first?
I always load hex file via main app in external eeprom, or in upper half of PIC FLASH memory.
In main app there is already all you need to connect to PC or whatever. So use that to load HEX from PC.

INTCON=0
FOR Adr=32768 TO 65023 STEP BlockSize
ERASECODE Adr
NEXT Adr
FOR Adr=0 TO 32255
Err=0
FwReceive:
Err=Err+1
IF Err=250 THEN
GOTO DeliteAndReset
ENDIF
HSEROUT2 ["A:",DEC6 Adr,3]
HSERIN2 100, FwReceive, [WAIT("D:"), Tmp0, Tmp1]
IF Tmp0<>Tmp1 THEN GOTO FwReceive
Adr.15=1
WRITECODE Adr,Tmp0
Adr.15=0
NEXT Adr
GOTO StartBootloader
And at end of code there is bootloader that copy from upper half to a lower half of FLASH. That bootloader is precompiled.


@ ORG .65024
StartBootloader:
ASM
dw 0EF3Dh, 0F07Fh, 06EF6h, 06AF8h, 00E94h, 06E7Fh, 00E55h, 06E7Eh, 00EAAh, 06E7Eh, 0827Fh, 00000h, 0947Fh, 0EF3Ah, 0F07Fh, 06AF8h
dw 00E80h, 06E7Fh, 00009h, 050F5h, 0EF3Ah, 0F07Fh, 06AF8h, 06EF5h, 0000Ch, 028F6h, 00B3Fh, 0E109h, 00E84h, 06E7Fh, 00E55h, 06E7Eh
ETC...
Code for that is:

DEFINE RESET_ORG .65024

Adr VAR WORD
Tmp VAR BYTE
BlockSize VAR BYTE BANKA SYSTEM
@ MovLW BLOCK_SIZE
@ MovWF BlockSize

FOR Adr=0 TO 32255 STEP BlockSize
ERASECODE Adr
NEXT Adr

FOR Adr=0 TO 32255 'Ne diraj zadnjih 512B
Adr.15=1
READCODE Adr,Tmp
Adr.15=0
WRITECODE Adr,Tmp
NEXT Adr
@ RESET
EDIT:
Hope that this is not too confusing...
EDIT2:
https://www.youtube.com/watch?v=jbLy6kE-Szg

Dave
- 22nd March 2016, 17:36
Norbert, As a matter of fact I always place some kind of reset command or sequence into my serial comm routines for just that issue. I usually use the key combination "ctrl Z" which then places the target processor into a 10 second timeout which enables me to disconnect the terminal program and start the bootloader program. Works a treat... Been using it for years now...

Norbert
- 22nd March 2016, 18:42
Pedja - very instructive video!
Since there is an onboard 1Mbit FRAM on the hardware that could be used for the intermediate storage of the serially-uploaded code, I'll give it a try. Thanks for the suggestion and your code - I think I get the general drift of it.

On this thread [URL="http://www.picbasic.co.uk/forum/showthread.php?t=10144 "], BradB suggests setting a flag in EEPROM for bootloader/no bootloader at next reset. That sounds useful too, to avoid having to catch the bootloader in time after reset, which can be timing critical - as per your suggestion, Dave.

And a little too late, a thankyou to DarrelT who in an old thread suggested RTFM and @ RESET...

Art
- 23rd April 2016, 18:08
Hi :) One way to reset would be to clear the watchdog timer yourself,
and jump to an endless loop that fails to clear it.

Serial over a Toslink cable would give the 10 kV isolation.
I've found 0.2uF capacitance across the Toslink receiver
output to ground (instead of a cap in series used for digital audio)
overcomes the receiver's clock jitter, and allows the DC serial signal.