PIC16F877A Reset due to UART functions

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
arvinfx
Posts: 115
Joined: 22 Feb 2010 18:44

PIC16F877A Reset due to UART functions

#1 Post by arvinfx » 12 Jul 2023 14:29

Hi,
I have this problem in two projects both codes are so similar. I have TMR1 interrupt each 100ms and also UART1_Write_Text in some place of code.
Problem is Random reset occur in both project or some time my program halt or do wrong code. At first I wonder that my Micro has some damage or Flash rom is not well ! but by erasing UART functions problem has solved totally!!! Now I think random reset and code error happen when within UART functions interrupt is occur but I need to have both! so i would be happy to hear about solving this problem from you guys.

Code:

Code: Select all

program test


Dim encoder_count,Motor_HZ,old_encoder_count as word
txt as string[5]

sub procedure interrupt
    Intcon.7=0
    if PIR1.TMR1IF then                                                      
       timer=timer+1                                                          
    
       if encoder_count > old_encoder_count  then                              
          Motor_HZ= encoder_count - old_encoder_count                           
       else
           Motor_HZ=old_encoder_count - encoder_count                        
       end if
       old_encoder_count = encoder_count                                       
       TMR1H = 11 TMR1L = 220
       clrwdt
       PIR1.TMR1IF=0
    end if
    Intcon.7=1
end sub


main:

OPTION_REG=%11001111   
Intcon=%11011000 
T1CON=%00110001
TMR1H = 11                                                                      
TMR1L = 220  
PIE1 =%00000001 
UART1_INIT(115200)

lop:
  wordtostr(PCON,txt) 
  UART1_Write_Text("PCON="+txt+chr(10)+chr(13))
  delay_ms(100)
goto lop

Firewire
Posts: 166
Joined: 20 Jun 2009 17:12

Re: PIC16F877A Reset due to UART functions

#2 Post by Firewire » 12 Jul 2023 19:06

If the controller does a reset then something is wrong with the circuit.
Try a baud rate of 9600. As written it must not make a reset because then something is wrong with the circuit.

arvinfx
Posts: 115
Joined: 22 Feb 2010 18:44

Re: PIC16F877A Reset due to UART functions

#3 Post by arvinfx » 13 Jul 2023 08:08

Firewire wrote:
12 Jul 2023 19:06
If the controller does a reset then something is wrong with the circuit.
Try a baud rate of 9600. As written it must not make a reset because then something is wrong with the circuit.
Thanks for participation.
9600 BUAD rate make it worse! Even I can remember that on 1st project I ran simulator on Proteus and same reaction happened , so it is not hardware it is software issue . Might be Stack overflow / underflow because some time reset not occur beside my code execute wrongly like variables are wrong or changed!
I hope someone from MikroElectronica team participate in this topic.

Post Reply

Return to “mikroBasic PRO for PIC General”