Thanks for your thoughts Alex. Trouble is that cop resets during the main loop and not when writing to flash.
To test if the mcu is behaving as if the cop period is short, I shifted the cop service code to the "wait for output compare" loop at the end of the main loop. This gives maximum period between cop service of abt 0.5 ms. PROBLEM SOLVED. No more cop reset. This suggests that the cop reset period is changed to short. But cop is set in config register for long period????? (coprs=0)
Is it possible that these on chip ROM routines (pgrnge and or erarnge) somehow cause the cop reset period to be changed? But then how could it be put back to the long period? The config registers are write once only!
Rob
Hello Rob,
The pgrnge and erarnge routines do not affect the configuration (have a look at AN1831, Rev 3). I would suggest to reset the COP timer within your initialisation, prior to entering the EEPROM or flash write routine.
What else do you do before entering the main loop? Are there any delays? Do you currently write to both the EEPROM and flash sequentially? If so, do you wait until the EEPROM write process is completed before leaving the routine (this may take a few milliseconds).
A technique I have used with the MMEVS is to use selective assembly (compile) by defining or not defining an EVALMODE label. During evaluation mode the ROM based routines are bypassed, but I can still test for other problems.
Regards,
Mac
Hi Mac,
It's pointless going on much about when or where cop is serviced since the program runs ok if using eeprom. But suffice to say cop is serviced at the very top of code and several times during initialisation. There is a timer based delay sub used during initialisation. It has a base loop of 1 ms and cop is serviced at top of each loop.
Fact is that if flash routines are called, cop behaves as if the short reset period is set and long if eeprom used. I've tested the coprs bit during execution and it is clear. Also tested srsr register and it is definitely cop reset.
The cop resets occur well away from reading or writing flash based data. There is no problem getting through the initialisation section.
Because of the limitations of the mmevs qblty em, two register files are used. The reading and writing subs test which .inc file is in use to determine if flash or eeprom is to be used. Only one method is used not both. Works a treat. All I do is rem out the inc file not needed before assembly.
The problem is solved by servicing cop in under the short reset period in the main loop (even though mcu is configured for long cop period).
While I have found a way around the problem, it would be nice to know what's going on.
Rob