PDA

View Full Version : Re-Programming Problem



Kamikaze47
- 4th April 2009, 18:40
I have a strange problem. Im making a program that I need to use a 32.768khz crystal on the timer1 input to get accurate timing. So I have set up timer1 in this fashion. However this uses the same pins as the programming clock and data and since i have MCLRE off in my config, I cant seem to reprogram the chip.

I've tried 3 different chips and every time i flash this program onto one of them the program goes on OK but then no matter what I do PicKit2 will not find the chip any more.

Even taking the chip out of the circuit and connecting it directly to the PicKit2 does not allow it to recognise the chip. Ive tried selecting the chip manually and erasing but it didnt work. The program is still there.

Im thinking the timer1 configuration is interfering with the communication with the progammer, and becuase MCLR is disabled, pulling MCLR low does not stop the program.

Does any1 know if there is a way for me to erase these chips cos otherwise they are pretty much dead since the program is not complete.

config:

__CONFIG _CONFIG1H, _INTIO2_OSC_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _MCLRE_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L

code:

DEFINE OSC 8

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 5
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

OSCCON.4=1 ' 8Mhz Internal Clock
OSCCON.5=1
OSCCON.6=1

ADCON0=%00000000 ' ADC off
ADCON1=%01111111 ' All I/O digital

T0CON=%10010111 ' Timer0: 16-bit, 1:256 scaler, 1=128uS, 1sec=7813
T1CON=%00001111 ' Timer1: 16-bit, 32.768 kHz external clock, $FFFF=2 sec

RF_IN VAR PORTA.7
SOLENOID VAR PORTA.2
LED VAR PORTA.3
UP var PORTA.1
DOWN var PORTA.4
ENTER VAR PORTA.5
BLANK1 VAR PORTA.0
BLANK2 VAR PORTA.6

pulse var word
temp var word
hours var byte
mins var byte

input RF_IN
INPUT UP
INPUT DOWN
INPUT ENTER
INPUT BLANK1
INPUT BLANK2

LOW SOLENOID
HIGH LED

hours=0
mins=0

PAUSE 500

LED=0


main:
gosub set_time
' Rest of the program to go here
end



set_time:
LCDOUT $FE,1,$FE,2," Set Hours"
LCDOUT $FE,$C0," ",dec2 hours,":",DEC2 mins
set_time_loop:
IF UP=1 then
gosub wait_release
hours=hours+1
if hours=24 then hours=0
LCDOUT $FE,$C0," ",dec2 hours,":",DEC2 mins
endif
IF DOWN=1 then
gosub wait_release
hours=hours-1
if hours=255 then hours=23
LCDOUT $FE,$C0," ",dec2 hours,":",DEC2 mins
endif
IF ENTER=1 then
gosub wait_release
LCDOUT $FE,1,$FE,2
RETURN
endif
goto set_time_loop


wait_release:
pause 20
waitloop:
if UP=1 or DOWN=1 or ENTER=1 then goto waitloop
pause 20
return

Acetronics2
- 4th April 2009, 19:08
Hi,

How are those chips called ??? ...

That would certainly help to know it ...

did you test your Pickit with a "valid" chip after that ??? to be sure there's no problem on its side.

Also have a look to the Microchip " Midrange manual " $ 28 ( ICSP Programming )

Alain

Kamikaze47
- 4th April 2009, 19:14
sorry, they are 18F1320 chips.

Ive tested the programmer with other chips on different programs it it works, it just as soon as I program this program to a chip its stuck there for good. Ive fixed the program by re-enabling MCLR so that the programmer can stop the program.

But ive still got 3 PIC chips that have the un-fixed program and cant seem to clear them.

i'll have a look for the Midrange manual u mentioned

Acetronics2
- 4th April 2009, 19:41
Ahhh,

18F1320 ...

I had reprogramming problems with some of them ( still have one which definitly "locked" after ~ 20 reprogrammings ) Thread posted here.

The second one took service back two Picstart plus revisions later...

Batch is 05250SE ...

Tried three programmers : Picstart+, ICD2 and a ( trustable ) "custom one" ... same behaviour.


Microchip never answered anything about that ...

Soooo, I'd encourage you to turn to another pin for pin compatible chip ( 16F88 i.e. ... )

Alain

Kamikaze47
- 4th April 2009, 19:50
I don't think that's the issue. I did this test: Grabbed a brand new, never used 18F1320 and programmed and old program on it and it worked, programmed a different program and it worked, then programmed the program posted in my OP and now the chip cant be read by PicKit2. The program runs, but I cant change or erase it.

Darrel Taylor
- 4th April 2009, 20:34
I was just reading a thread on another forum ...
http://www.electro-tech-online.com/micro-controllers/35817-junebug-pic18f1320-dead.html

They came to the conclusion that erasing it with a JDM type programmer seemed to work, when the PICkit2 wouldn't..
<br>

Kamikaze47
- 4th April 2009, 20:40
Nice work as usual Darrel. This is exactly the problem I am having. I did google it but I guess I wasnt using the right key words.

So I guess the moral of the story is: 18F1320+TMR1(w/ext clock)+MCLRE_OFF = bad

Too bad I dont have a JMD programmer. I guess i'll see if its worth building one just to revive these 3 PIC chips.

Charles Linquis
- 4th April 2009, 20:53
I have found that a Microchip ICD2 can program any part - properly (and can debug too). Even though it costs more, the time saved in debugging a programmer problem is worth it. And it programs EVERY PIC.

Kamikaze47
- 5th April 2009, 00:51
I borrowed a JMD programmer from a friend to try to erase these PICs but no luck. After doing the erase procedure and also trying programming a working program neither worked. If I apply power to the PICs after all of that I see that they still have the program on them that stuffed them up.

Is it just me, or does it seem like bad design on behalf of microchip if disabling MCLR and setting Timer 1 to external clock will create a program that cannot be erased from the PIC?

Kamikaze47
- 5th April 2009, 01:06
I finally solved it.

I found this very useful snippet in the PICkit2's User's Guide:


Use VPP First Program Entry - When checked, it allows the PICkit 2 to connect to and program devices with configurations and code that interferes with the ICSP signal pins, preventing PICkit 2 from detecting them.

Once I set that, they erased like a dream. So three 18F1320's saved from the trash :)

Darrel Taylor
- 5th April 2009, 01:25
You read the User's Guide?

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3299&stc=1&d=1238890824" /><!-- 3299 -->

Wish I'd done that :rolleyes:
<br>