Help!!! Why Can't I Program My PIC18F25K22 ID's ????(Solved) - Page 1
Forum section: electronics / general

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 30, 2015, 08:27:54 pm
content: :popcorn:Please Help!!! I have spent two long days trying to get this thing to work, I don't know what else I can do!I don't have access to a PICKIT2 or PICKIT3.So, Ok, I decided to build my own programmer for PICC chips, on a breadboard and using Visual Basic 6 to control the operations. So I went to Microchip.com and downloaded the .pdf App note (see Attached files) to show me how to do this.It couldn't be that hard!Ok, after a few days , I managed to make my own programmer for PICC chips on a breadboard, used my bench PC and Visual Basic 6 with WinXP to control the operations. Then I put on my thinking cap and wrote a few 100 lines of code. Seemed like a good idea so far..I am only trying to code a few pgm'ing instructions to pgm a chip.My first try was a success..with 16F88x chips..then I tried to do an 18F25K22.It worked perfect with 16F887 chips. Programs them and verifies them like a pro.Note: the Pic 18F25K22 has the same pinout as the 16F887.It reads out the Device ID correctly for the PIC 18F25K22It reads out the PIC 18F25K22 ID codes at location 0x20 0000 to 0x20 0007 perfectly(I guess, all 0xFFFF).The BulkChipErase routine works fine.(I assume, I readout &HFFFF's looking at a few bytes of pgm memory.)Since I can do a BulkChipErase and read Device ID's, I know the chip is properly entering the programming mode.I have 10 (from Digikey)Brand NEW 18F25K22 chips, have tried all of them to test my code and always with the same failure to pgm as a result.I have checked the Clk, Data, VPgm waveforms with my scope and they are clean and levels are perfect.Due to the 486 vintage PC that I am using, the clock high and low min widths are about 20uSec ea. ..very slow enough!The Vpgm voltage rises to 9V in <100nSec and falls back to 0V in <2uSec after programming is finished. Clk and Data waveforms have approx. 100nSec Rise/Fall times, Vhi=5.00V, VLo <.4VWhen device being programmed is in an idle state, Vdd=5.00V, Pin 1 Vpgm pin is held at 0.13V, a chip reset condition.The Dly1 routine works perfect.Vpp=9V, Vdd=5.00V I am always using 9V for Vpp=HV programming.The device being programmed has no connections to any of its other pins, only connecting to Vss, Vdd, Vpgm, PClk, PDat pinsI have properly connected the Vss Vdd lines and there are bypass caps between them.But I cannot seem to program these 18F25K22 ID locations with my own data..why??Result:The ID bytes all remain unchanged or 0xFFFFafter calling PgmIDs18************************************************************************************************Here's the VB6 code that should be doing the job(I just coded VBasic exactly as shown following the steps shown on the Pgm'ing the ID's page 22 Section 3.4 of the Microchip Pgm'ing ApNote).'======================================================================================Public DW as Long, W as Long, mSec as Integer, P as Long,'======================================================================================Private Sub PgmIDs18()CW = &H1B: Out P, CW 'RB6,RB7 Low, Vpgm=0 'P is address of Parallel Port Register 0x37A which controls Vpp, Clk, DatamSec = 10: Call Dly1CW = &H1D: Out P, CW 'Set VPgm=HV ' Vpgm=Pin1=Vpp=9 V HV to enter Pgm'ing mode.mSec = 10: Call Dly1DW = &H8EA6: Call CID16 'Configures ECON1 register to Enable ProgrammingDW = &H9CA6: Call CID16 'CFGS enable Program Flash or IDsDW = &H84A6: Call CID16 'WREN write enable enabledDW = &HE20: Call CID16 'Set Table Ptr RegsDW = &H6EF8: Call CID16 'writes &H20 to TBLPTRUDW = &HE00: Call CID16DW = &H6EF7: Call CID16 'Writes &H0 to TBLPTRHDW = &HE00: Call CID16DW = &H6EF6: Call CID16 'Writes &H0 to TBLPTRLDW = &HA5A5: Call W2BytesInc2 'Cmd 1101 Writes 2 bytes post Inc 2DW = &HAAAA: Call W2BytesInc2 'DW is just test data for all ID bytesDW = &H5555: Call W2BytesInc2DW = &H5A5A: Call StartWrite18 'Cmd 1111dDW = &H94A6: Call CID16 'Resets Write Enable bit WREN, Write Enable disabled.CW = &H1B: Out P, CW 'RB6,RB7 Low, Vpgm=0mSec = 10: Call Dly1End Sub'==================================================================================Private Sub W2BytesInc2() 'Cmd 1101CW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=HV 9V 'bit 0=1 cmd clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHiCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 1=0 cmd clk'd inCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 2=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 3=1 cmd clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi'Now clock in two bytesDim Bit As IntegerFor Bit = 0 To 15 ' Clocks in 16-bits of Payload data LSB FirstIf (2 ^ Bit) And DW Then ' Clock in a 1CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit B of DW 1 clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsElse 'Clk in a 0CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit B of DW 0 clk'd inEnd IfNext BitEnd Sub'=====================================================================================Private Sub StartWrite18() ' 1111 has last 2bytes as payload followed by special NOP' Special NOP(0000) holds 4th bit high for Pgm Time(3mS) and then Lo=200uS'mSec = 1: Call Dly1CW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 0=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 1=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 2=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 3=1 cmd clk'd, Cmd 1111 StartWrite clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsDim Bit As IntegerFor Bit = 0 To 15 ' Clocks in 16-bits of Payload data LSB FirstIf (2 ^ Bit) And DW Then ' Clock in a 1CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit Bit bit=1 of DW clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsElse 'Clk in a 0CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi Bit bit =0 of DW clk'd inEnd IfNext BitmSec = 1: Call Dly1 'a delay to assist in debug' 0000 Special NOP that starts programming the ID bits on 4th bitCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 1=0 cmd enteredCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 2=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 3=0 cmd clk'd inCW = &H1E: Out P, CW' Clock Hi, Data Lo, Vpgm=VpgmHi PROGRAMMING of ID bits StartsmSec = 30: Call Dly1'Tprog for ID StartWrite must wait TDelay5=P9 with Clock held hi for programming to complete'30mSec exceeds spec P9 wait spec=1mSec.. wait extended for debugging testsCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmLo wait time starts with 'bit 4=0 Cmd=0000 clk'd in.mSec = 10: Call Dly1 '(P10 Clk Lo must wait =TDly6 is Spec'd at 200uSec Minimum), wait extended for debugging testDW = 0 ' Now clock in Payload = 0For Bit = 0 To 15 ' Clocks in 16-bits of Payload data LSB FirstCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit B of DW 0 clk'd inNext BitEnd Sub'=======================================================================================Private Sub CID16() ' Clocks in 16-bits of Payload data LSB First, always after CoreInstruction is calledCall CoreInstructionDim Bit As IntegerFor Bit = 0 To 15If (2 ^ Bit) And DW Then ' Clock in a 1CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit B of DW 1 clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsElse 'Clk in a 0CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit B of DW 0 clk'd inEnd IfNext BitCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsEnd Sub'=========================================================================================Private Sub CoreInstruction() '18Fx5K25 Chip Core Instruction' 0000 is always entered first b4 a 16-bit instruction/data payload that follows immediatelyCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 1=0 cmd enteredCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 2=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 2=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 3=0 cmd clk'd in. Both Clk and Data Lo, Ready for a 16 bit loadEnd Sub'========================================================================================

author: Skimask
author_rank: Super Contributor
timestamp: May 30, 2015, 11:23:06 pm
content: Quote from: SuzyC on May 30, 2015, 08:27:54 pmBuy a PICKIT2 or PICKIT3QuoteYou've got access to the internets, you've got access for a $30 (or whatever the knockoffs are going for these days) programmer.QuoteYou're doing most of what's required...but not all of it. Re-read the programming spec datasheet.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 30, 2015, 11:29:04 pm
content: Thanks for the advice, Skimask, but I am on a tight budget, have more time than money to spend..the rent is due on Monday!I've read over and over the Pgm'ing Appnote..I seem to be blind to what I am missing!

author: picandmix
author_rank: Frequent Contributor
timestamp: May 31, 2015, 09:37:42 am
content: Think its only the Pickt3 that will program /debug that 18f25k22 series.You can buy a bare bones pk3 from China for about GB £12 or a cased one for £20, boths cheaper than the 10 chips you bought.http://www.ebay.co.uk/itm/Hot-PICkit3-PIC-KIT3-Debugger-Programmer-Emulator-Chip-Programmer-PIC-Controller-/271799867505?pt=LH_DefaultDomain_3&hash=item3f4888d871Diy programmers for those chips, if it was so easy it would be all over the web.A programmer built on a breadboard can introduce more problems than it solves.

author: Deathwish
author_rank: Unknown
timestamp: May 31, 2015, 09:53:14 am
content: Picandmix, being on Govt benefits and always hard up, thank you for the link, just purchased that one, just hoping it comes with the case as it doesn't actually say and pictures on sales do not guarantee it does, merely that it can be put in one.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 10:13:57 am
content: Thanks Picandmix, for your suggestion..but I enjoy the challenge of getting a circuit and my code to work. I also like to work with what I have at hand.BTW, I didn't buy those 10 chips just to test my programmer, I bought these chips to use in projects!I know that making my own programmer could be difficult and it would certainly seem a time-wasting, impractical thing to bother with for any millionaire to waster their time on an attempt to do this, but I don't like just throwing money at a problem to solve it andI enjoy creating my own custom hardware to work with.But sometimes I get stuck working on a difficult problem, and that is why I am posting here for help, I do not want to be stymied with just give up and buy it suggestions.So, Please! No more suggestions to just go and buy a programmer!

author: android
author_rank: Regular Contributor
timestamp: May 31, 2015, 01:05:42 pm
content: This is probably not much help (sorry), but I notice that Figure 3-5 says:Quote...which is 5 ms (min). I see you're using 30 ms for debug purposes so that should be ok, but maybe it needs to be closer to 5 ms for this device (I can't imagine why though). Otherwise I can't see anything obviously wrong with your code, so that makes me think it might be a timing problem.BTW, where you have coded "Out P, CW" what are the meanings of each bit of the CW variable? I could guess from your comments but I'm not 100% certain.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 02:20:41 pm
content: Thanks Android! I have tried several lesser Tprog wait times with the same result. However, the I am using software loops to create very short delay times with my routine Call Dly1. Close observation of the delay (wait) times reveal on my scope an accuracy of <10% from expected, so I compensate by increasing the wait time an additional 10% to assure I meet the minimum delay (wait) requirements.Out P, CWSyntax: P( as in Parallel PORTaddr (0x37A) Control Register as Long), CW (var name as Long for a control byte to be output)The CW control byte controls Vpp for programming HV programming voltage control, PClk as an output PC--> MCU, and PData as an I/O line PC<-->MCU.I now that timing in general is not an issue with my code,unless too much delay is a problem, which I doubt. I have single-stepped trough my write and read routines and observed the same results.P is the PC's Parallel Port Address (LPT!:) control register, located at address 0x380 (decimal 890). It has several bit lines available for I/O meant to be used for printer communication. The P is physical address the Parallel Control Port (0x37A) register and DW is the byte to output from the PC. The PC has a register at that address (P) that controls pins on the Parallel Port connector by means of setting/clearing bits of the Parallel Port Control Registers. These I/O pins are originally intended for printer control and are named nStrobe, Select, Init. ALF. For input, besides the 8-bit Parallel Port 0x378, there is a input only register at 0x379 which has several available bits for input and the I/O lines in my program use bits of the Parallel Port Control register at an address of 0x380.I am augmenting VBasic6 with Inout32.dll which allows port I/O in VBasic, makes XP and other new operating systems capable of just using simple statements such as as out P, CW (a single byte) to communicate directly at a hardware level with the outside world through the Parallel port connector of legacy PC's.I have stated that the hardware works perfectly with the PIC16F887, 16F886, but I think it is somehow my code with the PIC18F25K22..but that is the enigma here and I welcome anyone to tell me that I am somehow in error.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 02:53:48 pm
content: Perhaps I can star in a new TV series especially for coders called the "The Walking Bits UnRead"I have noticed that doing a HV Bulkerase seems to set all the bytes readback from the PIC18F25K22 to be zero.That wouldn't be so bad if that was even a stable state condition!Is it possible that I have even more problems!I also noticed that if I call PgmIDs18() after supposedly doing a HV Bulkerase that the bytes read back from the first 32-bytes of Program Flash memory again read out as 0xFFFF. If I then physically remove the chip in the reset idle state from the ZIF socket and re-insert back in, all the program area bytes read back are all zeroes!It leads me to believe that the PIC18F25K22 is somehow left in a zombie unstable state and retains this state after physically being removed from the programmer.Now this coding/HW puzzle is seemingly ever more interesting and challenging!The HV bulkerase routine shone here is in VBasic but directly copied step by step from the Microchip Pgm'ing guide Table 3.2 on page 13 and I have checked step by step with my scope that I see the same PClk versus PDat results as shown in figure 3.2 showing the bit timing diagram for Bulkerase.'==================================================================================Private Sub BulkErase18Fx() 'See Notes about Table Pointer below at end of program comments'First Reset MCU BulkErase Erases the entire device, after this some CONFIG WORDS must be config'dCW = &H1B: Out P, CW 'RB6,RB7 low, Vpgm=0mSec = 10: Call Dly1CW = &H1D: Out P, CW 'VPgm=HV 'RESETS Chip and enters HV programming mode.mSec = 10: Call Dly1 'Now MCU Erase instruction is to be clocked inDW = &HE3C: Call CID16 'MOVLW 0x0E3C First MOV 0x3C to 0x0E (0E3C)is the 16-bit payload to clock inDW = &H6EF8: Call CID16 'MOVWF TBLPTRU Move's the above 0x3C byte to the Table Pointer's Upper RegDW = &HE00: Call CID16 'MOVLW 00 to 0xOE registerDW = &H6EF7: Call CID16 'MOVWF TBLPTRH 'Moves above to Table Pointer HighDW = &HE05: Call CID16 'MOVLW 5 to 0x0E registerDW = &H6EF6: Call CID16 'MOVWF 5 to TBLPTRLDW = &HF0F: Call TBLWR 'Cmd 1100 Table Write Writes 0x0F0F to &H 3C 0005DW = &HE3C: Call CID16 'MOVLW 0x3C to 0x0E registerDW = &H6EF8: Call CID16 'MOVLF the above to TBLPTRU, at RAM address 0FF8hDW = &HE00: Call CID16 'MOVLW 0 to 0x0E registerDW = &H6EF7: Call CID16 'MOVLF the above to TBLPTRH, at RAM address 0FF7hDW = &HE04: Call CID16 'MOVLW 0x4 to 0x0E registerDW = &H6EF6: Call CID16 'MOVLF the above to TBLPTRL, at RAM address 0FF6hDW = &H8F8F: Call TBLWR 'Cmd 1100 Table Write 0x8F8F to &H 3C 0004DW = &H0: Call CID16 'NOPDW = &H0: Call BulkEraseHVStart'A NOP that hold Dat Lo when 4th bit=0, for Tprog(P9>15mSec)when Bulk Erase BeginsmSec = 20: Call Dly1 'mSec=15 mSec, the Min for HV BulkEraseCW = &H1B: Out P, CW 'RB6,RB7 low, Vpgm=0 Exits Programming ModeEnd Sub'============================================================================Private Sub BulkEraseHVStart() ' 0000 Special NOP that starts programming the ID bits on 4th bitCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 1=0 cmd enteredCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 2=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 3=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHi PROGRAMMING of ID bits Starts'30mSec exceeds spec P9 wait spec=1mSec.. wait extended for debugging testsCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmLo wait time starts with 'bit 4=0 Cmd=0000 clk'd in.mSec = 30: Call Dly1 'BulkErase must wait TDelay5=P9 with Clock held hi for programming to completeDW = 0 ' Now clock in Payload = 0For Bit = 0 To 15 ' Clocks in 16-bits of Payload data LSB FirstCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit Bit of DW = 0 clk'd inNext Bit-='===================================================================================Private Sub TBLWR() 'TableWrite instruction' 1100 Table Write precedes a 16-bit payload to TableCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit 0=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit 1=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit 2=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit 3=1 cmd clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 3=0 cmd clk'd in. Both Clk and Data Lo, Ready for a 16 bit Load'Now Clk in the 16-bit PayLoad DWDim Bit As IntegerFor Bit = 0 To 15 ' Clocks in 16-bits of PayLoad data LSb FirstIf (2 ^ Bit) And DW Then ' Clock in a 1CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit B of DW 1 clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsElse 'Clk in a 0CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit Bit of DW 0 clk'd inEnd IfNext BitEnd SubThis is a fine kettle of fish!

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 03:25:59 pm
content: Below the timing diagram and step-by-step for BulkErase as copied from the Microchip Pgm'ing guide.pdf

author: Mechatrommer
author_rank: Super Contributor
timestamp: May 31, 2015, 03:26:31 pm
content: Quote from: SuzyC on May 31, 2015, 02:20:41 pmi am of not much help other than want to say, congratulation on your VB6 route, welcome to the "rotten" community of few of us. i suspect you'll have a hard time getting help in forum because 1) not much people are interested in building diy pickit, they rather buy clones or originals 2) no one will know the latency of all those things you described except yourself, you alone have the access to it. you need to observe/scope closely of your codes, hardwares and signals timing should be in close conformance with the datasheet. my ultimate advice alas offtopic, get a decent job that not only can support you rental and minimum survival cost, but be able to save some to buy electronics and books to get you going, there is another cost to be saved for ordering tools, soldering iron, pcb's enclosures and all, if you want to profit from this hobby. time is limited, now you may think you have abundant of it, but dont be too late to realize that. make a life first and then the life will make you. ymmv.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 03:35:49 pm
content: Thanks Mechatrommer for the encouragement.I say, if Microchip can do it..so can I!As I said before, I am not in it for the money, but for the challenge of this task.This is my hobby, some would prefer solving other puzzles, I like to do this.I learn a lot about hardware and software this way and I find this challenge as an experience that is both frustrating and yet quite rewarding and fascinating.When I want to enjoy myself, I spend endless hours in the surf, the ocean is my spiritual home. I really enjoy my few friends and family and my lover and I also love making music on my piano and guitar. When I want to exercise my brain, I do this. Neither surfing nor building DIY programmers makes me any money.I enjoy creating my own hardware solutions and if I eventually get things to work or not, my projects give me a good feeling of accomplishment..so, you see, I kinda feel like Frank Sinatra when he sang, "I Did It My Way!"I don't expect everyone to be as sympathetic as you towards what might be a Don Quixote type of goal..At the same time, my project might be just a few code words away from working!

