Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - problem in reading persisted value

(you are viewing a thread; or go back to list of threads)

problem in reading persisted value (by Gaurav P)
Hello people,
I am working on an event counter with 4 digit 7 segment display. I am using PIC16f628A chip for the same. I have assigned pin No. 4 to sense power failure and this input contact along with OSF has been used to activate the persist command. I am observing the following problem.
Let me tell you, the number is getting stored on EEPROM.
1. I switch OFF the power.
2. If I switch it ON in 5-10 secs the stored number is successfully and correctly displayed on the display.
3. But, if I power ON the circuit after say 30-40 seconds, the displayed value is '0000'.
4. Now I switch OFF the circuit again and switch it ON in say 05 seconds, again the correct stored value is displayed.
5. When I read the pic's data block, I see first block shows the hex of correct value, stored and second block shows "00".
remaining all the data blocks are loaded with "FF" during programming itself.
6. This means it reads the 2nd block instead of 1st block if the circuit is powered ON after time more 30-40 secs.

I cant understand why this is happening. Stuck up here. Any suggestions?

Please let me know if any one wants me to share the ladder file.

Regards,
Gaurav.
Fri Nov 4 2016, 03:26:18
(no subject) (by MGP)
Always share the ladder file, better than 1000 words ;)
Fri Nov 4 2016, 03:44:31
problem in reading persisted value (by Gaurav P)
Here it is.

The input XPF is the input I have assigned to sense power failure.

I use an external crystal for oscillations.
Sat Nov 5 2016, 07:30:02, download attachment event counter_persist.ld
(no subject) (by MGP)
It should work, I think, but I can not see how the XPF circuit is made.

You can also try a TON of 10ms after the XPF instruction, then it cannot change the variable at startup for 10mS.

Maybe you should also try version2.3 of LDmicro because I'm 100% sure this version works with saving persisted variables.
Sat Nov 5 2016, 08:54:29
(no subject) (by Gaurav P)
OK. thank you for the inputs.
Tomorrow, I will share the schematic as well.
Sat Nov 5 2016, 10:14:28
(no subject) (by Gaurav P)
Please find attached, the schematic.
Sun Nov 6 2016, 01:14:54, download attachment event counter_LDMICRO.pdf
(no subject) (by MGP)
I think its not the software but the hardware that lets you down.
Attached some questions.
Sun Nov 6 2016, 02:45:21, download attachment Snap165.jpg
(no subject) (by Gaurav P)
pls check this one. This is the refined one, which I have made ready. All extra components are cleared. Now, this may give you a correct picture.
Sun Nov 6 2016, 23:55:30, download attachment event counter_LDMICRO.pdf
(no subject) (by MGP)
If BOREN is disabled and the controller still works at 1,4V then the inputs are also working at 1,4V, you gain nothing.

But I should not do this, you have no control over the controller because you dont know when he stops working.
Its good when using batteries and 1 voltage.

You need a external circuit to control the power supply not a resistor divider.

Also pay attention when you use a circuit like the resistors R25 and R28

Some calculations/
20Vac = 28Vdc

The V on pin4 = (28/227)*47 = 5,8V
The VDD = 5V-0.7V = 4.3V

If the protectiondiode at pin4 works the current though pin 4 is more than normal, or the pic is set in programming mode before startup (usualy 13V) because the 24V is faster the the VDD.
Mon Nov 7 2016, 07:23:20
(no subject) (by MGP)
Sorry, its not to control the voltage....

But you need an additional circuit to monitor the voltage, not resistors and then also enable BOREN again.

Search for "supervisor ic" or circuit.
Mon Nov 7 2016, 15:48:58
(no subject) (by Gaurav P)
OK guys... thank you... i shall make a comparator circuit to sense power failure... I hope it works well.
Sun Nov 13 2016, 10:20:05
(no subject) (by Ihor Nehrutsa)
to Gaurav

If I understand you, you want to record the value of the Ccounter to EEPROM when power is turned off. It right idea.

1) See D122 from PIC16F627A/628A/648A Data Sheet.
TDEW - Erase/Write cycle time = 8ms These parameters are characterized but not tested.

LDmicro starts to write 1 byte into EEPROM per 1 PLC cycle time if writing is available.
Your variable Ccounter has a size of 2 bytes, PLC cycle time is 2.5 ms.
So you need 2 bytes * 8 ms + 2 * 2.5 ms = 21 ms after a power failure sensor XPF fall before the power break down.
PIC need this time for processing the EEPROM write.
The capacitor C5 must hold normal voltage Udd on time 21 ms or more.

2) See line 46: to 65: in attached file. This is an internal algorithm of the PERSIST element.
If input of PRESIST is TRUE
see line 47:
then first time only once reads the value from EEPROM to RAM variable Ccounter
see line 48: - 55:

Lines 56: - 64: executes operations
if EEPROM is ready
__if EEPROM != Ccounter
____then EEPROM := Ccounter

to be continued
Mon Nov 14 2016, 12:22:39, download attachment eventcounter_persist.pl
(no subject) (by Ihor Nehrutsa)
time chart.

to be continued
Mon Nov 14 2016, 12:31:29, download attachment power.txt
(no subject) (by MGP)
Normaly it works, I did it before, but he needs a circuit like this.
Mon Nov 14 2016, 12:46:00, download attachment Snap168.jpg
(no subject) (by Ihor Nehrutsa)
to Gaurav

Only once reads Ccounter.
Only once writes Ccounter.
Prevent changes of Ccounter if power failure sensor XPF falls.

Try this LD, based on "event counter_persist.ld".
Mon Nov 14 2016, 12:52:51, download attachment eventcounter_persist_2.ld
(no subject) (by Ihor Nehrutsa)
Comment changed.
Mon Nov 14 2016, 13:01:26, download attachment eventcounter_persist_2.ld
(no subject) (by Gaurav P)
Thank you Ihor Nehrutsa.
Will certainly try this.
Fri Jan 27 2017, 06:11:49
(no subject) (by Gaurav P)
Thank you MGP.

This timing cycle is worth detailing...
Fri Jan 27 2017, 06:12:53
(no subject) (by MGP)
Ihor, you wrote...

[Quote]
Only once reads Ccounter.
Only once writes Ccounter.

I thought that if you change "Ccounter" anyware in the program that the eeprom data will be automatically updated.

So in row 6, this row will update the eeprom variable each count of Ccounter.
Writing only once Ccounter is not true
Reading only once Ccounter is not necessary because you read allways Ccounter.

But you have between 100000 to 1000000 eeprom writes, for tests is this ok.

For counters you need another temporary variable and write this variable to Ccounter when power failure.

This is what I have learned from the manual long time ago.
Fri Jan 27 2017, 07:27:45
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):