PDA

View Full Version : 12f675 very confused



glkosec
- 20th July 2009, 15:48
I have made the program below to run a simple leak test fixture. The problem I am having is that the machine randomly gets lost and the two bottom seal variables lock in the 0 or off position and do not function unless the power is taken away and the chip is reset. I have tried several different versions of the program to try and fix the problem and by everything i know and have read this should neevr happen in this situatyion. Any help would be much appreciated.
\\code\\
CMCON = %00000111 ' set all pins to digital
GPIO = %00000000 ' set all pin states to off
TRISIO = %00001000 ' All pin states to out except MCLR for trigger
WPU = %00000000 ' Shut off weak pull ups
INTCON = %00000000
'Register Initializations'


'Variables'
SWING_EXT VAR GPIO.0 ' Set variable names for pins
SWING_RET VAR GPIO.1
BOT_SEAL_RET VAR GPIO.4
BOT_SEAL_EXT VAR GPIO.5
MAIN_TRIGGER VAR GPIO.3


a0 VAR BYTE ' Byte variables for button
I VAR WORD ' Word variable for looping
'Variables'

'************************************************* ***************************
'************************************************* ***************************


INITIALIZE:
A0 = %00000000 ' INITIALIZE BUTTON BYTE TO ZERO
BOT_SEAL_RET = 1
PAUSE 500
BOT_sEAL_RET = 0
PAUSE 500

MAIN:
SWING_EXT = 1
PAUSE 500
GOTO MAIN_TRIG_CHECK
GOTO MAIN


MAIN_TRIG_CHECK:
BUTTON MAIN_TRIGGER, 1, 255, 0, A0, 1, START_OP
GOTO MAIN_TRIG_CHECK

START_OP:
SWING_EXT = 0
PAUSE 500
SWING_RET = 1
PAUSE 500
GOTO TEST

TEST:
BOT_SEAL_EXT = 1
PAUSE 500
GOTO TEST_TRIG_CHECK
GOTO TEST

TEST_TRIG_CHECK:
BUTTON MAIN_TRIGGER, 1, 255, 0, A0, 1, START_OVER
GOTO TEST_TRIG_CHECK


START_OVER:
BOT_SEAL_EXT = 0
pause 100
BOT_SEAL_RET = 0
pause 100
SWING_RET = 0
pause 100
swing_ext = 0
GOTO INITIALIZE


END
\\code\\

Archangel
- 20th July 2009, 16:53
Are you using this now on the actual machine, or just with LEDs? I am thinking reverse transients from relays or DUT, (device under test). All inductive devices must use snubber diodes and do not forget to use bypass caps on the PIC, which should be isolated from DUT.
How are your Config statments set?
You have analog stuff still turned on, ANSEL and ADCON0 need to be set.
ANSEL = 0
ADCON0 = 0
PCON = %00000011 ' BOD off, No POR flag set

glkosec
- 20th July 2009, 17:31
I am using this code on the machine itself right now. The load for all the outputs of the PIC are N-channel mosfets that turn on 12 solenoid valve coils. I have flyback diodes on all the coils to protect the PIC from voltage spikes form the coils. I turnned off the analog registers as you suggested but the problem still exists.

It seems to be more of an issue when i press the main trigger to quickly comming into the initaialize part of the program. Dont know if thats the cause or just a coincidence. Thank you for your timely help.

mackrackit
- 20th July 2009, 20:04
Do you have resistors from the MOSFET gates to the Zero rail?

Acetronics2
- 20th July 2009, 20:35
Hi,

What I see is you have forgotten to reset the A0 Button var. just before EACH Button Command ...

Generally it's a fatal error in such loops ...

Alain

Archangel
- 21st July 2009, 01:35
Hi,

What I see is you have forgotten to reset the A0 Button var. just before EACH Button Command ...

Generally it's a fatal error in such loops ...

AlainHi Alain, I never use the button command, I wondered about that, I bet that is it too . . .