News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

EEPROM misfire

Started by Fanie, Nov 11, 2024, 05:42 PM

Previous topic - Next topic

Fanie

I cannot believe I'm having trouble with this
I've used the Eread and Ewrite numerous times, and now cannot get it working.
I'm beginning to think the pic is broke.

Device = 16F684

Dim Drukker As Dword             ' frekwensie waarteen drukker gedryf word
Dim Voerder As Dword


Drukker = 20
       EWrite 10, [Drukker]    ' Start val for drukker 
       Voerder = 63
       EWrite 20, [Voerder]

Drukker = 0
       Voerder = 0
       Drukker = ERead 10
       Voerder = ERead 20


  Dis1 = Dig Drukker , 0                  ' Extract Current values for display
        Dis2 = Dig Drukker , 1
        Dis3 = Dig Drukker , 2
        Dis4 = Dig Drukker , 3
 
        Dis5 = Dig Voerder , 0                  ' Extract Current values for display
        Dis6 = Dig Voerder , 1
        Dis7 = Dig Voerder , 2
        Dis8 = Dig Voerder , 3
       
        GoSub Display


Display 7295 and 0100


Device = 16F684

Dim Drukker As Dword             ' frekwensie waarteen drukker gedryf word
Dim Voerder As Dword



       EWrite 10, [20]    ' Start val for drukker 

       EWrite 20, [63]

Drukker = 0
       Voerder = 0
       Drukker = ERead 10
       Voerder = ERead 20


  Dis1 = Dig Drukker , 0                  ' Extract Current values for display
        Dis2 = Dig Drukker , 1
        Dis3 = Dig Drukker , 2
        Dis4 = Dig Drukker , 3
 
        Dis5 = Dig Voerder , 0                  ' Extract Current values for display
        Dis6 = Dig Voerder , 1
        Dis7 = Dig Voerder , 2
        Dis8 = Dig Voerder , 3
       
        GoSub Display


Display 7060 and 7103


     Drukker = 20 : Voerder = 63

  Dis1 = Dig Drukker , 0                  ' Extract Current values for display
        Dis2 = Dig Drukker , 1
        Dis3 = Dig Drukker , 2
        Dis4 = Dig Drukker , 3
 
        Dis5 = Dig Voerder , 0                  ' Extract Current values for display
        Dis6 = Dig Voerder , 1
        Dis7 = Dig Voerder , 2
        Dis8 = Dig Voerder , 3
       
        GoSub Display

Display 20 and 63

John Lawton

You haven't waited for the EEPROM to write before reading it.

John

top204

If you are running an interrupt, disable it while you write to the on-board EEPROM.

The compiler's library code waits for the EERPOM to finish writing, however, the old devices did have querks, so try a small DelayMs after the EWrite command, just in case. Also, make sure your voltage is stable, because this can also effect the old dev ices while writing to flash or EERPOM.

Fanie

#3
Thank you John and Les.

No interrupts running and I had up to delayms 20 after each write and read - the longer write required is mentioned in the manual.

Perhaps this pic has a punctured EEPROM.  I'll swap it with another and try again.
I was thinking perhaps I'm staring against my eyelids and am missing something obvious.

Fanie

#4
I swapped the South African ::) (Mantech) pic out for another (Mouser) one and this one works with a delay of 20ms after each write.
It still did not work with a delayms 10 delay.  Very slow.

Thanks for looking. 
I will use the one I took off for flashing LED purposes ;D
When I started with the ESP32, my brother sent me a C flashing LED routine.
I think I must send him a flashing LED routine in Pic basic.

John Lawton

Did you set the declare correctly, (to match the actual frequency) e.g.
Declare Xtal = 4
Otherwise the EEPROM write delay might not be correct.

John

Fanie

Yes John.  I've used the same many times in the past.  Remember I have most of my analog inputs calibrate themselves automatic, they all use values saved in EEPROM.

I have lost a few pics in the not too distant past due to malfunction.  With these things you cannot do much because the user is always at fault.  You simply replace it and things go on.  Who knows, they may have been abused getting here, and some of the resellers have illiterates repackaging components by hand.  This you can see by the waveform the pins are bent on one side, and you cannot complain because then you are a racist. Trump wasn't too far off when he called this place a sht-hole.

Fanie

#7
This is weird.

I initially save 3 values, the first is only so the code at startup check to see there is a value.  If, continue to run the program.  Else save a value in each EEPROM location.

I then read these two values into variables.

The values read when the program start is incorrect, but further down in the program when I changed a value, it saves it correctly and reads it correctly.

I save 42 and 300.  The values returned when I read it directly after is 95 and 295.



I wanted to add.  Programming here on the desk returned the correct values.  I have since installed the board, and use Programmer-to-go on the PicKit4 and I have to walk back and forth to program the pic - and - since then I have had the incorrect values returned.

If I change these values when the app is running, it saves it correctly, and again with power up, the values are still correct.

       ' Test, if speed values were saved then skip
       Test = ERead 1    ' Begin Value
       DelayMS 20
       If Test <> 25 Then
          Test = 25
          EWrite 1, [Test]
          DelayMS 20
          Drukker = 42            ' 42Hz start freq for Press
          EWrite 10, [Drukker]    ' Save val for Press 
          DelayMS 20
          Voerder = 300          ' 300Hz freq for feeder
          EWrite 20, [Voerder]   ' Save Val For feeder
          DelayMS 20
       EndIf

Returns 95 and 295...

trastikata

Hi,

try breaking the word variable into bytes.

Voerder = 300         
EWrite 20, [Voerder.byte0] 
delayms 10
EWrite 21, [Voerder.byte1] 
delayms 10


Fanie

#9
Thank you Trastikata,

I have found a way around it, since there is an expected min / max value range, I simply use the expected value and write that in EEPROM in the program, which works.

It is weird that this happens, as I said I use EEPROM frequently and this is unexpected.  I plan to move away from the 16F684 anyway as my last 100 or so stock goes out, then use one of the newer faster cheaper more modern pics instead.

This project is nearing completion, it is a dough press feeder cutter for a small bakery.  Will post something in my "Something Else" thread  probably after I welded the bench it will live on.  I tested it tonight and the electronics and mechanical parts come together very well.

I want to complete it asap as I have other things sitting here the customer urgently need.