1 Reply Latest reply on Aug 10, 2019 5:47 PM by NoriakiT_91

    PSoC 5LP motor speed control

    CaDu_3933941

      Hi all,

       

      I am currently working on trying to read the RPM of a motor using a PSoC 5LP. The sensor consists of a IR sensor and a disc encoder. The disk encoder has holes that generate a pulse every time it blocks the IR sensor making the sensor output signal a PWM So far I was able to read the speed of the frequency/RPM of the motor doing the following:

       

      Code:

      #include "project.h"

       

       

      char string[120];

      int count;

       

       

       

       

       

       

      CY_ISR(Counter_ISR){

        

          count = 5*Counter_1_ReadCounter();

        

      }

      void Init_Hardware(void){

          UART_1_Start();

          PWM_1_Start();

          PWM_2_Start();

          Counter_1_Start();

        

          ISR_Counter_Start();

          ISR_Counter_StartEx(Counter_ISR);

        

      }

       

       

      int main(void)

      {

          CyGlobalIntEnable; /* Enable global interrupts. */

       

       

          Init_Hardware();

        

        

          for(;;)

          {  

            

              sprintf(string,"%d Hz\n \r", count);

              UART_1_PutString(string);

          }

      }

       

      The way it works is that the PWM sets a window during which the counter will count an event.  The ISR component is used to read the count every time the interrupt event happens within the PWM block. The other PWM is just there to drive the motor.

       

      My problem is that the counter variable does not seem to update should the speed change.

       

      Any help will be appreciated.

       

      Thanks

       

      P.S I do not know how to properly attach a project to posts.

        • 1. Re: PSoC 5LP motor speed control
          NoriakiT_91

          This is my solution on my CY8CKIT-059 Prototyping kit..

          GS004421.png

          The Counter_1 component can cause an interrupt when the counter value is captured.

          GS004424.png

          Please do not forget to clear the interrupt flag by reading the status register.

           

          CY_ISR(int_Capture_isr) {
              int_Capture_flag = 1;
              count = Counter_1_ReadCapture();
              Counter_1_ReadStatusRegister();
          }
          

           

          The counter value when capture input is asserted is gotten by the _ReadCapture() API function.

          GS004425.png

          1 of 1 people found this helpful