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.

Writing to a PIC16F88's data EEPROM

Status
Not open for further replies.

pdfruth

New Member
Using a PIC16F88.
I'm using an "INT" interrupt handler to capture the frequency of a signal input on RB0. Then I calculate a percentage (say -7%) of that frequency. And I use the CCP1 module (running in compare mode), and a CCP1 interrupt handler, to output a corrected frequency on the RA6 pin. The routine is working beautifully.

So, now I want to get fancy. I want to monitor the input frequency, capture the highest frequency encountered over time (ie. a high water mark), and save it. That too is working beautifully.

Now the problem...
When I capture a new "high water mark", I want to record it to the PIC's embedded data EEPROM, so that it can be retrieved in the future. This does work. However, upon initiating the EEPROM write operation, I'm finding that my other interrupt service routines are briefly disrupted/suspended. Upon reviewing the data sheet for the 16F88 (specifically, section 3.4), I discover "... We strongly recommend that interrupts be disabled... " during the write operation. Darnit. That's a bummer.

Has anyone discovered a way to write to the embedded data EEPROM, without having to disable interrupts?
 
Last edited:
Where is the problem with disabling interrupts? They only have to be disabled for half a dozen cycles (context save in ISR takes longer). If your requirements are so time critical then use a faster chip. Alternatively, post your code and your requirements and I'm sure someone here will come up with a solution.

Mike.
 
Can you suspend measureing the frequency while the eeprom is writing?

Maybe you could wait until the frequency is low, so the interupts are far apart in time, before writing the value to eeprom.
 
Maybe you could wait until the frequency is low, so the interupts are far apart in time, before writing the value to eeprom.

That is the conclusion I've come to as well.
I'm just going to store the "high water mark" in a ram variable. Then, when the input frequency drops, I'll record it in EEPROM.
 
At 2kHz a pulse is arriving every 500 cycles (assuming 4MHz clock) and the interrupts have to be disabled for 6 cycles. Just set a flag in your interrupt so your main code knows when an interrupt has just happened and write the EEPROM immediately after.

Mike.
 
Just set a flag in your interrupt so your main code knows when an interrupt has just happened and write the EEPROM immediately after.

Good idea... I will give this a try.
Due to competing priorities, it may take a little while, but I will report back.
 
Last edited:
Mike (Pommine),
I got a chance to implement your suggestion. It works perfectly.

I don't know why I didn't think of that. :rolleyes:
One of those cases of being so close to a problem (staring at it so long), that I overlook the obvious. Sometimes it's good to step away for a bit.

So, thank you sir.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top