Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Watch Dog Timer

Status
Not open for further replies.

Manpreet1604

Junior Member level 1
Joined
Nov 20, 2015
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,422
Code:
#include <xc.h>

#pragma config FOSC = INTOSCIO  
#pragma config WDTE = ON    
#pragma config PWRTE = OFF      
#pragma config MCLRE = OFF      
#pragma config CP = OFF        
#pragma config CPD = OFF      
#pragma config BOREN = OFF      
#pragma config IESO = OFF      
#pragma config FCMEN = OFF

#define LED1 GPIObits.GP4 // Pin No. 3
#define LED2 GPIObits.GP5 // Pin No. 2
#define LED3 GPIObits.GP0 // Pin No. 7
#define LED4 GPIObits.GP1 // Pin No. 6
#define INPUT GPIObits.GP2 // Pin No. 5

void delay_1ms();
unsigned char count = 0;

void main (void){        
   
      ANSEL = 0x00;  // turn off analog inputs
      ADCON0 = 0x00; //Turn off ADC
      CMCON0 = 0x07; //Turn off Comparators
      VRCON = 0x00; //Turn off Voltage Reference

    OSCCON = 0b01110000;  // internal oscillator, 8 MHz
    OPTION_REG = 0b00001111;//Prescalar assigned to WDT
    TRISIO = 0x04;//make GP2 as input and rest as output
 
    LED1=0; // set initial state of pin
    LED2=0;
    LED3=0;
    LED4=0;

while(1){

  SLEEP();               // Sleep mode

  LED2 = 1;                 // After wake-up the LED is turned on
  LED1 = 1;
  delay_1ms();
  LED2 = 0;
  LED1 = 0;
 
         if (count == 6){
             LED3 = 1;
             delay_1ms();
             LED3 = 0;
             count = 0 ;
         }
         
           if (INPUT == 1){
           LED4=1;
           LED1=1;
           LED2=1;
           LED3=0;
           CLRWDT();
      }
         
 }

}

void delay_1ms(){  
   
    TMR0 = 0 ;
    while (TMR0 < 200);
    count = count++ ;
}


hello everyone i am working with pic 12F683 and trying to learn WDT mode in this code iam able to turn on my LED 1,2 and 3 at desire time but unable to execute "
if (INPUT == 1){
LED4=1;
LED1=1;
LED2=1;
LED3=0;
CLRWDT();
}
"

I want to read the Input pin when Led1 and Led 2 goes high hardware is simple I have a pic 12f683 with 4 led and INPUT iam using jumper wire any help will be appreciated thanks.
 

Hi,

We don't see your schematic, thus we don't know when a switch or a LED is ON.
1ms LED on or off is not (good) visible.
WDT timeout is unclear
WD is cleared in input = 0 only

I don't know
* how you tested it and the test setup
* what you expect
* what you see instead

Klaus
 

Depending on the purpose of the watchdog timer, doing
it in code may not be the right idea. Watchdogs are often
used to ensure that a functional interrupt or infinite loop
cannot hang the program / OS execution. For such a use
you'd like something entirely independent of the processor.
Something like a retriggerable one-shot that gets reset by
code execution very specifically (i.e. quite unlikely to happen
by accident if the program / processor locks up), and throws
a non-maskable interrupt if it does ever time out.

Probably not the question you had in mind, but worth
considering.

If the watchdog resource fits this model (i.e. an independent
chunk of circuitry that the processor can only retrigger by
specific execution, and jerks the processor back if it hits)
then maybe it is useful for what I describe. But a ourely-code
"watchdog" might well sleep on the job if execution ceases
(or goes off into the weeds).
 

Hi,

We don't see your schematic, thus we don't know when a switch or a LED is ON.
1ms LED on or off is not (good) visible.
WDT timeout is unclear
WD is cleared in input = 0 only

I don't know
* how you tested it and the test setup
* what you expect
* what you see instead

Klaus
hello
there is nothing to show in hardware LED1 and LED2 are basic IR transmitter and receiver sensor LED3 and LED4 are just for indicators, LED1(IR_RX) and LED2(IR_TX) blinks after every 2 sec due to WDT timeout and controller go back into sleep mode LED3 is for indicate that code is working by blinking after every 10 or 12 sec and LED4 is indicator for INPUT pin.

in code when LED1 and LED2 goes high it means IR transmitter and receiver activated if there is any obstacle it will detected by the INPUT pin at gp2 and output at LED4 permanently high for now detecting the input iam using jumper wire directly short with gp5 through 10k resistance
--- Updated ---

Depending on the purpose of the watchdog timer, doing
it in code may not be the right idea. Watchdogs are often
used to ensure that a functional interrupt or infinite loop
cannot hang the program / OS execution. For such a use
you'd like something entirely independent of the processor.
Something like a retriggerable one-shot that gets reset by
code execution very specifically (i.e. quite unlikely to happen
by accident if the program / processor locks up), and throws
a non-maskable interrupt if it does ever time out.

Probably not the question you had in mind, but worth
considering.

If the watchdog resource fits this model (i.e. an independent
chunk of circuitry that the processor can only retrigger by
specific execution, and jerks the processor back if it hits)
then maybe it is useful for what I describe. But a ourely-code
"watchdog" might well sleep on the job if execution ceases
(or goes off into the weeds).
hello
there is nothing to show in hardware LED1 and LED2 are basic IR transmitter and receiver sensor LED3 and LED4 are just for indicators, LED1(IR_RX) and LED2(IR_TX) blinks after every 2 sec due to WDT timeout and controller go back into sleep mode LED3 is for indicate that code is working by blinking after every 10 or 12 sec and LED4 is indicator for INPUT pin.

in code when LED1 and LED2 goes high it means IR transmitter and receiver activated if there is any obstacle it will detected by the INPUT pin at gp2 and output at LED4 permanently high for now detecting the input iam using jumper wire directly short with gp5 through 10k resistance
 

Attachments

  • SDMTS.PDF
    12.3 KB · Views: 122

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top