View previous topic :: View next topic |
Author |
Message |
FBKD14_12
Joined: 19 Apr 2023 Posts: 4 Location: Ohio
|
Using a WDT |
Posted: Wed Apr 19, 2023 9:21 am |
|
|
Hello,
I am very new and trying to fill a short-term replacement position for our last Coding employee. However, I have never dealt with WDT and need some assistance to at least get started.
We are using the PIC18F27Q43
I have read manuals and viewed examples on how to implement the WDT. None of these have been helpful for our application. We have a circuit board that runs a hot tub. However, the unit will freeze and we would like to implement a WDT to restart the board when it might freeze. Our board does have a power latch.
What fuses do I need for this processor?
How would one implement this into their main loop?
Thank You to anyone willing to help! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Apr 19, 2023 9:41 am |
|
|
Depends totally on how fast the main loop actually executes?.
If in normal operation, this loop executes ten times per second, then
you would want to use a watchdog at perhaps half this (so 200mSec).
Generally watchdogs are not accurate, so you need to always allow at
least 50% 'in hand' on the worst case loop time.
Then if there are any things that 'must happen', have a test to verify
that these are happening before you reset the watchdog.
Unless you have a controlled loop time that is predictable, so will remain
within very tight margins, whatever is happening, you don't want to
use the windowed watchdog on your chip.
In most cases setup WDT_SW, and only enable the watchdog after the
initialisation. Lots of things in the boot can be too slow for the watchdog.
Easier to not fiddle with the other fuses, instead use the setup_wdt
function and specify the time you want. This actually sets up the fuses
for you (it is not actually a 'function', but a command to the compiler to
add the right fuses).
Really though you should find out why the unit freezes _first_. The
watchdog should only be used on a system that is working 100%, to
catch things like spike failures, not as a solution to a hanging system. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Apr 20, 2023 7:27 am |
|
|
hmm... hot tub controller....
I'm betting you're using mechanical relays ?
If so, you'll need to supress the arcing and sparking.
Also beef up the power supply, be 100% sure it's NOT dipping down ( less than VDD ) when relay is energized. |
|
|
FBKD14_12
Joined: 19 Apr 2023 Posts: 4 Location: Ohio
|
|
Posted: Thu Apr 20, 2023 7:49 am |
|
|
We have identified our issue to be transcient. We are just needing a short-term solution until our transcient issue has been solved.
We have determined a well ran WDT setup however, we use a condensing unit along with a heater in our application. Where we would like the Condensing Unit to have a delay after WDT resets. Is this possible?
Our chip says to work with the WDT Reset Pin Enable Option but have not found any data sheets stating how to enable it. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Apr 20, 2023 8:51 am |
|
|
Honestly you NEED to solve the PROBLEM !
Using the WDT will not reliably work.
You could easily have the PIC reset so often that it never actually runs the entire program. A 'hot tub controller' usually reads 2 or 3 temperature sensors ,checks for water pressure (flow), controls some kind of LCD display or several LEDs, looks for push button operating as well as controlling the pumps and heaters, and of course required safety circuits, so really dozens of necessary functions. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Fri Apr 21, 2023 4:43 am |
|
|
There is no 'pin' involved in the watchdog, so you are misreading the
data sheet.
The watchdog just resets the chip. However using the restart_cause
call, allows you to 'tell' that this was a watchdog, rather than a full
reset. Remember though that all peripherals need re-initialisation whne
this happens.
You need to solve your problem first.
To use the watchdog, you have to rewrite the code to support a 'warm'
recovery when this happens, or accept that this is a full reset. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 479 Location: Montenegro
|
|
Posted: Fri Apr 21, 2023 6:44 am |
|
|
Quote: | Our chip says to work with the WDT Reset Pin Enable Option but have not found any data sheets stating how to enable it. |
Reset pin enable refers to MCLR pin, which you can either enable or disable. You can see how resets work on page 235 of the datasheet.
Others have already explained in great detail why relying on WDT to "correct" some fundamental error in software or hardware is a very bad, potentially dangerous method. One success as seen from the outside can also lead to thinking that WDT reset is a magic pill that cures all the errors. It doesn't. If you are lucky, it only hides them. Hey, I for one was thinking the same at the beginning. Enable WDT, sparkle some clear_wdt()'s in your code and everything is great :-). Except it is not.
As for the transients, SSR's might help. You can find many controlled with logic level signal and also take care of zero crossing. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Fri Apr 21, 2023 6:55 am |
|
|
PrinceNai's comment about possibly using some of the smarter SSR's, is a
very good point. As he says, you can get types that will switch at the zero
crossing, and massively reduce the problems.
Also MOV's on the supplies should be thought about. |
|
|
FBKD14_12
Joined: 19 Apr 2023 Posts: 4 Location: Ohio
|
|
Posted: Fri Apr 21, 2023 11:58 am |
|
|
We do greatly appreciate and understand the concerns of using the WDT in this setting as it is unreliable and just a band aid for a potential large problem.
These will not be for the field as we trying to enable a WDT just to keep a unit running without freezing over long periods while unattended and causing a massive issue. Currently, have been looking for our transient issue.
Our board currently uses 12 SSRs to control parts. However, this board is not our control board which is receiving the transients.
However, with our PIC18F27Q43 can anyone supply a snippet of code or advice on how to determine in code when a WDT Reset has occurred? As we would like to throw the unit into a separate loop with an LED to symbolize a WDT has occurred. This will help identify for the next day what has happened.
Thank you for all the advice and help! |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 479 Location: Montenegro
|
|
Posted: Fri Apr 21, 2023 1:42 pm |
|
|
Quote: | However, this board is not our control board which is receiving the transients. |
Where do they come from?
Code is simple:
Code: |
value = restart_cause();
if(value == 7){
output_low(LED);
}
|
Put something like that at the beginning of your main. Value 7 is valid for WDT_TIMEOUT on 18f46k22, check .h file of your PIC what it is for that one. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 479 Location: Montenegro
|
|
Posted: Fri Apr 21, 2023 2:26 pm |
|
|
I re-read the topic from the start. You said: Quote: | However, the unit will freeze. | What exactly do you mean with that? PIC can't freeze, meaning doing nothing. If it runs, it is also executing some code. Obviously not the one you want, but it does something. I gather it is not resetting (and reset would be the most likely consequence if some external glitch affects the system), otherwise you wouldn't be looking for another way to reset it. Do you know where in your code it is at the time it "freezes"? Always the same place? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Fri Apr 21, 2023 3:51 pm |
|
|
You could add code similar to PC BIOS POST,where a counter gets incremented and displayed. When the display 'freezes', you know WHERE the code stopped.
I used zero cross SSR for decades. Designed them myself since the cost of 6 ZCSSR per unit was way too much (more than the entire unit !! ). |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 479 Location: Montenegro
|
|
Posted: Fri Apr 21, 2023 5:19 pm |
|
|
Quote: | where a counter gets incremented and displayed . When the display 'freezes', you know WHERE the code stopped |
Exactly. Because it is entirely possible that hardware is ok, but some condition for exiting some loop is wrong in the code, so the program can't exit from there. You never mentioned how often this freezing happens? Have you noticed that it happens when PIC performs some specific action? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sat Apr 22, 2023 1:45 am |
|
|
As a comment also, have you got the BROWNOUT fuse enabled?.
A 'freeze', is more likely to be a brownout, than something the watchdog
can handle. |
|
|
FBKD14_12
Joined: 19 Apr 2023 Posts: 4 Location: Ohio
|
|
Posted: Mon Apr 24, 2023 5:59 am |
|
|
Sorry,
When I say the unit will freeze. The micro controller seems to freeze up and take in zero input. During this time the current operation of the tub stays the same. However, using the tactile buttons to control pump, temp, cool, or hot do not work, along with many other switches. The code will freeze in random spots never the same.
Currently we have checked the button status and nothing is coming back on the overlay for noise or voltage drops. This is also a random chance in very few units that this all happens.
Currently, we are just using the WDT in a field unit to where we have a trustworthy way that while testing and the unit becomes "stuck" we can reset and continue testing.
We have the WDT set for this purpose and were able to verify the WDT reset. Is there a way to detect the WDT and skip our initialization for variables?
This would be nice for while testing these units because we would like to skip initialization for variables and pull from EEPROM to prevent our relay board from turning off during WDT.
Again, thank you to everyone for helping! |
|
|
|