Reset command on a PIC18F

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
ArthurK
Posts: 63
Joined: 16 May 2013 05:06

Reset command on a PIC18F

#1 Post by ArthurK » 22 Aug 2013 00:09

Hello, I am using the PIC18F87J50 and need to implement a software based reset. I have searched GOOGLE where some people have mentioned the assembly command RESET. I have tried to implement this as ASM RESET with no success. The compiler does not error but the command appears to do nothing. Thanks

Aquadrox
Posts: 168
Joined: 20 Mar 2012 18:11
Location: France / Gien

Re: Reset command on a PIC18F

#2 Post by Aquadrox » 22 Aug 2013 07:57

Hello,

You could use the watchdog, in normal mode you clear it, and when you want to reset you stop clearing.
For exemple:

Code: Select all

if (flags.CLR_WTCHDG)
       asm CLRWDT;
Then you just have to clear the flag somewhere and the MCU will reset.

BR.

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Reset command on a PIC18F

#3 Post by dejan.odabasic » 22 Aug 2013 15:43

Hello,

Here is the simple code which I tested with PIC18F87J50 on EasyPIC PRO v7.

Code: Select all

int i;
void main(){
  LATA = 0;
  ANCON0 = 0xFF;
  ANCON1 = 0xFF;
  TRISA = 0;
  Delay_ms(1500);
  for (i = 0; i < 3; i++){
    LATA = 0;
    Delay_ms(321);
    LATA = 0xFF;
    Delay_ms(321);
  }
  asm RESET
}
Best regards.

#MAAM#
Posts: 31
Joined: 14 Jan 2010 08:44

Re: Reset command on a PIC18F

#4 Post by #MAAM# » 22 Aug 2013 23:35

In briefly use watchdog timer.

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: Reset command on a PIC18F

#5 Post by Toley » 23 Aug 2013 00:46

#MAAM# wrote:In briefly use watchdog timer.
Why use watchdog to reset the pic??? This is not the intended use of the watchdog. You will have to wait for watchdog timeout while asm RESET is instantly. This is a valid instruction of the microcontroller and a very usefull one. I use it a lot for bluetooth bootloader with ds30loader.
Serge T.
Learning is an endeless process but it must start somewhere!

#MAAM#
Posts: 31
Joined: 14 Jan 2010 08:44

Re: Reset command on a PIC18F

#6 Post by #MAAM# » 23 Aug 2013 15:39

Toley wrote:
#MAAM# wrote:In briefly use watchdog timer.
Why use watchdog to reset the pic??? This is not the intended use of the watchdog. You will have to wait for watchdog timeout while asm RESET is instantly. This is a valid instruction of the microcontroller and a very usefull one. I use it a lot for bluetooth bootloader with ds30loader.
this exactly what i mean by using watch dog timer

erolbars@gmail.com
Posts: 2
Joined: 21 Oct 2022 17:05

Re: Reset command on a PIC18F

#7 Post by erolbars@gmail.com » 13 Apr 2023 17:26

Hi everyone,
I am trying to use the software reset on the pic18f4550 like this:

if (readbuff[64-1]==98){ soft_reset(); } //incoming data from usb as soon 98 shows up a 99 esc cmd is followed so USB data is not stuck sending 98's. this is how I do for all other USB GUI clicks buttons.
What AM am I doing wrong?

void soft_reset()
{ asm RESET;
// POR_bit =1;
// BOR_bit=1;
// RI_bit=1;

}

but the program keeps resetting in a loop! if I comment on one of the blocks above, the program flows normally.
the settings are set as follows:

<DEVICE_NAME>P18F4550</DEVICE_NAME>
<DEVICE_CLOCK>48</DEVICE_CLOCK>


<NAME>PLL Prescaler Selection</NAME>
<DESCRIPTION>Divide by 3 (12 MHz oscillator input)</DESCRIPTION>

<NAME>System Clock Postscaler Selection</NAME>
<DESCRIPTION>[Primary Oscillator Src: /1][96 MHz PLL Src: /2]</DESCRIPTION>

