3 Replies Latest reply on Oct 23, 2016 11:24 AM by user_1377889

    Need help understanding timer/counter function

    jacobaman30_1951111

      I recently purchased a PSOC motor control unit (CY8CKIT-037) with a PSoC 4 (CY8CKIT-042). The system comes with code to get everything up and running. I have been going through the sensored BLDC motor control code and I am a bit confused on what the timer/counter does to get the speed measurement from the hall sensors. I see that there is a count, capture, and clock input. I am not sure how the signal from the hall sensor is detected and what interval it is detected on. In addition I am confused about the difference between "on terminal count" versus "on compare/capture count". If someone can run through with me the basic functions such as how the sampling and interrupt function in this code I would be very appreciative. I have attached photos of the Timer/counter block

         

       

         

      CY_ISR(speed_measure_isr)
      {
          uint16 cntCaptur = 0;
          
          cntCaptur = Counter_Spd_ReadCapture();
          
          speedCur = preCntCaptur - cntCaptur;
          /* If speed is too low, Regard motor is stopped*/
           if(speedCur > 5000)        /* < 300Rpm*/
              speedCur = 5000; 
          
          /* filter for speed measured */
          speedCur = (preSpeedCur >> 2) + (preSpeedCur >> 1) + (speedCur >> 2);    
          
          preCntCaptur = cntCaptur;
          preSpeedCur = speedCur; 
          
          Counter_Spd_ClearInterrupt(Counter_Spd_INTR_MASK_CC_MATCH);
      }

        • 1. Re: Need help understanding timer/counter function
          user_1377889

          Welcome in the forum, Jacob.

             

          You have got the advantage (opposed to me) of no language barrier. So my question is: Did you find the counter's datasheet (click right) because all the functioning is explained in deep.

             

          The counter is free running and decreases (it is a down counter) with every "count" pulse, aligned to the clock signal. The hall sensor, after passing the LUT generates a signal for every revolution. This signal is used to capture the current counter value. The difference to the previous value gives the time needed for a revolution. All that is handled within the interrupt handler.

             

          "on terminal count" is the point where the counter is zero and another pulse comes

             

          "on capture/compare" is

             

          a) The signal "capture" goes high which will save the current counter value in an internal register

             

          or

             

          b) signals that the counter value compares with a pre-set comparison value.

             

           

             

          Bob

          • 2. Re: Need help understanding timer/counter function
            jacobaman30_1951111

            Hello Bob,

               

            Thanks for the reply. I am now a little bit confused on the timing aspect of the counter timer. For the speed measurement the hall sensor will create a couple counts during one period of the timer. The period of the timer is set at 65535 and counts down to zero based on the 200kHz timer input. So each timer interval is 0.65 seconds. What happens in the code when the period goes to 0. The timer might clock in 500 and the next value 65000. This previous timer value is going to give a negative speed. What am I missing.

            • 3. Re: Need help understanding timer/counter function
              user_1377889

              Use the windows calculator, set to "Programming" and width to "Dword".

                 

              Enter 500 - 65000 =

                 

              Convert the result to a word by selecting now "Word" (The calculator cannot do that better) and you get 1036. This is what C will calculate for you.

                 

               

                 

              Bob