Pic 18F452 Resets after ~3 second

Status
Not open for further replies.

Foldesa

Junior Member level 1
Joined
Dec 29, 2004
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
176
18f452 resets touch

Hello !

I have a 18F452 on 4 mhz.
It uses 2 interrupts: timer and RB0 (external interrupt).
The code works until I start sending the impulses to RB0.
Then it resets. Otherwise not.

Here is the most simple test program I could wrote, but it still
has an error.

Can someone help ?

Here goes:

Code:
program Teszt_int;
var
 T1Count:byte;


procedure Interrupt;
begin
if testbit(PIR1,TMR1IE)=1 then
  begin
  T1Count:=T1Count+1;
  if T1Count = 2 then
   begin
    T1Count :=   0;
    TMR1H   :=  23;
    TMR1L   := 184;
    //1 second interrupt has occured
   end;
  end;

if testbit(intcon,int0If)=1 then
 begin
 //RB0 Int
 end;

ClearBit(PIR1,TMR1IE);
clearbit(intcon,int0If);
end;


procedure init;
begin
 intcon:=$00;
 SetBit(intcon2, INTEDG0);
 SetBit(intcon2, INTEDG1);
 SetBit(intcon2, INTEDG2);
 adcon1 := 255;
 PORTA  := 255;
 TRISA  := 255;
 PORTB :=0;
 TrisB :=0;
 T1Count:=0;
 ClearBit(PIE1, RCIE);
 ClearBit(PIE1, TXIE);
 SetBit(PIE1, TMR1IE);
 setbit(intcon, gieh);
 TMR1H     := 23;
 TMR1L     := 184;
 T1CON     := $F9;
 INTCON    := $C0;
 LCD_Init(PORTD);
 lcd_cmd(LCD_CURSOR_OFF);
 LCD_Out(1,1,'Start or Reset');
 delay_ms(3000);
 lcd_cmd(LCD_CLEAR);
end;

begin
init;
 repeat
 begin
 LCD_Out(1,1,'Ok');
 end;
 until (0=1);
end.

It's in pascal, but I hope someone finds a bug in it...


Thanx

András
 

try to disable watch dog timer
 

Hi,

Have a look at the power line of the PIC, maybe when you turn on the RB0 you have a voltage drop or something.
Also, as ash said, make sure that you are not using the WDT and because you are using TMR1 you didnt use any of the fetures of the WDT.

If you found my answer useful, click on the button that says Helped me.


Good luck.
 

hai

u should not use wdt so disable it
then check that did u use any reset in that external interrupt pin
because the external interrupt rb0 has higher priority than other
 

hi,

as I can see from your code, problem lies within your initialisation code.
here you are using INT0 as interrupt pin and you are giving external pulses to it.
and statement
TRISB:=0
will configure all portB pins as output.
and u r giving input to it.
so it will be outputing 0 on INT0 pin after initialisation is done.when u give trigger then trigger signal is shorted to 0 !!!!!!!!. thats why it is resetting.

I dont know much about PASCAL. either replace
TRISB:= 0 by
1.bitwise ORing equivqlent instruction TRISB = TRISB OR 01. (this will not change your other pin directions)
or
2. set TRISB value with last bit 1.(other bits will depend upon ur other pin directions u require)


I think this should solve your problem. If no then check for WDT. else we will discuss further.Revert me back please.

Also with PIC always remember to keep unconnected pins in input mode.
If it helps then plz click helped me button and let me know.

Best Luck.

Suryakant.
 

    Foldesa

    Points: 2
    Helpful Answer Positive Rating
Hello !

suryakant u r right. There is the problem.
How stupid of me ) But if I change to
Trisb:=$FF; then it goes good.

But there still is a proble
It counts the impulses for about 1 second
then it stops counting. What is the problem ?


Thankx for the help so far.


András
 

Hi,

Nowonwards remember to proerly initialise ports.
Situation like this may damage at least that port pin and may contoller too because of PD due to short.

I did not get the logic of your code exactly....
get answers of following you may get problem solved:

why u r checking TMR1IE for 1 why not u r checking its interrupt flag....i.e.TMR1IF.

As u r clearing TMR1E at the end of ISR, by ClearBit(PIR1,TMR1IE); ,
next time when it comes in ISR then

"if testbit(PIR1,TMR1IE)=1 then "

this condition becomes false so that particular code is not executed .....

I think u should replace TMR1IE by TMR1IF in both of the above statements.....
just see what happens or elaborate about your logic of ISR

Best Luck.

Suryakant.
 

Hi suryakant !

I'v tried to replace the TMR1IE with TMR1IF, but it didn't help.
I'm no expert but I can think maybe the pin direction definiation
causes it, and some other bit(s) have to be checked. I'm reading
the datasheet but I didn't find anithing yet.

Hope someone has an idea for this too

Than you


Andárs
 

Hi,

See, you want interrupt to occur due to impulses on RB0, but u r not enabling INT0IE. so if u want interrpt on RB0 then instead of

