Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F88 freezing in operation

Status
Not open for further replies.

SPDCHK

Member
Is it normal for a PIC to freeze during operation?

My PIC16F88 is configured as follow:

Internal RC @ 4MHz
RA1, RA2 & RA3 = Analogue measurements
RA0, RA6 & RA7 = Digital input signals
RA4 = Digital Output signal
(RA5 not used as IO, used for MCLR and Vpp for ICSP)
PORTB used for 2*20 line HD44780 type LCD

All three AI measurements are displayed on the LCD. The code also includes a real time clock, a number of starts counter and elapsed runtime timer. The circuit is used to control temperature using one AI as MV (Measured variable), one AI as SP (Set Point) for operation and the 3rd AI is used for ambient temperature indication. The SP has a hysteresis value of X°C less than SP (i.e. SP - Hyst) to switch the pump off. The SP is adjustable via a POT but the hysteresis value is called from a table in steps of 5°C. I have a counter that increments from 0 to 9 and that represents 5°C up to 50°C. This hysteresis value is stored in EEPROM to retain the last value in case of power failure or PIC reset.

The output signal is connected to another control circuit via a opto-isolator to galvanically isolate the two circuits.

The circuit run for about 2 days (I can’t pinpoint the exact time) before it just freezes up and the LCD becomes static with last shown values. No switch input or change to any of the temperature sensors can make the circuit to start up again. I’ve gone as far as to put a “heartbeat” indication on the LCD so that I can monitor the circuit. The only thing remaining is to do a reset. (Power off or MCLR).

My timer circuit (16F628) controlling my house lights and irrigation system has been running non-stop for years now. Why does the 16F88 freeze up?

Anybody willing to see what stupid mistake(s) I've made?

Thanks

View attachment AI_Measure.pdf Complete circuit diagram
View attachment AI_measure.zip MPLAB asm source code
Normal.gif Indication of normal LCD display (* = Heartbeat)
Runtime.gif Runtime and no of starts counter indication
Hyst.gif Hysteresis and real time indication
 
It should not freeze.

Setup the watch dog timer to restart you system when it hangs. You should use the WDT even if there is no problem in this sort of app. And you should still fix the problem.

There is a very good chance your code has gotten stuck in some routine and can not get out.

Can you run it connected to an debugger. You may be able to BREAK/HALT the stuck program using the debugger to see where it is, and what state everything is in.
 
3v0 said:
Can you run it connected to an debugger?
3V0. I have Bill's Junebug that I use for the ICSP, but as I understood from Bill, if I want to use the DEBUG function, I must have PORTB<6,7> free from any IO. Unfortunately my LCD display is connected to those two port pins. I haven't actually tried DEBUGGING online.

3v0 said:
Setup the watch dog timer to restart you system when it hangs
Now my ignorance is really showing :eek: How do I do that?
 
SPDCHK said:
3V0. I have Bill's Junebug that I use for the ICSP, but as I understood from Bill, if I want to use the DEBUG function, I must have PORTB<6,7> free from any IO. Unfortunately my LCD display is connected to those two port pins. I haven't actually tried DEBUGGING online.
I do not think you are using PORTB 0 or 1, Can you move PORTB LCD bit around so you can free up 6 and 7 for debugging ?

SPDCHK said:
Now my ignorance is really showing :eek: How do I do that?

I do not often send people to the data sheet but in this case
For how it works see PICmicro Mid-Range MCU Family Reference Manual
see 15.12 of the PIC16F88 datasheet for specific information on that chips Watchdog Timer (WDT)

After you get the WDT setup and running it will timeout if left alone. When it times out the processor resets and your program starts over. You place insturctions in the main loop of you program to keep the timer from overflowing. If you code gets stuck in some loop or routine the timer overflows and you are unstuck.
 
Nice schematic, if it's on a PCB it'll be difficult to modify. But if it's on a breadboard well...
As mentioned moving the LCD Data to B0-3 would free up RB6 & 7

Question what is the output range of the LM358? Can you do the setpoint R41 in software or is it best with a pot?

PS the 16F88's internal 4MHz clock will drift too much for a real time clock.
 
Last edited:
blueroomelectronics said:
Nice schematic, if it's on a PCB it'll be difficult to modify. But if it's on a breadboard well...
Yip, circuit already built and running

blueroomelectronics said:
Question what is the output range of the LM358?
Output range of the LM358 is set for 0..5V.
blueroomelectronics said:
Can you do the setpoint R41 in software or is it best with a pot?
Only after I designed the code for the hysteresis did I realize I could have made the Set Point in software as well. I might still do that, rendering the RA1 input redundant.

blueroomelectronics said:
PS the 16F88's internal 4MHz clock will drift too much for a real time clock.
Yes, I am aware of that. I only need the real time clock to reset my runtime and number of starts counters every 24 hours. If it drifts a minute a day it does not matter. :p
 
SPDCHK said:
Yes, I am aware of that. I only need the real time clock to reset my runtime and number of starts counters every 24 hours. If it drifts a minute a day it does not matter. :p

With a tolerance of 1%, it could drift up to 15 minutes per day.

Mike.
 
You could tap an extra diode off the transformer add a 10k resistor and connect it to RB0. It'll give you a nice 60Hz (or 50Hz) clock that's accurate enough for a clock.
 
blueroomelectronics said:
You could tap an extra diode off the transformer add a 10k resistor and connect it to RB0. It'll give you a nice 60Hz (or 50Hz) clock that's accurate enough for a clock.

Not from what I have heard about the S.A. grid.:)

However, if it wasn't for power cuts, the mains signal (at least in the UK) is guaranteed to be accurate over a 24 hour period.

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top