- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Labels:
-
PSoC 5 Device Programming
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is my solution on my CY8CKIT-059 Prototyping kit..
The Counter_1 component can cause an interrupt when the counter value is captured.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is my solution on my CY8CKIT-059 Prototyping kit..
The Counter_1 component can cause an interrupt when the counter value is captured.
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.