Mike Mansheim wrote: > > The simplest control system for something like this is: > > if (speed < desired speed) increase pwm output > else if (speed > desired speed) decrease pwm output > > This will oscillate around the desired speed, which often is perfectly > acceptable. How much it oscillates depends, among many other things, on > how much you change the pwm output each time. In your example, you make > the change in pwm output "proportional" to the difference between the > actual speed and the desired speed, which can be a useful enhancement - > although it will still always oscillate around the desired speed. > But it is not a "classical" proportional control, where the pwm output > each time this calculation is done is a function *only* of the difference > between the speed and the desired speed, and has no "memory" - i.e. it is > completely unrelated to the previous pwm output. The integral term is > what adds this memory. > A couple of practical notes if you use this approach: > > - it can be useful to add a hysteresis term to create a window in which > no change is made to the pwm. e.g.: > > if (speed < (desired speed - hysteresis)) increase pwm output > else if (speed > (desired speed + hysteresis)) decrease pwm output > > - I realize you were probably picking numbers out of the air for your > example, but just in case, don't feed 1100 to a 10 bit pwm register. > It will max out at 1023, if you've set the pwm frequency correctly > relative to the clock; less otherwise. > I thought it might oscillate, and if it's very narrow it'll probably be acceptable. Sorry for the figures - they were just an example - never thought to make them more accurate to the PWM module. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body