I have a program that is making use of two separate tables being read by the ReadTable command. I have one ReadTable command on a interrupt handler and the second on the main loop. I'm experiencing sporadic data corruption and I believe the problem lies in the ReadTable command using variables that are not saved as part of the interrupt context. So when I get an interrupt in the middle of a ReadTable access, the access gets corrupted. I believe the data pointer is the culprit here. I'm not sure how to work around this without going into the assembly code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found a quick fix for this problem. Make sure you save the DataPointer before using ReadTable on an interrupt handler and restore it before exiting it:
Sub TimerHandler
saveptr = DataPointer
ReadTable (Table1, index, output)
…
DataPointer = saveptr
end Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've now added a bit of code to GCBASIC that should save the DataPointer variable properly in the interrupt. Thanks for posting, and sorry for the delay in replying!
I have a program that is making use of two separate tables being read by the ReadTable command. I have one ReadTable command on a interrupt handler and the second on the main loop. I'm experiencing sporadic data corruption and I believe the problem lies in the ReadTable command using variables that are not saved as part of the interrupt context. So when I get an interrupt in the middle of a ReadTable access, the access gets corrupted. I believe the data pointer is the culprit here. I'm not sure how to work around this without going into the assembly code.
The chip is a 16F690 if that makes a difference.
I found a quick fix for this problem. Make sure you save the DataPointer before using ReadTable on an interrupt handler and restore it before exiting it:
Sub TimerHandler
saveptr = DataPointer
ReadTable (Table1, index, output)
…
DataPointer = saveptr
end Sub
I've now added a bit of code to GCBASIC that should save the DataPointer variable properly in the interrupt. Thanks for posting, and sorry for the delay in replying!
The fix is at the usual address, http://gcbasic.sourceforge.net/newfiles/update-nochipdata.zip.