"INTCON := $C0; "

use INTCON :=$D0;

See if this helps.
If not then, it would be better if u tell what u want to do exactly in this program.....u can tell in brief (e.g. I want to count how many pulses r coming at RB0 pin in 1sec (frequency)).....so that i can interprete ur code from that perspective.

Best Luck.

Suryakant.
 

Sorry. I wasn't clear enough.

I want to do wat you just said: count impulses in 1 second.
So an interrupt has to be generated every 1 second, and another
if RB0 gets an impulse.
I feel so confused, because I can't find the problem. Maybe if I
rest for a few days and don't think about it I would fint the problem
in a few minutes, but now "I can't see the forest from 1 single tree"

Thank you

András
 

Just enable interrupt by setting INT0IE bit in INTCON coz value of $C0 disables it.
so INTCON = $D0 should be there to enable interrupt on RB0. refer to datasheet's interrupt section.

If still thats not working then let me know

Best Luck.

Suryakant.
 

I dont'g get it.
I carfully readed all about the interrupts in the data sheet and everithing seems to be fine.
Here is the latest teszt code:
Code:
program Teszt_int;
var
 T1Count:byte;
 a,b:word;
 line:array[16] of string;

procedure Interrupt;
begin
if testbit(PIR1,TMR1IE)=1 then
  begin
  ClearBit(PIR1,TMR1IE);
  T1Count:=T1Count+1;
  if T1Count = 2 then
   begin
    T1Count :=   0;
    TMR1H   :=  23;
    TMR1L   := 184;
    //1 second interrupt has occured
    A:=A+1;
   end;
  end;

if testbit(intcon,int0If)=1 then
 begin
 //RB0 Int
 B:=B+1;
 clearbit(intcon,int0If);
 end;
end;


procedure init;
begin
 a:=0;
 b:=0;
 intcon:=$00;
 setbit(intcon2, INTEDG0);
 PORTB :=$FF;
 TrisB :=$FF;
 T1Count:=0;
 SetBit(PIE1, TMR1IE);
 setbit(intcon, gieh);
 TMR1H     := 23;
 TMR1L     := 184;
 T1CON     := $F9;
 INTCON    := $D0;
 LCD_Init(PORTD);
 lcd_cmd(LCD_CURSOR_OFF);
 LCD_Out(1,1,'Start or Reset');
 delay_ms(3000);
 LCD_Out(1,1,'              ');
end;

begin
init;
 repeat
 begin
 wordtostr(a,line);
 LCD_Out(1,1,'TMR');
 LCD_Out(1,10,line);
 wordtostr(b,line);
 LCD_Out(2,1,'RB0');
 LCD_Out(2,10,line);
 end;
 until (0=1);
end.

The timer works fine. Increments by 1 every second.
But the RB0 is not so lucky.
It does nothing consistent, and I mean it. If I toutch
it with my hand ( I shouldn't do it I know ) then it suddently
starts counting. If I send impulses it does nothing.

I'v attached the asm file, maybe the compiler does something
worng. Sorry but I'm no expert to examine the asm code.

Is it possible that the PIC damaged but works somehow?

Thank you

András
 

Hi,

Sorry for late reply....I was BZy.

"If I toutch
it with my hand ( I shouldn't do it I know ) then it suddently
starts counting. If I send impulses it does nothing. ".......
Check for proper connection to RB0.....may be by touching connection is being made and when left untouched it gets disconnected.......

u can check for pin damage by changing the code for interrupt at RB0 to interrupt at RB1 and changing software accordingly..........and give pulses at RB1 pn. if only rb0 is damaged it should work with RB1....

IF still this not works and in ur code variable A measures seconds and B measures pulses then
try replacing TMR0IE by TMR0IF in interrupt routine in ur uploaded latest code.

Best Luck.

Suryakant.
 

I assume that you have a 0.1 mfd cap from each power pin connection close to the chip to ground.

I also assume that you have mclr tied high through a resistor and that the pin is actually high. If it floats it may cause your problem.

Does it matter where you touch the chip. ie the case, the pins.
You definitely have some type of capacitive effect happening on one of the pins.

Good Luck

Enigma460
 

suryakant said:
Situation like this may damage at least that port pin and may contoller too because of PD due to short.
That's why it's a good idea to always enable BOR in the configuration fuses. And I would normally set the BOV to the highest possible value.

When you have BOR, a short at anywhere in your circuit would likely to bring the PIC to reset stage, and hance the I/O are reset to input.
 

hello !

I have tried RB0 and <RB4:7>, but the same sh*t happends. I don't know what to do. I will replace the Pic, and see what happends. If that's no good I'm going to find another way to solve the problem.

Thanx for all the replies.


András
 

check you MCLR

and try to set Low the RB0 using a Resitor.
Code:
RB0 ---------/-----\/\/\---Vcc
         |            R
         [] R
         |
        _
        GND

i can also use the
function Button(var PORT: byte; PIN, Time, Astate: byte): byte;
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…