PDA

View Full Version : PIC keeps resetting when executing subroutine



jbirnsch
- 26th August 2009, 01:25
All,

I am having problems with the below code when the subroutine warning is executed. PortA.0 is pulled high with a 1k. When the bin is full the limit switch pulls PortA.0 low. The buzzer and light will blink 2 times then the PIC will reset. I have used 2 different PIC's. - F84A and F819. Both PIC's do the same thing. 5V is solid and I have plenty of decoupling and bulk capacitance sprinkled throught the circuit. For the warning lamp and buzzer driver I use 1k to the base of a 2N4401 transistor's to drive the light and buzzer. I tried Tris statements and ADCON setup with the F819 with no help. I have tried HC and XT osc drive settings. Both parts are rated for 20MHz operation. I set power up timer to off and brownout off. All I want is the buzzer and light wo toggle 5 times then if the switch is still low at PORTA.0 then just have the binlight on until PORTA.0 hoes high. I'm about to smash this with a hammer soon as something this simple should not cause this much trouble.

Any help here is appreciated.



'************************************************* ***************
'* Name : Combine.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 8/15/09 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************

define OSC 20

'ADCON0 = %11000001
'ADCON1 = %10001110

'trisa = %00001110
'trisb = %11110111

binlight var porta.1
buzzer var portb.2
backup var porta.2
alarm var byte

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

low buzzer
low binlight
low backup

PAUSE 500
alarm = 0
high buzzer
high binlight
high backup
pause 500
toggle buzzer
toggle binlight
toggle backup

LCDOUT $FE,1
LCDOUT $FE,$80, "TattleTale X"
LCDOUT $FE,$C0, " Monitor"
pause 5000
LCDOUT $FE,1

monitor:

LCDOUT $FE,$80, " No Alarms"
LCDOUT $FE,$C0, " "
if alarm = 1 then
goto light
endif
if PORTA.0 = 0 thEN
alarm = 1
GOsub warning
ELSE
GOto monitor
endif


warning:
LCDOUT $FE,1
LCDOUT $FE,$80, " BIN FULL!!!"
LCDOUT $FE,$C0, " "
high binlight
high buzzer
pause 200
toggle binlight
toggle buzzer
pause 200
toggle binlight
toggle buzzer
pause 200
toggle binlight
toggle buzzer
'pause 200
'high binlight
'high buzzer
'pause 200
'low buzzer
'low binlight
RETURN


light:

if PORTA.0 = 0 then
high binlight
else
alarm = 0
GOTO monitor
endif

Jerson
- 26th August 2009, 01:55
monitor:
LCDOUT $FE,$80, " No Alarms"
LCDOUT $FE,$C0, " "
if alarm = 1 then
goto light
endif

if PORTA.0 = 0 thEN
alarm = 1
GOsub warning
endif
GOto monitor


This might be better.

jbirnsch
- 26th August 2009, 04:07
It still resets when the warning subroutine is run. I am going to try another computer to compile and generate the hex code. I am currently useing an ancient laptop with 98SE.

mackrackit
- 26th August 2009, 04:39
Just for fun, replace the tranistor driveres, buzzers, lamps with LEDs.
Could still be a hardware problem and this will tell.

Archangel
- 26th August 2009, 04:54
I am currently using an ancient laptop with 98SE.
All I use is win98se. Maybe you are browning out due to inadequate power supply.

jbirnsch
- 26th August 2009, 05:18
I can remove the buzzer and lamps by unplugging a connector and the PIC still resets as I can see what's going on with the LCD screen. I tried a different computer and the result is the same.....

jbirnsch
- 26th August 2009, 05:34
Maybe you are browning out due to inadequate power supply

I checked that also with my scope. Power is solid.

I am using a 2A DC/DC converter PT6212E-5 on my circuit board with plenty of bulk capacitance. I have used these parts on many of my other PIC projects without problems. I am using a 3S1P Lipoly battery pack that can supply 30A cont current for my 12V input until it can be installed. I am using PBP V2.46 with the patch installed and the latest beta programming software with my epic programmer. The epic software on CD V3.30 gives the same reset problem...

Jason

languer
- 26th August 2009, 09:29
I know the following is commented out, but not sure what is going on here:
'ADCON0 = %11000001
'ADCON1 = %10001110

'trisa = %00001110
'trisb = %11110111
You want to make sure all the analog inputs (ADC and Comparators) are set to digital. Also I think your TRIS directives are backwards (i.e. desired output are inputs and viceversa). Again this is commented out, but you should be defining these things at the beginning.

Not sure what the real problem is, but somehow I think you are having a stack overflow.

Try replacing the "GOsub warning" with "GOto warning"; and "RETURN" with "GOto monitor".

Ioannis
- 26th August 2009, 10:36
Try the attached file removing the .txt

Also as languer noted, your TRIS set up is commended out. Why? According to your variables, there is a conflict with the TRIS settings. Perhaprs an input is not biased and seen as high or low irrelevant what you really do on the pin.

Ioannis

aratti
- 26th August 2009, 11:50
Hi Ioannis, I would also modify label light as per the attached code, because otherwise if portA.0 is zero then program will put high binlight and end.


light:
if PORTA.0 = 0 then
high binlight
else
alarm = 0
endif
GOTO Monitor

end


Al.

Ioannis
- 26th August 2009, 13:31
Nice Al. I missed that!

Ioannis

jbirnsch
- 26th August 2009, 15:03
I will try this tonight when I get home from work.

I had commented the ADCON out when I switch from a 16F819 to a 16F84A. The 84A does not have a A/D conveter.

Having the TRIS commented or uncommented did not make a difference.

If I cant get this to work I will switch to a SX28 processor. I have the code working on my DEV board with LED's with SX/B.

Jason

Ioannis
- 26th August 2009, 19:23
It is absolutely necessary to define the state of the Inputs and Outputs. On Reset the controller set all pins as inputs.

Give special attention as to which pins you define inputs and outputs. There are cases that pins are not only inputs but set as analog input too!

So,

1. Read with extreme attention to the details the datasheet for the MCU you use.

2. Set if any analog/comparator inputs accordingly

3. Set the pins as inputs and outputs (unused as outputs and unconnected)

Ioannis

khoog
- 27th August 2009, 02:20
Have you disabled the watchdog timer?

jbirnsch
- 27th August 2009, 05:24
Got it working. Thank's Ioannis and every one else. It must have been stack overflow. I'm getting rusty. Used to do 5 or 6 PIC projects a year but haven't done one in 2 years.

Jason

Ioannis
- 27th August 2009, 07:03
You are welcome.

Ioannis