Ken, there are 2 issues that have not been addressed since the beginning of this project.
1. The less serious of the 2 is your use of the hardware PWM module. R/C devices, such as servos and ESC's, expect a control pulse (typically 1-2mS) at about 50Hz. You can probably go lower to 30Hz or higher to about 100Hz and things should still work fine. However, a PIC16 with a 20MHz clock (which I believe you are using) will not go below 1220Hz (PR2=0xff). Even with an 8MHz clock the lowest is 488Hz (244Hz with a 4MHz click) and is still probably to high compared to the desired 50Hz.
2. To get a closed loop control system to work correctly, you need more than a bunch of if-then-else statements. Ideally you want to use a PID controller. A proportional-integral-derivative controller (PID controller) is a generic loop feedback mechanism. It measures a process variable (e.g. temperature), and checks it against a desired set point (e.g. 100 degrees Celsius); it then attempts to adjust the process variable by changing a controller output (e.g. PWM signal to an electric heater) which will bring the process variable closer to the desired set point. Even a simple P (proportional only) controller would be much better than what you currently have.
Bookmarks