Page 277 - Programming Microcontrollers in C
P. 277

262    Chapter 5  Programming Large 8-Bit Systems

                              If the counts are converted to RPM prior to calculation of the error
                          signal, the reduction of sensitivity for large errors would not be a
                          problem. The problem that occurs when the motor is stopped still exists.
                          In this case, no input capture would occur when the motor is not rotating,
                          and the count value would be undefined. There seems to be no clear-cut
                          reason to choose the time or the velocity measurement. Each has
                          advantages and each has drawbacks. The drawbacks are about the same
                          for each, so we will choose the case that has the simplest program.
                          Therefore, the time-based or count-based system will be used.
                              Now comes the interesting problem of the calculation of 3000000/
                          RPM. Each time the desired speed of the motor is input to the system,
                          this calculation must be completed. The straightforward calculation
                          of this value will yield code as follows:

                   #include “hc11e9.h”


                   WORD count(WORD RPM)
                   {
                       unsigned long num = 30000000;


                       return num/RPM;
                   }

                              The listing file of the compiled version of this function is


                   1 ; Compilateur C pour MC68HC11 (COSMIC-France)
                   2          .include”macro.h11"
                   3  .list +
                   4  .psect _text
                   5 ; 1 #include “hc11e9.h”
                   6  .psect _data
                   7 _Register_Set:
                   8 0000 1000           .word 4096
                   9;2
                   10 ;  3 WORD count(WORD RPM)
                   11 ;  4 {
                   12      .psect _text
                   13  _count:
                   14 0000 BD0000               jsr     c_kents
   272   273   274   275   276   277   278   279   280   281   282