Memory problem PIC16F
I'm trying to understand a problem with the memory of my PIC16F877A (yes I know it's old).
I have a robot with 4 wheels controlled via Bluetooth (module HC05).
When I excite the motors in opposite directions, abrupt change of direction, I have the program that starts to do anything.
I looked at what happens in debug mode and I see that the PIC is in an area of the memory where there is no more program.
Only the interrupt timer continues to run.
I added a Watchdog and I can see that the PIC reset.
But sometimes it doesn't go out of the program. I have at the beginning of my program a calculation that initializes coefficients from constants that I define at compile time (for example the speed of the motors). This function is executed only once but when I excite the motors, my coefficients change value!
So to resule, when a sudden change of direction occurs, either the program goes out of its memory area, or some variables have changed and modify the behavior of my robot.
I made a test by modifying the maximum speed of my robot and when it is not too fast, no problem appears. So I'm looking at a problem with the motors' current calls (I activated the brown-out).
Do you know by experience how much it can corrupt a program? Can a small voltage drop cause memory problems or do I have to focus on the program?
I'm using MPLAB 5.15 and XC8 1.34.
Thank you for your help!