I also posted this thread on the Microchip forums, but I haven't received a useful answer yet, so I'ma try it here - maybe there is somebody who can help me.

While writing very basic programs for the PIC16F684, I stumbled across a strange behavior. After putting the chip out of the programming socket on my breadboard, it runs perfectly, but when I remove the power supply (5V) and reattach it, it won't run. I made the following observations:
- after putting it back into the programmer (without re-programming), it starts working again
- when it doesn't work, the clock-out is still toggling at expected rate, but the other ports are low (the should toggle all outputs slowly, but it doesn't)
- with a bit of luck and inserting the chip the right way on the breadboard (first make the outputs connect, then the power supply), you can get it to work again.
- connecting the leads to the chip in that way won't do the trick
- when /MCLR is turned on, you can reset the chip when putting the resistor to ground, but you can't get the chip to start again when putting the resistor to +5V.

I guess it has something to do with POR, BOR or /MCLR but since I'm a newbie to PIC programming I don't know what's the cause of the behavior. Is the configuration correct?

The setup is the PIC16F684 connected to +5V on a breadboard and LEDs on the outputs.

Here is the code I'm using - it should toggle all pins at a slow rate (except /MCLR and CLKOUT)

Code:

list p=16f684
#include <p16f684.inc>

;----------------- Configuration -----------------;
__CONFIG _FOSC_INTOSCCLK & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF
ERRORLEVEL -302

;------------------- Variables -------------------;
; Bank0 = 20h-7Fh
CBLOCK 0x020

Delay1: 1
Delay2: 1

ENDC
;-------------------- Macros ---------------------;
BANK0 MACRO
BCF STATUS,RP0
ENDM

BANK1 MACRO
BSF STATUS,RP0
ENDM

MOVLF MACRO lit,file
MOVWF lit
MOVWF file
ENDM

Delay MACRO time
MOVLW time
CALL Delaybegin
ENDM


;----------- Reset Vector & Interrupts ------------;
ORG 0x000 ; processor reset vector
Goto Start ; go to beginning of program

ORG 0x004 ; interrupt vector location
RETFIE ; return from interrupt
;--------------------Start-------------------------;
ORG 0x010
Start:
BANK0
CLRF PORTA
CLRF PORTC
MOVLF 0x07,CMCON0
BANK1
clrf ANSEL ; =0 digital I/O, =1 analog input
MOVLF b'00000000',TRISA ; data direction TRIS 0: output, 1: input (Hi-Z mode)
MOVLF b'00000000',TRISC ; all outputs


BANK0
;-------------------Main Loop-----------------------;

Loop:
CLRF PORTA   ; turn LEDs off
CLRF PORTC
Delay 0xFF
DECF PORTA   ; trun them back on again; 0x000000-1 = 0x111111
DECF PORTC
Delay 0xFF
goto Loop

;------------------Sub routines---------------------;

Delaybegin:
MOVWF Delay2
CLRF Delay1
delloop:
DECFSZ Delay1
GOTO delloop
DECFSZ Delay2
GOTO delloop
 RETURN

END
It's a trivial thing (until it isn't), but do you have decoupling capacitors on your power supply near the chip? Have you tested if any other programs work on this particular chip and breadboard?
Indeed, this sounds like some sort of power issue, manifesting as latchup somewhere in the CPU core.
Try enabling the brown-out-reset (in your __CONFIG line)-- I've experienced seemingly random latchup when I had the BOD disabled, and enabling it fixed the problems. Situations where you don't want it enabled are quite rare.
Well thanks guys - A Pic12f675 worked perfectly on the same setup, but I will follow your suggestion.
I turned on the BOR and used a cap directly at the power supply of the chip, but the results are the same.
MGOS wrote:
I turned on the BOR and used a cap directly at the power supply of the chip, but the results are the same.
What about a different (known-good) program on this misbehaving chip? Anything there?
I don't have any examples and I didn't find anything useful on the web :/ like a really simple program.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement