Page 276 - Programming Microcontrollers in C
P. 276

Timer Operations    261


                                      30000000
                              RPM =
                                       Counts
                          Neither calculation is convenient in a microcontroller. The numerator
                          is larger than an int but smaller than a long. Both Counts and
                          RPM have a range that can be contained in an int. One would expect
                          that the conversion to time should be done on the input speed. That
                          way, the division would be done only once for each speed setting. If
                          the measured times were converted to RPM each time a time were
                          measured, the computer program would be loaded with complicated
                          divisions in its real time application portion. But let’s examine the
                          nature of the error with the different types of measures. Suppose the
                          input RPM were converted to time and the measurements were based
                          on time. Then the error signal, which is the difference between the
                          measured value and the desired value, would have a wrong sense.
                          That is if the motor is moving too slowly, then the error signal would
                          be negative, which would cause the motor to go even slower. If the
                          calculation were done based on RPM and the motor were going too
                          slow, the error signal would be positive. In this case, the control would
                          drive the motor faster which is the needed correction.
                              The difficulty with the time-based system could be solved by
                          using the negative value of the error signal for the feedback control.
                          A simple analysis will show the potential problem with this approach.
                          Suppose that we work with two counts, C  and C  . Let us use the
                                                                   d       m
                          value K for the constant in the above equation. Therefore,

                                               1         1  
                                             
                              e= C –C= K             –        
                                   d    m
                                               RPM d  RPM  m 
                              The error signal is seen to be

                                     RPM  – RPM 
                              e=K        m       d  
                                      RPM * RPM  m  
                                          d
                              When the two speeds are nearly the same, this expression is very
                          nearly proporstional to the difference between the two speeds. However,
                          when one of the speeds deviates significantly from the other, it will
                          cause the resultant error signal to be less sensitive to difference than
                          would be expected. Also, there is the problem that occurs if the motor
                          is stopped and the error signal in that case is undefined.
   271   272   273   274   275   276   277   278   279   280   281