author: Andy Watson
author_rank: Super Contributor
timestamp: May 31, 2015, 04:12:50 pm
content: Do you have any means of monitoring the signals on the parallel port?Many moons ago I spent some considerable time developing and programming a CPLD to transfer data (the wrong way) via a laptop parallel port. There was no time to spare in the data stream (hence the CPLD), it was a case of configuring the port and letting data rip through in a burst - approx 15 seconds worth IIRC. We never managed more than a couple of seconds because "something" was looking at the port and resetting it. We had disabled the windoze (WIn98 I think) drivers and even the maskable interrupts but there was still something resetting the parallel port. Never did find the cause - that was when I gave up all hope of using a windoze machine to dorealI/O.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 04:21:06 pm
content: Thanks Andy Watson, for sharing your parallel experience with me.I am not using at all the 8-bit Parallel Base Port &H378, just using 4 bit lines of the Control Register &H37A to control I/O for PClk, PData, Vpp HV. I use a Parallel Port input bit of &H379 to read Pdata back. In every case the PC is the master, PClk is, of course, always an output, A PClk generated only by the PC, while the MCU must output PData on an output pin and also be able to input MCU Pdata back into the PC.Yes, I have a Rigol 200-MHz 4-Chan DS4024 scope with over 85 megabytes of streaming storage. I checked each step and state of the programming process and see no problem except there is a great variation in PClk and PData pulse width that is both intrinsic to coding and PC interrupts, but in all cases, the slow latency of PC I/O means that the Min pulse widths of the clock signals skew considerably, there are certainly extended periods of timeout by the PC measured in tens of microseconds, but my PClks are always in the tens of microseconds. The Clk/Data pulses never miss their relative order and are never too short in pulse width.Windows must pause to do a DMA display screen refresh and perhaps some other busywork, but I am not so sure that is the problem..but then..what is it??I have solved your CPLD-like problem by using the PC to download the programming data to a dedicated MCU that stored the program data in a SRAM buffer and then it did the programming job and consistently adhered to the strict timing behavior to interface with the target CPLD. If all else fails I will attempt again this same approach.But why should Microchip be so mischievous and not tell us about this possible critical timing programming caveat?If anyone is interested, I can take a scope Selfie of any of the programming steps and post these pretty pictures for all to see.

author: Andy Watson
author_rank: Super Contributor
timestamp: May 31, 2015, 04:48:26 pm
content: I notice that it has a low voltage programming mode, here's a bit of a straw to clutch at:https://www.eevblog.com/forum/microcontrollers/icsp-microchip-issues-or-all-me/Quote from: SuzyC on May 30, 2015, 08:27:54 pmPossibly try tying the low-voltage programming pin to its inactive state - can't hurt to try it!

author: zapta
author_rank: Super Contributor
timestamp: May 31, 2015, 05:28:01 pm
content: Quote from: SuzyC on May 31, 2015, 03:35:49 pmIt's your hobby, time and money so do as you please. You set the rules.If you will still not be able to make it work and will wonder why, you can still get an off the shelf programmer and compare the signals to yours. This will also be a learning experience.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 05:41:58 pm
content: Thanks Zapta, this has crossed my mind. For the sake of comparison I could buy a PICKIT3 or clone to find out how it does the job. Then I would have two PIC programmers working.In the name of the fact that more can be in some cases, somehow less, I would be just so happy to have but one, my one!Does anyone out there have the time and compassion to put their four precious scope probes upon the ICSP interface pins PClk, PData, Vpp and VDD to record how the PICKIT3 performs this circus? I would simply love to see the results. All it takes is a cellphone or SmartPhone to take a screen shot and post it. I would probably need to look at the first few milliseconds of ICSP programming.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 05:44:21 pm
content: Thanks again, Andy Watson.I sometimes feel like Sherlock Holmes working on this problem, it is so cool to have a Watson helping me!I tried tying rb3/PGM to Vss, exactly the same results.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 05:58:03 pm
content: Three other possibilities have become apparent: Is it necessary for Vdd to be controlled by the ICSP programmer, is it that Vdd must rise and settle quickly to Vdd and then, within a time window of only a few microseconds to seconds that Vpp HV be applied to enter into the programming mode?My breadboard in an idle state keeps Vdd constant at 5.00V with the pin 1 HVpgm pin held either at 5V or ground, either method of setting the idle Vpp pin don't manage to make any change in doing the job as of now.Is it possible to read out the Device ID without entering the Programming Mode of the PIC18F25K22? If if is then I am just not entering the programming mode..but how is that possible if I can read the Dev ID code always consistently and correctly, and even if I readback garbage data depending on my programming steps, I must be programming in some odd way?Or has anyone found a flaw in my BulkErase or other code?A third possibility is that somehow some programming control register remains in a state that needs to be set/reset. This is a possibility with any bit stream, perhaps somewhere I am somehow lacking or adding just one serial bit more to create chaos rather than success?

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 09:51:54 pm
content: Not only myself, but some others have suggested that I might somehow exceed any Max time, any timeout time for any of the programming operations or timers. A close examination of the Pgm'ing Appnote shows only the Vpp rise and fall time has any effect..and I have checked that the rise and fall times are well within spec. Finally, my scope shows all timing and waits for programming exceed the Min. times for any pulsed operation by a generous amount.See my pretty pink and green polka dot enhanced spec sheet attached.So, we can eliminate this possibility!

author: BlueBill
author_rank: Regular Contributor
timestamp: May 31, 2015, 10:00:01 pm
content: Use your homebuilt programmer to build a Pickit2 lite.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 10:10:29 pm
content: Thanks for the suggestion, BlueBill. Love the polka dots on your name symbol character from SouthPark.But where's the firmware HexFile to be found to stuff into the PIC2LITE PIC 18F2550?And one other coding sage has testified in their reply to my post that only the PICKIT3 is capable of programming the 18F25K22 chips!PickandMix replied, "Think its only the Pickt3 that will program /debug that 18f25k22 series."Interesting enough, when I perused the list of chips that were able to be programmed by the many and slightly different Ebay PICKIT3 clones, I couldn't find the 18FK25K22 chip among those listed for any of the PICKIT3 clones who displayed such a list.So, I guess I am LED back from the BlueRoom to the LED light district to find a way to pay for a genuine PICKIT3.

