CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16f627 need help for implemented Watchdog

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
romano21



Joined: 04 May 2018
Posts: 8

View user's profile Send private message

PIC16f627 need help for implemented Watchdog
PostPosted: Fri May 04, 2018 4:59 am     Reply with quote

Hello to all ! A few years ago a man give me a program for pic16 that he had created.

I spend long time for doing a functional electronic part, today the case works.

Simple system with 1 push button and 1 led and which allows to switch in SP95 (fuel classic ) or E85 mode.
FIXED LED = unleaded mode (long press on the button).
Flashing LED 6x = E85 mode (long press then 6 short press).

But it happens totally randomly that the program crash, after 3 days or 3 weeks or after 1 year.

My car goes wrong and the box in LED off or then it goes back into SP95 (fixed LED) randomly.

The program prevents any programming in eeprom 10 seconds after startup.

The box must then be reprogrammed manually using the push button.
This phenomenon is very probably caused by electrical disturbances it is impossible for me to reproduce the phenomenon.

I know i need to integrate WATCHDOG in my program.

But I am no ideas of how and where to place WDT in my program. My experience with C programming is very limited.

I use Mplab to compile the program PIC16F627. Can someone help me ? Thanks ! Sorry for my english.
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Fri May 04, 2018 1:49 pm     Reply with quote

Are you using CCS C?.
If not this is not the forum to be asking.

Honestly you need to be fixing the electrical disturbance causing the problem. A watchdog is not a fix for such problems.
BOR might help ensure a clean restart, but a BOR restart or a watchdog restart is going to involve the code restarting, so it won't be in the state it was when running.
Automotive applications require very careful hardware design, since this is a noisy environment.
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat May 05, 2018 11:31 am     Reply with quote

I have to agree with Mr. T., automotive products have to be very, VERY well designed ! Starting with proper PCB design and layout, every I/O well filtered, shielded cabling, mumetal box, robust power supply, correct PB debounce are just a few of the items that need to be done.
A WDT is a 'crutch' or 'bandaid', something used as a last resort. It is vital to find out WHAT is causing the problem. Airborne EMI, cell phone, bad alternator, power surge, crosstalk, EMP from lightning 20 miles away, the list is endless... but each and every issue has a solution.
romano21



Joined: 04 May 2018
Posts: 8

View user's profile Send private message

PostPosted: Tue May 08, 2018 4:40 am     Reply with quote

I agree with you and i work for this.

But watchdog is not useless for my situation and even if agree with you for hardware parts, i just need help for place watchdog in my program. I can share my program if needed.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 08, 2018 12:12 pm     Reply with quote

romano21 wrote:

I just need help for place watchdog in my program. I can share my
program if needed.

In your program you will most likely have a main loop. This loop will be
a continuous while() statement. Inside the loop you call various functions.
But what if one of those functions hangs up ? What if it doesn't return
to the main loop when it's finished ? In that case, the watchdog timer
will timeout and reset the PIC. It may not cure the problem.
The problem could be a bad sensor. But this is the most simple implementation:
Code:

while(TRUE)
  {
    data = read_sensor();
    final_data = process_result(data);
    display_result(final_data);

    restart_wdt();   // Restart WDT if we didn't hang.
   }
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Tue May 08, 2018 1:37 pm     Reply with quote

and then you of course need to work out the slowest routine the code may ever need to execute, and set the watchdog interval to be longer than this.
Ideally you have the restart only executed if all the component parts of the code have executed correctly.
romano21



Joined: 04 May 2018
Posts: 8

View user's profile Send private message

PostPosted: Tue May 08, 2018 1:50 pm     Reply with quote

Main.C

Last edited by romano21 on Wed May 09, 2018 2:00 am; edited 1 time in total
romano21



Joined: 04 May 2018
Posts: 8

View user's profile Send private message

PostPosted: Tue May 08, 2018 1:52 pm     Reply with quote

Timer.c

Last edited by romano21 on Wed May 09, 2018 2:00 am; edited 1 time in total
romano21



Joined: 04 May 2018
Posts: 8

View user's profile Send private message

PostPosted: Tue May 08, 2018 1:54 pm     Reply with quote

ihm.c ( human machin interface )

Last edited by romano21 on Wed May 09, 2018 1:57 am; edited 1 time in total
romano21



Joined: 04 May 2018
Posts: 8

View user's profile Send private message

PostPosted: Tue May 08, 2018 1:56 pm     Reply with quote

eprom.c

Last edited by romano21 on Wed May 09, 2018 1:55 am; edited 1 time in total
romano21



Joined: 04 May 2018
Posts: 8

View user's profile Send private message

PostPosted: Tue May 08, 2018 1:57 pm     Reply with quote

timer.c

Last edited by romano21 on Wed May 09, 2018 1:54 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 08, 2018 5:35 pm     Reply with quote

romano21 wrote:
Main.C

#include <htc.h>

You're using the Hi-Tech compiler. We're only supposed to answer
questions for the CCS compiler. This is the CCS forum.
romano21



Joined: 04 May 2018
Posts: 8

View user's profile Send private message

PostPosted: Wed May 09, 2018 2:01 am     Reply with quote

Sorry for that !
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group