I'm making a system that gets the signal of a hall sensor attached to a fan, the faster it spins the faster is the signal, i want to use the interrupts on the RA to count the rising edge and calculate the RPM with the amount of rising edges in a specific time, what timer should i use? i'm trying to use the R_GPT but when i StatusGet it giver me a tipe of data i cant use with an if statement, how can i do it and what is the best timer for this?
In your example, timer_status_t is a structure, so you are mismatching types. The timer count would be in status.counter.
A better way to do what you are attempting is to use the GPT with the input capture function. It will latch the count on the rising or falling edge of the input (configurable) and that latched count would be available in the timer callback function when the input is triggered. Calculate the difference in count between the and you can determine the frequency of the input signal.
if i try to use the interrupt pin as capture A it gives me an error
What is the error? If you mouse over the red block, it should tell you what is wrong. You would need to configure "Capture A Source" or "Capture B Source" to use input capture.
added event link and it worked, i only need to set the input capture A or some other config?
Yes, and in the callback, look for the TIMER_EVENT_CAPTURE_A or TIMER_EVENT_CAPTURE_B event. This if a fragment from code that is using input capture to do exactly what you are trying to do. The pulse accumulator is for lower frequency signals that just count how many events have occurred:
void ScCallback (timer_callback_args_t *pArgs){ word wCapturedCount; if ((pArgs->event == TIMER_EVENT_CAPTURE_A) || (pArgs->event == TIMER_EVENT_CAPTURE_B)) { ulPulseAccumulator++; wCapturedCount = pArgs->capture;