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.

Cannot simulate EEPROM write

Status
Not open for further replies.

sam77

New Member
Hi everyone
I’m having problems writing to EEPROM on the PIC16F684. I searched the board for similar problems (here and on MICROCHIP forum ) and it helped me solve some of the errors. However, I want to write a literal to address 1 and see the result in the EEPROM watch window in MPLAB SIM . My code below does not give any errors during BUILD. But when I run the simulation, the program is stuck at BTFSS. And I don’t see any changes in the EEPROM window . Thanks for your help

Code:
	#include	<P16F684.inc>
	__CONFIG    _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _FCMEN_OFF & _IESO_OFF
w_temp 			equ		0x7E
status_temp 	equ		0x7F
	org		0x000
	goto	main
	org		0x004
	movwf	w_temp
	movf	STATUS,w
	movwf	status_temp
	movf	status_temp,w
	movwf	STATUS
	swapf	w_temp,f
	swapf	w_temp,w
	retfie

main
loop1

	BCF		INTCON,GIE		;DISABLE INTERUPTS
	BSF		STATUS, RP0		;Bank 1
	MOVLW	B'00000001'		;USE ADRESS 1 IN EEPROM MEMORY
  	MOVWF	EEADR
  	MOVLW	B'00001111'		; SEND THIS VALUE AS THE DATA TO ABOVE ADRESS
  	MOVWF	EEDATA
  	BSF		EECON1, WREN	;Enable write
	MOVLW	55h 			;
  	MOVWF	EECON2			;Write 55h
  	MOVLW	0AAh    		;
  	MOVWF	EECON2    		
  	BSF		EECON1,WR   		
writing						; delay until write is complete
	btfss	PIR1,EEIF
	goto	writing
	BSF		INTCON, GIE   ;Enable INTs. 
	goto loop1
	end
 
You've made two significant errors.

Firstly, you haven't cleared the EEIF bit before your routine.

Secondly, you didn't reset the bank bit before testing the EEIF flag. The EEIF flag is part of PIR1 which is in bank 0. Your code was testing the bit in bank 1, which is the EEIE bit of PIE1, which never changes.

As an alternative, you can test the WR bit. It's probably good practice to clear the bank bit after that.

The two examples here simulate OK. One tests the EEIF flag and one tests the WR bit.

When simulating, you have to be aware that there is a significant pause when writing to the EEPROM

Code:
	BCF		INTCON,GIE		;DISABLE INTERUPTS
	BSF		STATUS, RP0		;Bank 1
	MOVLW	B'00000001'		;USE ADRESS 1 IN EEPROM MEMORY
  	MOVWF	EEADR
  	MOVLW	B'00001111'		; SEND THIS VALUE AS THE DATA TO ABOVE ADRESS
  	MOVWF	EEDATA
  	BSF		EECON1, WREN	;Enable write
	MOVLW	55h 			;
  	MOVWF	EECON2			;Write 55h
  	MOVLW	0AAh    		;
  	MOVWF	EECON2    		
  	BSF		EECON1,WR   		
writing						; delay until write is complete
	btfsc	EECON1, WR
	goto	writing
	BSF		INTCON, GIE   ;Enable INTs. 
	BCF 	STATUS, RP0
	nop

	BCF		PIR1, EEIF
	BCF		INTCON,GIE		;DISABLE INTERUPTS
	BSF		STATUS, RP0		;Bank 1
	MOVLW	B'00000001'		;USE ADRESS 1 IN EEPROM MEMORY
  	MOVWF	EEADR
  	MOVLW	B'11001100'		; SEND THIS VALUE AS THE DATA TO ABOVE ADRESS
  	MOVWF	EEDATA
  	BSF		EECON1, WREN	;Enable write
	MOVLW	55h 			;
  	MOVWF	EECON2			;Write 55h
  	MOVLW	0AAh    		;
  	MOVWF	EECON2    		
  	BSF		EECON1,WR   
	BCF		STATUS, RP0		
writing2					; delay until write is complete
	btfss	PIR1, EEIF
	goto	writing2
	BSF		INTCON, GIE   ;Enable INTs. 
	BCF 	STATUS, RP0
	nop
 
Thanks it worked
Unfortunately, I have to rethink my design because of the write time. Thanks again
 
I guise you can advise me on the best course of action. I designed an EKG device and the analog section is complete. I want to digitize the signal and save it, to be operated on later (which I will decide later). The ADC on the chip seems to be working but I haven’t tested how long the conversion takes. So I want to minimize the time between ADC samples. Also the amount of EEPROM data would only be (256*8)/10= 208 samples which is not much ( 10bit ADC). I also want to use the 16F684 because I have lots of them, I’m just a beginner, and I’m using pickit1. I have been looking at “256K SPI Bus Low-Power Serial SRAM” (https://ww1.microchip.com/downloads/en/DeviceDoc/22100D.pdf). Do you think this can solve my problem? Or any advise.
Thanks again for all your help
 
It would be simpler to use a pic with more ram such as a 16F88 (368 bytes). You can then use the ram as a buffer before writing to the EEPROM. You don't state how often you need to sample the data but if it's less than 250Hz then you could possibly write it to flash memory. Flash is typically twice as fast as EEPROM.

Mike.
 
You want something with much more RAM. Use a pic24, as you can get 8 k of RAM.

The number of samples that you need to store is something you need to decide, which depends on how you are going to output your data.
 
Thanks you guys,
I attached the wave form obtained from the analog side. The frequency of the signal is between 0.7 Hz and 1.2 Hz depending on the age of the subject (rough average). Note that the waveform is up sided down. Pommie, the 16f88 cannot be programmed with pickit1. I want to sample 1.5 seconds long at a sampling rate where I would not lose much of the signal fidelity. Any advise on what sampling rate I should consider. I was thinking anything between 120 Hz and 300 Hz. As to Driver300 question, the output may be to RS-232 or if possible USB. Please note that I’m trying to use the things that I have e.g. Pickit1 , 16f684, Max chip for serial comm and I also found 3 of the serial SRAM that I bought a couple of weeks ago (and did not know it). I’m kind of a part junky.
Thanks guys
image002..jpg
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top