<NAME>USB Clock Selection (used in Full-Speed USB mode only; UCFG</NAME>
<DESCRIPTION>USB clock source comes from the 96 MHz PLL divided by 2</DESCRIPTION>

<NAME>Oscillator Selection</NAME>
<DESCRIPTION>HS oscillator, PLL enabled (HSPLL)</DESCRIPTION>

<NAME>Fail-Safe Clock Monitor</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>Internal/External Oscillator Switchover</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>Power-up Timer</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>Brown-out Reset</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>Brown-out Reset Voltage</NAME>
<DESCRIPTION>Minimum setting</DESCRIPTION>

<NAME>USB Voltage Regulator</NAME>
<DESCRIPTION>Enabled</DESCRIPTION>

<NAME>Watchdog Timer</NAME>
<DESCRIPTION>Enabled</DESCRIPTION>

<NAME>Watchdog Timer Postscale</NAME>
<DESCRIPTION>1:8192</DESCRIPTION>

<NAME>CCP2 MUX bit</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>PORTB A/D</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>Low-Power Timer 1 Oscillator</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>MCLR Pin</NAME>
<DESCRIPTION>Enabled</DESCRIPTION>

<NAME>Stack Full/Underflow Reset</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>Low Voltage Program</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>Dedicated In-Circuit Debug/Programming Port (ICPORT)</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>Extended Instruction Set</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>

<NAME>Background Debug</NAME>
<DESCRIPTION>Disabled</DESCRIPTION>


here is the main()

I dont see the problem , please Help
Thanks


void main()
{

init();



for (i = 1; i < 65; i++) {
writebuff[i-1]= 0; //msb

}
HID_Write(&writebuff,64);
Delay_ms(120);



// DD++;
GIE_bit =1;
// DD[0] = DD % 10 + '0';
onetimeFLG=1;

// SSD1306_Init(SSD1306_SWITCHCAPVCC, 0x78);
// (writebuff[60-1]) = EEPROM_Read(60);

// EEPROM_Write(60,errorFLG);




while(1) {
WATCHDOG(_ON);
// asm{ &&(RedLED==1))
GIE_bit =1; // CLRWDT
// } // watchdog at 8 sec if program hangs char Soft_UART_Init(char *port, char rx_pin, char tx_pin, unsigned long baud_rate, char inverted);
HID_Read() ; // put this here is a strong USB com
HID_Write(&writebuff,64); // put this here is a strong USB com

// Send bytes from 'z' downto 'A'

(writebuff[60-1]) = (RCSTA.OERR*1)+(RCSTA.FERR*2)+(BOR_bit*4)+(POR_bit*8)+(PD_bit*16)+(TO__bit+32)+(RI_bit*64) ;


CheckUSBcmdFromPC();


AVGanalog();

if ( Mot11Start==1 || Mot12Start==1 || Mot13Start==1 || Mot14Start==1){statusbit4=1;ServoVLV14W();}
if ( Mot21Start==1 || Mot22Start==1 || Mot23Start==1 || Mot24Start==1){statusbit5=1;ServoVLV24W(); }

if( Mot6Start1==1 || Mot6Start2==1 || Mot6Start3==1 || Mot6Start4==1 || Mot6Start5==1 || Mot6Start6==1){ statusbit6=1; ServoVLV16W();}
if ( SY1StartUp==1 || SY1StartDwn==1) {SY1step(); }
if ( SY2StartUp==1 || SY2StartDwn==1) {SY2step(); }

if (SY1SY2cycleStart==1) { DrawAcidRQFlag=0; DeliverAcidToLabRQFlag=0;
SYcycleStart();

}

if (DrawAcidRQFlag==1){
SY1SY2cycleStart=0; DeliverAcidToLabRQFlag=0;
DrawACID();


}
if (DeliverAcidToLabRQFlag==1){
SY1SY2cycleStart=0;
DrawAcidRQFlag=0;

DeliverACID();
}

// Portd.RD4=~ Portd.RD4; // if ( RedLED==1) {SY1step1(); } SY1StartUp=0; SY1StartDwn=0; SY2StartUp=0; SY2StartDwn=0;SY1SY2cycleStart=0; DeliverAcidToLabRQFlag=0;
//////================SY1=================



if (readbuff[64-1]==50 ){ //SY1 MOMENT UP


// GIE_bit =0;
Stepper1Enable=0; //active on low
// Sound_Init(&PORTB, 2);
Stepper1DIR=0; //Dir UP
// Sound_Play(SpeedStepper12, 100);
// PWM1_Init(SpeedStep); //Ch13 pn RC2
// PWM1_Start();
// PWM1_Set_Duty(Duty);


}

if (readbuff[64-1]==51){ //SY1 MOvMENT DWN


// GIE_bit =0; //
Stepper1Enable=0; // this disable the stepper drv and stop putting power to the motor to avoid heating if set to 1
// Sound_Init(&PORTB, 2);
Stepper1DIR=1; //Down
// PWM1_Init(SpeedStep);
// PWM1_Start();
// PWM1_Set_Duty(Duty);// Sound_Play(SpeedStepper12, 100);

}
//////================SY2=================
if (readbuff[64-1]==52){ //Dir UP //MOMENT sy2 UP
//GIE_bit =0;
Stepper2Enable=0;
// Sound_Init(&PORTB, 3);
Stepper2DIR=0;
// PWM1_Init(SpeedStep);
// PWM1_Start();
// PWM1_Set_Duty(Duty);


}
if (readbuff[64-1]==53){ //Down //MOMENT sy2 DWN
// GIE_bit =0;
Stepper2Enable=0;

Stepper2DIR=1;
// PWM1_Init(SpeedStep);
// PWM1_Start();
// PWM1_Set_Duty(Duty);

}

iii++;

if (iii>=100){ iii=0;
// EEPROMRecall(); // WATCHDOG(_ON);
// displadataToLCD();
writebuff[61-1] =(statusbit0*1)+(statusbit1*2)+(statusbit2*4)+(statusbit3*8)+(statusbit4*16)+(statusbit5*32)+(statusbit6*64)+(statusbit7*128);
// (writebuff[60-1]) = (status1bit0*1)+(status1bit1*2)+(status1bit2*4)+(status1bit3*8)+(status1bit4*16)+(status1bit5*32)+(status1bit6*64)+(status1bit7*128);

}


iiiii++;
PEIE_bit =1;
if (iiiii>=1000) { // every 10 sec read PWM serial

GIE_bit =0;
// UA



if ((UART1_Tx_Idle() == 1) && (UART1_Data_Ready() == 0) ){ //reset this when buton mouse GUI is up) { // stay here until data buffer empty {
UART1_Write_Text("read");
iiiii=0;
// UART1_Read();
GIE_bit =1;

GreenLED=~GreenLED;

} //
}
// if(UART1_Data_Ready() ==0 ){ // proceed when data buffer empty
if( byte_read[0]== 'F' ){ // look for start byte 'F'


C2++;
(writebuff[48-1]) = C2; // enter 50 in dec = 2 in char convert int to ascii byte
(writebuff[49-1]) = byte_read[C2];// ;

if (C2>=17){C2=0;}
}





if (RCSTA.OERR || RCSTA.FERR || BOR_bit ==0 || POR_bit==0 || PD_bit==1 || TO__bit ==0 || RI_bit==0 )
{
RCSTA.CREN = 0;
RedLED=~RedLED;
RCSTA.CREN = 1;
}

// asm {CLRWDT}// watchdog at 8 sec if program hangs char Soft_UART_Init(char *port, char rx_pin, char tx_pin, unsigned long baud_rate, char inverted);

if (onetimeFLG==1){
EEPROMRecall(); // WATCHDOG(_ON);
// GIE_bit =0;
// initLCD();
// PrintLCDstaticInfo();
onetimeFLG=0;
// GIE_bit =1;
// WATCHDOG(_OFF);
}


GIE_bit =1; //PEIE_bit =1;

// WATCHDOG(_ON);

}; //while




} //main

Post Reply

Return to “mikroC PRO for PIC General”