author: SuzyC
author_rank: Frequent Contributor
timestamp: May 31, 2015, 11:35:57 pm
content: When a 16Fx88x chip is being programmed, the compiler Intel .hex file is just a long sequential list data/instruction packets and addresses prefacing each 16-bit payload packet, so I assume that the serial bit stream is just being copied in a serial fashion from program address =0 to to the end of the program space, but I never thought of instructions being executed by the MCU being programmed like it was running outside the programming mode of operation. Each instruction would be required to be prefaced by the '0000 Core Instruction, but what does this Pgm'ing Appnote paragraph mean:"CORE INSTRUCTIONThe core instruction passes a 16-bit instruction to theCPU core for execution. This is needed to set upregisters as appropriate for use with other commands."But this doesn't say which of many possible native PIC18F25K22 CPU instructions would be allowed to be executed or ignored?Another thing that I know is that the configuration registers must be set correctly for a MCU to allow Flash Memory instruction memory to be programmed, otherwise the programming fails, so a HV bulk erase must sometimes reset these CONFIG memory protect/Read Protect bits to keep them from upsetting the apple cart. This is the case with the PIC16F88x chips and no doubt with probably all others.One thing that I can't quite wrap my head around is that in programming the PIC 18F25K22 the programmer is actually sending actual instructions of the 18FK25K22 instruction set and the MCU responds. This means that somehow internally these instructions are decoded and executed just like the chip was running code with an active instruction clock running.In light or this, one of the configuration (CONFIG2H) registers (see attached below) show that the default/unprogrammed state of the WDT is hardware only enabled with a clock to WDT ratio is 1/32768.Is WDT active during programming?The first page of the P18F22K25 data sheet proudly states:Extended Watchdog Timer (WDT):- Programmable period from 4 ms to 131sDoes this mean that I first must program the CONFIG2 register bits to disable the WDT?The default state of the clock configurations bit in the CONFIGs show default as Hi-Speed EC clock and Primary Clock enabled, but this is not the internal clock.It is obvious from the tens of nSec response of the chip being programmed that it is delivering the next PDat output bit in a few tens of nSecs from a PClck pulse inputted rise/fall, which would otherwise indicate a very fast internal clock running.Does this mean that the chip being programmed can somehow be rebooting on WDT timeouts?In other words, the programming stream must get in and get its job done fast or else face WDT reset consequences?Does the programmer have to send along the programming instructions one to reset WDT commands in very periodic short intervals between groups of programming instructions, starting shortly after programming starts or else get caught by WDT during programming? Or else, as above stated, I know I can first program CONFIG2 bits to disable the WDT?If that is the case then I could get away of just reading the DevID, which is the only thing that works, since it only takes a few instructions to execute to be accomplished and therefore I have avoided a WDT reset?Yet all this is somewhat contradicted by the Pgm'ing specs that give no Max. Clk hi or low pulse width. But long PClks meaning slow programming would still be just as possible by disabling the WDT in CONFIG2.At the same time, the Clk Min Period is just 100nSec, and this means the programming can be accomplished very fast, like 65535K Flash model x 8 bits/byte by .1uSec/clock = something like <53mSec. Could this Pgm'ing clock outrun the WDT? Doesn't seem likely with the long mSec Tprog delays inherent in programming or BulkErasure.But the most important thing is to consider, if the above fantasy is real, why wouldn't Microchip make it known in big bold letters on the first page of the Pgm'ing guide?

author: Bruce Abbott
author_rank: Frequent Contributor
timestamp: June 01, 2015, 09:56:27 am
content: Here's an open source programmer that is supposed to do the 18F25k22, and has been tested with an 18F25K20.http://openprog.altervista.org/OP_eng.htmlPerhaps you could get some clues by browsing the source code, eg. function COpenProgDlg::Read18Fx in progP18.c (found in Command-line utility source code archive op_0.9.1.1.tar.gz).

author: neslekkim
author_rank: Super Contributor
timestamp: June 01, 2015, 10:36:23 am
content: Quote from: SuzyC on May 31, 2015, 10:10:29 pmHow different are 18f26k22 and 18f25k22?, atleast, I could program my 18f26k22 with both my clone, and original pickit3's..But again, as I think I mentioned before, ask TopLoser if he have any pickit's laying around, he have sold a couple earlier.

author: Ian.M
author_rank: Super Contributor
timestamp: June 01, 2015, 11:10:56 am
content: Nearly all the PICkit 2 firmware and software (including sourcecode) is hosted over at Microchip. See:http://www.microchip.com/forums/FindPost/775368You would need the PICkit 2 v2.61 software + the upgrade to device file v1.62.14 or higher. The firmware hex file is bundled with the standalone application.N.B. the standalone application programming only device support list is considerably longer than the PICkit 2 MPLAB device support list, which is itself longer than the list of devices that can be debugged with a PICkit 2.A PICkit 2 Lite is cut down by omitting the target Vdd generation and control circuit. As such it is limited to the subset of the device support list that can run at 5V, and also, depending on the existing target PIC's firmware, may not be able to reprogram PICs that have external /MCLR disabled in their CONFIG.

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 01, 2015, 01:36:19 pm
content: I tested the idea that WTD was running and my common sense demands that it is not, since Microchip would have mentioned this caveatThe most basic thing my programmer can do is 1) Read the DeviceID. This works perfectly every time.(2) Read MCU address locations. The device ID read works perfect.(3)Do a HV Bulkerase, it should erase everything except the DeviceID.My SW/HW cannot seem to do this. I read back all 00's as result.There are just two possibilities, and they are:1)If I cannot seem to erase the 25F25K22:This can be due to my software code is incorrect. But it is step-by-step copy of the code in the Microchip Prgm'ing datasheet.To check the Microchip code for errors or typos, I examined the latest errata sheet. There is no mention of any errors.So, it is not a software problem.2)Then this is a hardware problem.I followed my code completely through the BulkErase procedure(it has been uploaded to this toipic)I monitored the Vpp, Pclk, Pdat lines to verify the code was executing bit for bit v. the code to accomplish BulkErase.Result, the program executes without a detectable software or hardware flaw.I have checked for runt pulses, VoutHi, VoutLo, rise/fall times/glitches/VppHi and Lo transition times and they all beat the specs.So, considering the above, I must conclude that what is left..the PIC18F25K22 chips could be defective.This means that all 10 25F25K22 and the 4 25F45K22 are defective. This is hard to believe since I purchased them from a reliable major electronic parts hardware player.There is only one thing that bothers me, one of the first replies to my post for help warned me that I might not be doing things right somehow. I was not told what, just it was implied that some step was missing.What do I do now? The chips have been purchased over 6-mths ago, and have been sitting on my Procrastination Shelf until now.If only I had a PIC programmer to make a test!Thanks neslekkim,I downloaded the source code, it was difficult to read for me, but it seems to me that the Microchip BulkErase instructions are the acid test to determine if the programmer is working.Thanks Ian.M for your help, I haven't yet attempted to download the sourcecode for the PICKIT2, but I can't get myself to accept that the Microchip guide to programming is in error, even though many sections explain programming operation in ways that make understanding difficult, too much very important detail is poorly explained, this document is unprofessionally needlessly vague and sometimes confusingly ambiguous.Thanks to Bruce Abbott, but open-source projects are a circus in a software jungle, they often try to be so general at everything that they are almost incapable to be understood for the specifics. As for this project it would certainly be worth the while to find a more specifically targeted HW/SW approach or buy a commercial product.

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 01, 2015, 01:40:28 pm
content: Skimask replied to me, "You're doing most of what's required...but not all of it. Re-read the programming spec datasheet."What am I missing?

author: Ian.M
author_rank: Super Contributor
timestamp: June 01, 2015, 01:50:22 pm
content: You might want to try 3rd party software that can be configured for your programmer hardware (assuming you are bit-banging the programming signals from your PC)If it works, you have an algorithm or timing problem. If it doesn't, you have a hardware problem or maybe dead PICs. N.B. dead PICs are *VERY* unlikely, and if you have any, the most likely cause is that your programmer has killed them!http://picpgm.picprojects.net/would be worth trying.

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 01, 2015, 03:47:39 pm
content: Thousand Thanks Ian.MI know it is highly unlikely that these chips bought are bad..very unlikely..but then?I wish I knew about this sitehttp://picpgm.picprojects.net/sooner, could have saved hours and hours of troubleshooting!I needn't have had to re-invent the wheel.

author: amyk
author_rank: Super Contributor
timestamp: June 01, 2015, 04:08:19 pm
content: QuoteAre you removing and inserting them while it's powered on? Don't do that.I notice that you are using 5V Vdd but the datasheet says that Vihh must be at least Vdd+4.5 and at most 9. In other words,you cannot do high-voltage programming on an 18F2XK22/4XK22 at 5V Vdd, since then you'd need at least 9.5V to enter programming mode but that would violate the 9V max. The reason some of it seems to work but not others, is purely due to process variations. The parts may enter programming mode with less than 4.5V above Vdd, but this behaviour is not guaranteed at all.Ideally you'd use something between Vdd+4.5 and 9V. Since Vdd can be between 2.7 and 5.5V if you want to do bulk erases, pick something in that range which will satisfy the Vihh requirements. E.g. 8V on Vihh and 3V Vdd should be OK.If you look at their programming specifications you'll see that this is different from the 16F88x, which need a Vpp between 10 and 12V (I'd pick 11) and Vdd between 4.5 and 5.5V (5V is just right.) If you were using 9V Vpp with the 16F88x and it worked, I'd consider that also pure luck.Quote from: SuzyC on May 31, 2015, 11:35:57 pmPresumably everything except control flow instructions.QuoteThere is no "internal clock" - the only clocking is being supplied by the programmer.There is no minimum clock frequency.The same can be done for AVRs:

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 01, 2015, 04:16:30 pm
content: Thanks Amyk for your suggestions, some are good, some are very, very bad.I think you are confusing Vdd with Vpgm when you say," you cannot do high-voltage programming on an 18F2XK22/4XK22 at 5V Vdd, since then you'd need at least 9.5V to enter programming mode"I think you are saying to raise Vdd to 9.5 Volts??Vihh is rated at 11V Absolute Max Ratings in the spec sheet, so it seems that 9V would be safe, why shouldn't that work. They specify that all programming voltages are allowed to be set with a precision of +/- .25VSee attached.

