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.

forgetful EEPROM (on F627)

Status
Not open for further replies.

Adam

New Member
I'm using a pic 16F627, Picbasic, Ic prog and a JDM programmer

I have a chip programmed to if you hold the switch down on startup, it sets a variable to 1, writes it to eeprom. Then carries on with startup as normal

The next part (only part, if no switch held down) of it is done everytime it starts up, is to set the varaible to 0, read the variable from the eeprom and if its equal to 1, to switch on output on.

The problem is that when you hold down the switch when switching it on, it will switch the output on, its obviously written and read back the eeprom, but if you switch it off and on again without the switch held down, the output stays low, its as if the eeprom has forgotten its contents

any ideas?, I can post the simple code here later, but I do not have it on this computer

Adam
 
It is very rare that an EEPROM will forget things it has been given to memorize unless
1) You have exceeded the endurance cycle of EEPROM (around 10M). This will rarely happen.
2) Your program is accidently writing to the EEPROM.

Do this in your code.
Forcefully disable the EEPROM memory write (WREN) at startup (eventhough it is disabled at startup).
Enable EEPROM memory only when it is is read or write.
This may solve your problem.

And to know if there are any other bugs, post your code here.
 
If I understand what you are trying to do, then I would think that you should check the eeprom first.

I.E.

Code:
turn off output
if eeprom = 1 turn on output
set eeprom = 0
if button pressed set eeprom = 1

The above would turn the output on if the button was pressed when the circuit was previously powered up. Is that what you are trying to do?

Mike.
 
any ideas?, I can post the simple code here later, but I do not have it on this computer

The eeprom may be inadvertently being overwritten as the the chip is being powered down. Make sure you disable writing to the eeprom (BCF EECON1,WREN) after each write is completed. Post your code.
 
I've never been able to have it working the f627 with picbasic's built in read and write commands, a mate of mine wrote the parts that set the registeres directly.

This isn't my final code, its merly all the stuff that works stripped out, so I can work on the bit that doesn't work.

Code:
'@ device INTRC_OSC_NOCLKOUT
'eeprom 1, [0]

EECON1   = %00000000		'Control 1 register, disable EEPROM write
cmcon = 7
box var byte
box = 1
if porta.1 = 1 then

EEADR    = %00000001		'Address register
EEDATA   = box			'Data register, replace 127 with data to store
EECON1   = %00000100		'Control 1 register, enable EEPROM write
EECON2   = 85			'Control 2 register
EECON2   = 170			'Control 2 register
EECON1.1 = 1			'Control 1 register, begin write
EECON1   = %00000000		'Control 1 register, disable EEPROM write
else
EECON1   = %00000000		'Control 1 register, disable EEPROM write
pause 100
endif

high portb.0
box = 0



EEADR  = %00000001		'Read from location 1
EECON1 = %00000001		'Initiate read
PAUSE 1				'Pause may not be required, experiment
box = EEDATA		'Place value from EEPROM into variable


if box = 1 then
 high portb.4
endif
END

Thanks for any help you can give...

Adam
 
Adam,

You cannot write to EEPROM the way you are trying to. The write sequence is very time critical and has to be done in assembler. Either persevere with the built in commands or, if your basic compiler supports inline asm then replace your write code with the following sequence.

Code:
                movlw   1
                bsf     STATUS,RP0
                movwf   EEADR;		Set Address
                bcf     STATUS,RP0
                bcf     INTCON,GIE;		no interupts please
                movfw   Value
                bsf     STATUS,RP0
                movwf   EEDATA
                bsf     EECON1,WREN
                movlw   55h
                movwf   EECON2
                movlw   0AAh
                movwf   EECON2
                bsf     EECON1,WR
                bcf     STATUS,RP0
waitEEDone      btfss   PIR1,EEIF
                goto    waitEEdone
                bcf     PIR1,EEIF
                bsf     STATUS,RP0
                bcf     EECON1,WREN
                bcf     STATUS,RP0

The above will write to location 1 with the value "Value"

If your Friend has a working knowledge of asm then he/she should be able to adapt the above.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top