PSoC 5LP motor speed control

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
CaDu_3933941
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

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:

pastedImage_0.png

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.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

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

View solution in original post

1 Reply
lock attach
Attachments are accessible only for community members.
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

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