author: amyk
author_rank: Super Contributor
timestamp: June 01, 2015, 04:27:31 pm
content: Please read carefully...Code:9 ---+---- ---+ Vihh MAX| |7.2--+ ---+ Vihh MIN| ^| |5.5--+---- Vdd MAX 4.5V| || v2.7--+---- Vdd MIN ---+||0 ---+

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 01, 2015, 04:41:37 pm
content: Thanks Amyk and a thousand pardons, I see your point now. If I lower Vdd to 4.5 volts that I can use Vihh =9V and meet the programming specs.I will give that a try.Your diagram makes your point very clear to understand, Sorry, I was unable to distinguish in your suggestions between Vdd and Vpp and I thought you suggested to raise Vdd to 9.5V!It means though that just having Vihh=9 at Vdd=5.0V, Vpp at just .5V above 9V max is enough to prevent programming!

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 01, 2015, 05:34:19 pm
content: I just lowered Vdd on my breadboard to 4.25V and ViHH is set to 9.0V, but with the exactly same result. I did a scope check and the Vout Voltages and Vdd were steady at 4.15 to 4.25VPossibilities:(1) I have already fried my 14 victims of grave programming abuse.(2) My software is somehow in error, If I call BulkErase, the result is of a short memory dump shows all 0's, but what is puzzling is if that I read the 7 ID locations routine and then run again another read at Flash Program Mem=&H0 to &H32 I then see all ones. The readings repeatedly show that all are erased 0xFF, that is until I powerdown reset or else call ReadDevID and then, if I call ReadMemory18 I am back to reading all zeros again consistently.Something else is a widdle screwy here.I think I need to once more step through my code to find some error.

