Hi,
Richard covered the gain calculations, not much to add to that.
Your problem is most likely the line
Code:
Drive_T=Drive_T+Drive_P '(I used DriveT=Drive_T+... to keep some level of drive)
Drive_T will accumulate to very large numbers and you don't show what type variable it is. If it's BYTE then you'll be in even more trouble because it won't work properly adding Drive_P when that value is negative. For that to work both variables need to be the same size - which they might be, I don't know since you don't show the code. If you insist on keeping that line you should probably consider clamping Drive_T too so that it won't go higher than 255 in this case.
With a gain of 9 ($0900) the output will be saturated whenver the error is 29 or more (because 29*9=261). To get more resolution I'd probably skip using HPWM and set the CCP module up manually, that way you can 10bit PWM resolution instead of 8.
/Henrik.
Bookmarks