author: android
author_rank: Regular Contributor
timestamp: June 02, 2015, 01:06:38 pm
content: One more thing you could try...Before trying to write new ID bytes, instead of doing a Chip Erase (0F8F) do an Erase User ID (0088). The chip erase may be just taking a very long time.

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 02, 2015, 02:14:41 pm
content: Thanks Android for your help. I notice that the erase sequence try to writes a 16-bit word to an 8-bit space?DW = &H8888: Call TBLWR 'Cmd 1100 Table Write 0x88 to &H 3C 0004Here's the exact code, but the effect is that results are exactly the same.In every case, reading the 8 IDs repeatedly shows 0xFFFF's, but IDs never program with new values, though.If I Call SubBulkErase8FxIDsOnly, then follow with ReadPgmMem18, reads first 32-bytesI get repeatedly 0xFFFFFread out.If I power down the programmer completely and power up, the ReadPgmMem18 now shows again repeatedly 0's.My four-year old daughter tried the same thing..same results.My immediate conclusion is that the Table Pointer for Pgm Flash Memory reads is not being reset!...why??This is odd, because every Call ReadPgmMem18 resets the MCU upon entry!'This is the exact VB code complete to do all operations, with recently corrected comments'====================================================================================Private Sub BulkErase18FxIDsOnly() 'EraseUserIDs 0x0088'First Reset MCU BulkErase Erases the entire device, after this some CONFIG WORDS must be config'dCW = &H1B: Out P, CW 'RB6,RB7 low, Vpgm=0mSec = 10: Call Dly1CW = &H1D: Out P, CW 'VPgm=HV 'RESETS Chip when Vpgm=VpgmHi, PC to 0000HmSec = 1: Call Dly1 'Now MCU Erase instruction is to be clocked inDW = &HE3C: Call CID16 'MOVLW 0x0E3C First MOV 0x3C to 0x0E (0x003C)is the 16-bit payload to clock inDW = &H6EF8: Call CID16 'MOVWF TBLPTRU Move's the above 0x3C byte to the Table Pointer's Upper RegDW = &HE00: Call CID16 'MOVLW 00 to 0xOE registerDW = &H6EF7: Call CID16 'MOVWF TBLPTRH 'Moves above to Table Pointer HighDW = &HE05: Call CID16 'MOVLW 5 to 0x0E registerDW = &H6EF6: Call CID16 'MOVWF 5 to TBLPTRLDW = &H0: Call TBLWR'Cmd 1100 Table Write Writes 0 to &H 3C 0005DW = &HE3C: Call CID16 'MOVLW 0x3C to 0x0E registerDW = &H6EF8: Call CID16 'MOVLF the above to TBLPTRU, at RAM address 0FF8hDW = &HE00: Call CID16 'MOVLW 0 to 0x0E registerDW = &H6EF7: Call CID16 'MOVLF the above to TBLPTRH, at RAM address 0FF7hDW = &HE04: Call CID16 'MOVLW 0x4 to 0x0E registerDW = &H6EF6: Call CID16 'MOVLF the above to TBLPTRL, at RAM address 0FF6hDW = &H8888: Call TBLWR'Cmd 1100 Table Write 0x88 to &H 3C 0004DW = &H0: Call CID16 'NOPDW = &H0: Call BulkEraseHVStart'A NOP that holds Dat Lo when 4th bit=0, for Tprog(P9>15mSec)when Bulk Erase BeginsmSec = 20: Call Dly1 'mSec=15 is Min for ID's BulkErase. There is no wait Max specCW = &H1B: Out P, CW 'RB6,RB7 low, Vpgm=0 Exits Programming ModeEnd Sub'====================================================================================Private Sub ReadPgmMem18()CW = &H1B: Out P, CW 'RB6,RB7 low, Vpgm=0mSec = 10: Call Dly1CW = &H1D: Out P, CW 'VPgm=HV 'RESETS Chip Vpgm=VpgmHimSec = 1: Call Dly1'First Set TBLPTR Address to 0DW = &HE0: Call CID16 'MOVLW 0 First MOVLW (0x0E) with &H00,the 16-bit payload to clock inDW = &H6EF8: Call CID16 'MOVWF TBLPTRU Move's the above 0x20 byte to the Table Pointer's Upper RegDW = &HE0: Call CID16 'MOVLW 0x0 to 0xOE registerDW = &H6EF7: Call CID16 'MOVWF TBLPTRH 'Moves above to Table Pointer HighDW = &HE0: Call CID16 'MOVLW 0x00 to registerDW = &H6EF6: Call CID16 'MOVWF 0 to TBLPTRL'------Now Table Pointer Address is set to 00 0000clsFor Ju = 0 To 32 Step 2Call TBLRDPinc 'Read Pgm Flash Mem with Post Inc. Adrr CmdCall ReadData18FPdm(Ju) = WCall TBLRDPinc 'Read next 8-bit address contents with Post Addr IncCall ReadData18FPdm(Ju + 1) = WNextCW = &H1B: Out P, CW 'RB6,RB7 low, Vpgm=0mSec = 10: Call Dly1End Sub/======================================================================================Private Sub ReadIDs18F()Dim ID(20) As IntegerCW = &H1B: Out P, CW 'RB6,RB7 low, Vpgm=0mSec = 10: Call Dly1CW = &H1D: Out P, CW 'VPgm=HV 'RESETS Chip when Vpgm=VpgmHi, PC to 0000HmSec = 1: Call Dly1'First Set TBLPTR = 20 0000 7 bytes: 20 0000:7 contain the IDsDW = &HE20: Call CID16 'MOVLW 0x20 First MOVLW (0x0E) with &H0020,the 16-bit payload to clock inDW = &H6EF8: Call CID16 'MOVWF TBLPTRU Move's the above 0x20 byte to the Table Pointer's Upper RegDW = &HE0: Call CID16 'MOVLW 0x0 to 0xOE registerDW = &H6EF7: Call CID16 'MOVWF TBLPTRH 'Moves above to Table Pointer HighDW = &HE0: Call CID16 'MOVLW 0x00 to registerDW = &H6EF6: Call CID16 'MOVWF 0 to TBLPTRL'------Now Table Pointer Address is set to 20 0000clsFor Ju = 0 To 7Call TBLRDPinc 'Cmd 1001 Read IDs with Post Inc. Adrr CmdCall ReadData18FID(Ju) = WNextCW = &H1B: Out P, CW 'RB6,RB7 low, Vpgm=0mSec = 10: Call Dly1End Sub'=======================================================================================Private Sub ReadData18F()'Read DataA$ = "": W = 0For Js = 0 To 7 'First Clock in 8 zerosCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHiNext JsFor Js = 0 To 7 'Now Data is Clocked Out..Read DataCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW: ' Clock Hi, Data Hi, Vpgm=VpgmHiGoSub MakeNumCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiNext JsCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHibe$ = ""For R = 8 To 1 Step -1be$ = be$ + Mid$(A$, R, 1)Next RFor R = 0 To 7U = Val(Mid$(A$, R + 1, 1))If U = 1 ThenW = W + (2 ^ R) 'W = 8-Bit DATA READEnd IfNextIf Pmode Then GoTo ExitRDataLPT_Form.FontSize = 14LPT_Form.FontBold = TrueH1$ = Hex$(W): L = Len(H1$): If L < 2 Then H1$ = "0" & H1$Print H1$ & " " & Mid$(be$, 1, 4) & " " & Mid$(be$, 5, 4)GoTo ExitRDataMakeNum:U = Inp(SP) 'inp(&H379 bit 4 =SELECT IN DB25 Pin13, if bit4=1 then clocked out PDat=1U = -((U And 16) = 16)A$ = A$ + Mid$(Str$(U), 2)ReturnExitRData:End Sub'=====================================================================================Private Sub TBLWR() 'TableWrite instruction' 1100 Table Write precedes a 16-bit payload to TableCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit 0=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit 1=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit 2=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit 3=1 cmd clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 3=0 cmd clk'd in. Both Clk and Data Lo, Ready for a 16 bit Load'Now Clk in the 16-bit PayLoad DWDim Bit As IntegerFor Bit = 0 To 15 ' Clocks in 16-bits of PayLoad data LSB FirstIf (2 ^ Bit) And DW Then ' Clock in a 1CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit Bit of DW=1 clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsElse 'Clk in a 0CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit Bit of DW=0 clk'd inEnd IfNext BitEnd Sub'==================================================================================Private Sub TBLRDPinc()'18Fx5K22 Table Read Cmd 1001CW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 0=1 cmd clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHiCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 1=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 2=0 cmd clk'd inCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 3=1 cmd clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHiEnd Sub

author: amyk
author_rank: Super Contributor
timestamp: June 02, 2015, 03:37:56 pm
content: Remembering that PGD is bi-directional, are you correctly changing the direction of your programmer's port? If you put a weak voltage divider on that line you should be able to see it floating in the middle in the short times between when you're driving it and the PIC is. Look at figure 4-5 in the programming spec.At this point you might be better off getting two debounced pushbuttons and LEDs hooked up so you can bit-bang it manually... it's only a few hundred bits to key in

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 02, 2015, 03:52:10 pm
content: Thanks Amyk.I am only using the bit lines of LPT1 on the PC, when an inp(&H379) is executed by the PC the bit line is always being read.The LPT port uses Open-Drain Pull ups for HW interface, so there is never a bus collision, the bit lines are always Open-Drain outputs.As I have stated before, this magnificent programmer works perfectly with PIC 16F88x chips, so this is not an issue.When I scope the output of the PIC18F25K22 when I am reading it, I can see exactly that the output reported by my reads to my VB screen are exactly what is shown on my 4-chan scope of PClk and PDat in the read operation (ReadData18F).It is certainly a possibility that somehow I have zilched all my poor 18Fx5K22 chips.I know for sure, having done this more times that I am proud of, that if a slip-of-the-probe accident raises Vdd above 7.5V and therefore surely fries a 16F88x chip, the device will read out all zero's when I attempt to program it or read any addr. of its memory.But I can't accept that to be the case for sure yet because of the inconsistencies of reading out sometimes zero's, sometimes all 1s.But although these chips have once been exposed to Vpp=11V, Vdd has never, ever exceeded 5.0V.Besides that, the DevIDs always reads correctly.

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 02, 2015, 07:01:22 pm
content: Update: I just tried asingle row eraseof 64 bytes (for purpose of testing, the first 64 bytes of Program Memory)According to bit polling to test WR bit to see if RowErase is complete, the write of 64 bytes was successful!However I get exactly the same results, a read of the first 32 bytes of Pgm Flash Mem is all 0'sHow can a write be successful and yet fail to knock up all erased bytes to all 1's?Can anyone tell me how the instructions below work read to test a bit (the code returns a byte) topollto see if a write is completed?Please see attached copy from Pgm'ing Datasheet for further clarificationI am totally confused, according to the 18F25K22 datasheet, the EECON1 Reg is located at0xFA6, is it just me or isn't the steps below trying to manipulate 0xA6BTW these steps are directly copied from the PIC18F25K22 Pgm'ing Datasheet.DW = &H8EA6: Call CID16 'Configures ECON1 register to Enable ProgrammingDW = &H8CA6: Call CID16 'CFGS enable programming of Config Bits if Set, Reset here to Enable Pgm Flash Program MemoryDW = &H84A6: Call CID16 'WREN write enable enabled'======================================================================================Private Sub EraseSingleRow18F() 'Erases 64 Bytes in any row, but only the first row is always erased here for debuggingCW = &H1B: Out P, CW 'RB6,RB7 Low, Vpgm=0 'P is address of Parallel Port Register 0x37A which controls Vpp, Clk, DatamSec = 10: Call Dly1CW = &H1D: Out P, CW 'Set VPgm=HV ' Vpgm=Pin1=Vpp=9 V HV to enter Pgm'ing mode.mSec = 1: Call Dly1DW = &H8EA6: Call CID16 'Configures ECON1 register to Enable ProgrammingDW = &H9CA6: Call CID16 'CFGS enable Program Flash or IDsDW = &H84A6: Call CID16 'WREN write enable enabledDW = &HE00: Call CID16 'Set Table Ptr RegsDW = &H6EF8: Call CID16 'writes &H0 to TBLPTRUDW = &HE00: Call CID16DW = &H6EF7: Call CID16 'Writes &H0 to TBLPTRHDW = &HE00: Call CID16DW = &H6EF6: Call CID16 'Writes &H0 to TBLPTRLDW = &H88A6: Call CID16 'Free EnabledDW = &H82A6: Call CID16 'WREN enabledDW = &H0: Call CID16 'NOPDW = &H0: Call CID16 'NOP ERASE ROW starts at 4h bit of this instructionPoll: 'Poll WR bit of EECON1 Reg until it is clearDW = &H50A6: Call CID16 'MOVF EECON, W, 0 'Now Poll PDat line until it is LoDW = &H6EF5: Call CID16 'MOVWF TABLATDW = &H0: Call CID16 'NOPDW = 0: Call EraseRowPoll 'WR is bit 1 of EECON1 Register WRerr is Bit 2 if writting operation failed bit is setNumTries = 0Poll: 'Poll WR bit of EECON1 Reg until it is clearDW = &H50A6: Call CID16 'MOVF EECON, W, 0DW = &H6EF5: Call CID16 'MOVWF TABLATDW = &H0: Call CID16 'NOPDW = 0: Call EraseRowPoll 'WR is bit 1 of EECON1 Register WRerr is Bit 2 if writing operation failed bit is setmSec = 1: Call Dly1NumTries = NumTries + 1If (NumTries > 1000) Then Pr$ = "Failed": GoTo ExitUponFailureif (W And 2) = 2 Then GoTo Poll 'Check bit 1 = 1 WR has started in progressmSec = 30: Call Dly1 'Erase wait time is 200uS spec'd minDW = &H94A6: Call CID16 'WREN disabledExitUponFailure:CW = &H1B: Out P, CW 'RB6,RB7 Low, Vpgm=0mSec = 10: Call Dly1End Sub'=======================================================================================Private Sub EraseRowPoll() '0010 Reads Data from EECON1 for EraseRowPolling, W is byte read out from MCUCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 0=0 lsb cmd enteredCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 1=1 cmd clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHiCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 2=0 cmd enteredCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 2=0 cmd clk'd in'Read DataA$ = "": W = 0 'W has been declared Public as IntegerFor Js = 0 To 7 ' Dummy 0 bits must be Clk'd in prior to Clk'ing out 8-bitsCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW: ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiNext Js'Now Clock Out the PDat bits read and make a byteFor Js = 0 To 7 ' Now Clk'ing out 8-bitsCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW: ' Clock Hi, Data Hi, Vpgm=VpgmHiGoSub MakeNum 'Input the bit clocked out of the MCUCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHiNext JsFor R = 0 To 7U = Val(Mid$(A$, R + 1, 1))If U = 1 ThenW = W + (2 ^ R) 'W = 8-Bit DATA READEnd IfNextGoTo ExitRDataMakeNum:U = Inp(SP) 'inp(&H379 bit 4 =SELECT IN DB25 Pin13, if bit4=1 then Select In LPT1 pin13 is at Vdd, so PDat was read =1U = -((U And 16) = 16)A$ = A$ + Mid$(Str$(U), 2)ReturnExitRData:End Sub

author: amyk
author_rank: Super Contributor
timestamp: June 03, 2015, 02:58:48 pm
content: Quote from: SuzyC on June 02, 2015, 07:01:22 pmHow are you sure that your readback code works?If your readback code is broken, you can't tell the difference between a successful modification or not. Make sure you are able to read any area of memory in the (unprotected) device first, before proceeding with writing. Since the configuration bits by default will have non-FF values, I would recommend attempting to read those.

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 03, 2015, 03:34:41 pm
content: Thanks a quadrillion protected bits, Amyk.I am able to most consistently, always able to read the Dev ID bytes without error..but these two bytes are never protected.My read routine has been checked over more than once, so it is OK, it copied right out of the Pgm'ing datasheet in VB code.However, if HV bulkerase is working(looks like it is not from my reading of bits!), then I would expect the CONFIG bytes to be all erased and the write/read protects require a bit to be 0 to protect. The BulkEraseHV supposedly erases everything with the 0xF8F call.However, if the BulkEraseHV is not working, then the CONFIG bytes might all be zeroed, preventing me fromwriting or reading correctly Pgm MeM or even changing the CONFIG words!So, there still might be a possibility that I am reading a Read/Write Protected memory spaces and that is why I see all 0's.In that case I must try to program/read CONFIG words to see what I get.And that's what I will do now in the next few minutes. Just takes a few minutes to code.But in this case, the Pgm'ing datasheet would have to be error, since it is stated there that a HV will erase all without any setting write enable EECON1 permission bits. Or else my BulkEraseHV routine would have to be in error, but it is code directly copied from the steps in the Pgm'ing datasheet.If setting the CONFIG bytes fails to fix the problem, then the only reasonable possibility left is that my chips are fried!

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 03, 2015, 06:12:31 pm
content: I wrote the following code below to set the CONFIGW all to the datasheet default values (Except for WDT turned off)The result: Same problems, and MCU still shows memory erased only if I call ReadIDs18 until I do a BulkEraseHV 0xF8F, then the first 32 bytes of memory show as zeros again.Quote from 18F25K22 Datasheet:Control bit, CFGS, determines if the access will be to the Configuration registers or to program memory/dataEEPROM memory. When the CFGS bit is set, subsequent operations access Configuration registers.When the CFGS bit is clear, the EEPGD bit selects either program Flash or data EEPROM memoryI am totally confused: The settings for theEECON1 Addr 0xF6A register controls all Writesand where they are written:It has default values of: xx-0 x000The settings for EECON1 are directly from the steps Section 3.6 (See attached copy of this page if below is confusing)Note:EEPGD can enable Pgm Mem writes, but CFGS overrides this if writing to ConfigW registers =1 enabled' Control bit, CFGS, determines if the access will be to the Configuration registers or to program memory/data'EEPROM memory. When the CFGS bit is set, subsequent operations access Configuration registers.'When the CFGS bit is clear, EEPGD=1 allows Program Flash writes or if clear EEPROM memory writes are enabled'Address Name Bit7 6 5 4 3 2 1 0 EECON1' FA6h EECON1 EEPGD CFGS — FREE WRERR WREN WR RD (Default Values xx-0 x000)' 0 1 - 0 x 1 1 when x' Write EEPROM Write CfgMem Writes WREN Write' Enabled Enabled Enabled enabled Starts' if EEPGD=1 Pgm Memory if FREE=1' writes are enabled Erases are Enabled' only if CFGS=0'----------------------------------------------------------------------------------------------------------------------'DW = &H8EA6 Result' EEPGD CFGS - FREE WRERR WREN WR RD' 1 0 - 0 1 1 1 x CONFIGW Writes DisableD'DW = &H8CA6' 1 0 - 0 1 1 ? x CONFIGW Writes DISABLED'DW = &H84A6' 1 0 - 0 0 1 ? x CONFIGW writes DISABLED'-------------------------------------------------------------------------------------------------------------------How can CONFIGW words be modified if writing to them is disabled?'========================================================================================Private Sub PgmCfg18()CW = &H1B: Out P, CW 'RB6,RB7 Low, Vpgm=0 'P is address of Parallel Port Register 0x37A which controls Vpp, Clk, DatamSec = 10: Call Dly1CW = &H1D: Out P, CW 'Set VPgm=HV 'RB6,RB7 Low, VPgm=VpgmHi, Resets Chip, Enters Programming ModemSec = 1: Call Dly1CWnum = 1Again:DW = &H8EA6: Call CID16 'Configures ECON1 register to Enable ProgrammingDW = &H8CA6: Call CID16 'CFGS enable programming of Config BitsDW = &H84A6: Call CID16 'WREN write enable enabledDW = &HE30: Call CID16 'Set Table Ptr Regs to Address of CONFIGWDW = &H6EF8: Call CID16 'writes &H30 to TBLPTRUDW = &HE00: Call CID16DW = &H6EF7: Call CID16 'Writes &H0 to TBLPTRH'All CONFIG words will be set to the default/unprogrammed values shown in datasheetIf CWnum = 1 Then 'CONFIGW numberDW = &HE00DW1 = &H2500 'DW1 in every case is CONFIGnHi=MSB and CONFIGnLo=LSB where n=CWnumElseIf CWnum = 2 ThenDW = &HE02DW1 = &H1FElseIf CWnum = 3 ThenDW = &HE04DW1 = &HBF00ElseIf CWnum = 4 ThenDW = &HE06DW1 = &HFF85ElseIf CWnum = 5 ThenDW = &HE08DW1 = &HC00FElseIf CWnum = 6 ThenDW = &HE0ADW1 = &HE00FElseIf CWnum = 7 ThenDW = &HE0CDW1 = &H400FEnd IfCall CID16 'Addr=DW of CONFIG Reg PairDW = &H6EF6: Call CID16 'Writes DW to TBLPTRLCWnum = CWnum + 1DW = DW1: Call StartWrite18 'Writes LSB to &H30 000n and MSB to &H30 000(n+1) where n=CWnumIf CWnum < 8 Then GoTo AgainDW = &H94A6: Call CID16 'Resets Write Enable bit WREN, Write Enable disabled.DW = &H9CA6: Call CID16 'Disables Writing to CONFIG RegsmSec = 1: Call Dly1CW = &H1B: Out P, CW 'RB6,RB7 low, Vpgm=0 Exits Programming ModeEnd Sub

author: android
author_rank: Regular Contributor
timestamp: June 06, 2015, 12:55:24 pm
content: Hi SuzyC,It just occurred to me that I may be able to help with some actual timings. What I did was put a Salae Logic analyser on the PGD/PGC pins of a PIC18F25K50 (not quite the same as yours) and captured the successful programming of the ID bytes by my MikroProg programmer. The programmer indicated that it did a chip erase followed by write ID bytes. Verify was turned off, so that should be all that was captured.I've attached a screenshot of the "google earth" view ... it only took 3 seconds but it was way too much to show on a screen all at once. This should help guide you through the csv file that Logic created (also attached) - showing all the transitions and when they occurred.It might take a while to digest...but it just might help you nail it. Good luck.Edit: Forgot to mention, the ID bytes I programmed were: A1 A2 A3 A4 A5 A6 A7 A8

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 07, 2015, 03:24:18 am
content: Thanks Android,These pictures are quite pretty, thanks a million for taking the effort!I can do the same thing with IDs programming, now works perfect, except my word!, everything is bit too all one-ish in programming results.I have everything working now except the code flash programming.I even bought a few more brand new chips..same result!I can display any 32-byte region of memory or ID's or Config Data.I can modify CONFIG bits or change ID's, just can't seem to get the *#@a@! Program Flash pgm. Mem. to write a single byte.Note: LastAddr DW W Ju mSec, PgmCodeSize, are declared Public'=======================================================================================Private Sub Pgm18F25K()Call BulkErase18Fx 'ERASES everything but CONFIGW are set to DEFAULT VALUES'Erases Program mem even if CP=1'and erases Data mem even if CPD=1clsLPT_Form.FontSize = 14Print "Bulk Erase Completed"Call FindLastAddrPrint "Programming from 0 to "; LastAddr; "Started ": T = TimerU = 0: H = 0: L = 0Dim N As IntegerJu = 0Do While Ju < LastAddrIsBlank = TrueFor L1 = Ju To Ju + 31If Pdm(L1) <> &HFFFF Then IsBlank = False: Exit ForNextIf (IsBlank = True) ThenL = L + 32If (L = 256) ThenH = H + 1L = 0End IfJu = Ju + 32GoTo SkipBlanksEnd IfN = 0DW = &H8EA6: Call CID16 'Configures ECON1 register to Enable ProgrammingDW = &H9CA6: Call CID16 'CFGS set to Program Flash or IDsDW = &H84A6: Call CID16 'WREN write enable enabledDW = &HE00 + U: Call CID16 'Set Table Ptr RegsDW = &H6EF8: Call CID16 'writes &H20 to TBLPTRUDW = &HE00 + H: Call CID16DW = &H6EF7: Call CID16 'Writes &H0 to TBLPTRHDW = &HE00 + L: Call CID16DW = &H6EF6: Call CID16 'Writes &H0 to TBLPTRLAgain: 'Loop to fill 64-byte write buffer with 32 Pdm() wordsCall W2HiLoBytesInc2 'Cmd 1101 Table Buffer Writes 2 bytes with post Inc 2Ju = Ju + 1N = N + 2If N = 62 ThenCall Pgm64Bytes18F 'Writes last 2 bytes and starts programmingN = 0: Ju = Ju + 1ElseGoTo AgainEnd IfL = L + 32If (L = 256) ThenH = H + 1L = 0End IfSkipBlanks:LoopExitPgm18F:Print "Last Address Programmed: "; LastAddrPrint "Programming of "; PgmCodeSize; " Bytes Completed in ";Print Format(Timer - T, "###.# Seconds.")mSec = 1: Call Dly1End Sub'========================================================================================Private Sub Pgm64Bytes18F() 'Writes last 2 bytes and starts programming' Special NOP(0000) holds 4th data bit high for Pgm Time(3mS) and then Lo=200uSDW = Pdm(Ju)CW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 0=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 1=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 2=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 3=1 cmd clk'd, Cmd 1111 StartWrite clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsDim Bit As IntegerFor Bit = 0 To 15 ' Clocks in 16-bits of Payload data LSB FirstIf (2 ^ Bit) And DW Then ' Clock in a 1CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit Bit bit=1 of DW clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsElse 'Clk in a 0CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi Bit bit =0 of DW clk'd inEnd IfNext Bit' 0000 Special NOP that starts programming the ID bits on 4th bitCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 1=0 cmd enteredCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 2=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 3=0 cmd clk'd inCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHi PROGRAMMING of ID bits StartsmSec = 3: Call Dly1 ' Tprog for StartWrite must wait TDelay5=P9 with Clock held hi for programming to complete'30mSec exceeds spec P9 wait spec=1mSec.. wait extended for debugging testsCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi wait time starts with 'bit 4=0 Cmd=0000 clk'd in.mSec = 1: Call Dly1 ' (P10 Clk Lo must wait =TDly6 is Spec'd at 200uSec Minimum), wait extended for debugging test' Now clock in NOP Payload = 0For Bit = 0 To 15 ' Clocks in 16-bits of Payload data LSB FirstCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit B of DW 0 clk'd inNext BitEnd Sub'======================================================================================Private Sub W2HiLoBytesInc2()'Cmd 1101DW = Pdm(Ju)CW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 0=1 cmd clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHiCW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'bit 1=0 cmd clk'd inCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 2=1 cmd clk'd inCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW: ' Clock Lo, Data Hi, Vpgm=VpgmHi 'bit 3=1 cmd clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi'clock into buffer two bytesDim Bit As IntegerFor Bit = 0 To 15 ' Clocks in 8-bits of Lo-Byte Payload data LSb FirstIf (2 ^ Bit) And DW Then ' Clock in a 1CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H14: Out P, CW ' Clock Hi, Data Hi, Vpgm=VpgmHiCW = &H15: Out P, CW ' Clock Lo, Data Hi, Vpgm=VpgmHi bit Bit of DW = 1 clk'd inCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi 'resets Clk and Data, ready for next instruction/data bitsElse 'Clk in a 0CW = &H1E: Out P, CW ' Clock Hi, Data Lo, Vpgm=VpgmHiCW = &H1D: Out P, CW ' Clock Lo, Data Lo, Vpgm=VpgmHi bit Bit of DW=0 clk'd inEnd IfNext BitEnd Sub'========================================================================================Private Sub FindLastAddr()LastAddr = 0For J = 65535 To 0 Step -1If Pdm(J) <> &HFFFF Then LastAddr = J + 1: Exit ForNext'If LastAddr > &H7FFF Then LastAddr = &H7FFF 'later a problem with 64KB Chip??End Sub

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 07, 2015, 03:31:58 am
content: BTW: Can anyone tell mehow longit takes a real PICKIT3 or clone to write and verify, fully stuff 32KB of code into a PIC18F25K22 or similar?

author: android
author_rank: Regular Contributor
timestamp: June 07, 2015, 04:21:54 am
content: I just programmed and verified the following code (which uses all 32768 bytes of ROM) into a PIC18F25K50 ...took just under 17 seconds with a MikroProg programmer:Code:const char FIXED = "A";void main(){const char * p = &FIXED;}Hex file attached.I'll try with a PICKIT3...but I don't usually use that so I'll need to set it up.

author: android
author_rank: Regular Contributor
timestamp: June 07, 2015, 07:53:07 am
content: Ok, finally got a PicKit3 working with MPLABX again...Source...Code:#include <stdio.h>#include <stdlib.h>const char FIXED = "A";/***/int main(int argc, char** argv){const char * p = &FIXED;p++;return (EXIT_SUCCESS);}Programming messages...Code:Connecting to MPLAB PICkit 3...Currently loaded firmware on PICkit 3Firmware Suite Version.....01.37.15Firmware type..............PIC18FProgrammer to target power is enabled - VDD = 4.750000 volts.Target device PIC18F25K50 found.Device ID Revision = 1The following memory area(s) will be programmed:program memory: start address = 0x0, end address = 0x7fffconfiguration memoryDevice Erased...Programming...Programming/Verify complete...took just under 10 seconds.Hex file birds eye view png attached FWIW (the csv file was 59 MB so I couldn't attach it).

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 07, 2015, 08:25:31 am
content: That's about the same time it takes to "program/verify" on my faster PC with my QB program. On my 486 2.8GHz the total process takes 16.2 seconds, but waiting just a few seconds doesn't tax my patience.Interesting, the Vdd=4.75 with the PICKIT3, this violates the programming specsheet Max Vihh <= 9V with Vihh =Vdd+4.5 =9.25V.At the same time, programming these chips with 11V (Absolute Max V Spec for Vpgm pin 1) at 5V Vdd doesn't seem to harm these chips at all, but time will tell if I need to do a HW modification to set Vihh lower.

author: amyk
author_rank: Super Contributor
timestamp: June 07, 2015, 03:20:06 pm
content: Quote from: SuzyC on June 07, 2015, 03:24:18 amWhat was the problem?Yes it appears the PICKIT3 is using a slightly lower difference between Vdd and Vihh, but there are tolerances in these and it makes sense for the programming specs to be on the conservative side.

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 07, 2015, 08:46:14 pm
content: Thanks Amyk, but the situation of Vihh is just the opposite than conservative. The Pickit3 sets Vihh at 9.25 volts and this violates Vihh max of 9V with an over voltage of .25V.I found some simple programming errors. I wasn't reading the MCU bytes correctly because I was setting the wrong values for TBLPTR, it was a matter of my code improperly adding a byte variable to the base instruction &HE0 (MOVLW) in setting of TBLPTR by using the mistaken: DW = &HE0 + u : Call CID16The correct code:DW = &HE00 + u : Call CID16 'Set Table Ptr RegsDW = &H6EF8: Call CID16 'assigns above u address value to TBLPTRUI was also not setting the TBLPTRU,H,L to a modulus 64 =0 page boundary to start a fill of the 64 byte write buffer.I was also dividing the .hex record start address by two and so all main() code was written to the address/2.My code was also word rather than byte oriented.On the hardware side, my scope showed the problem immediately, once I started to look in the right place.In the Pgm25K22 programming sub, at the very beginning I failed to enter programming mode properly before starting the programming sequence of commands. By accident with a mouse editing screwup, I deleted a delay call so my code was raising Vihh at the exact same time as the first PClk lo to hi and there must be a 400 uSec delay after Vpgm Lo-->Hi before any change in Pclk or Pdat.I am glad that I found that all my MCU chips are undamaged and programming failure was just due to bigtime coding screwup.I could see the Hex File did not match .lst file code addresses, so the programmed result was garbage, because I was not coding to set the write buffer TBLPTR table write addresses correctly and the .hex addresses were all set to addresses/2.

author: Deathwish
author_rank: Unknown
timestamp: June 16, 2015, 11:33:38 am
content: Quote from: picandmix on May 31, 2015, 09:37:42 amJust to let you all know that this seller does indeed send these out complete in a case. I got mine today

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 16, 2015, 12:47:08 pm
content: Thanks Deathwish, I may need to get one of these someday.For now, I have gotten my DYI programmer of my own HW and SW design to work perfectly.

author: macboy
author_rank: Super Contributor
timestamp: June 19, 2015, 02:06:12 pm
content: Quote from: SuzyC on June 16, 2015, 12:47:08 pmI too have a cheap PK3 clone and it works flawlessly. Keep in mind that the PK3 is not only a programmer, but an in-circuit debugger as well. Combine that with the fact that it supports basically all PIC devices of all Vcc ranges, and integrates into MPLABX (or not if you choose), and it is a great value.One learns a lot from taking on a project like your PIC programmer, and when it is all done, the most valuable thing gained is that knowledge, not the end product. Now that you have that, your needs may be better served by the 'real thing' (or a clone of it!), at least some of the time.I've never designed my own programmer but I wrote a really nice PIC disassembler. It even sorts out program memory pages and register banks, and resolves all SFR names and labels all functions and subroutines. I will never use it enough to get real value from my time and effort, but I learned a lot writing it.

author: SuzyC
author_rank: Frequent Contributor
timestamp: June 19, 2015, 02:41:58 pm
content: I strongly disagree, macboyThanks for your advertisement for Microchip's fine products, but you've haven't at all sold me.The instrument I've developed best fits my needs better than any other because I designed it to work that way, that I always have the ability to modify it or repair it so easily, that is works so well, it is all priceless. I am not in the chip programming business and even if was, I would need to purchase a minion of professional programming devices.