This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how can i use timer as counter??

Hi, i need to calculate the frequency of two PWM.

When it comes to frequency calculation, the counter function is the best solution, i think.

i'm using SDK 6.0.0 for my project.

i tried to calculate the frequency by timer. but the 'APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER)' can make 1ms timer interrupt as a minimum clock.

actually, the highest PWM frequency is up to 5kHz so, 1ms timer interrupt is so slow to capture the 5kHz PWM

  1. how can i get some example about counter??
  2. or how can i make more faster timer interrupt??

thanks!

Parents
  • Using nrf_drv_timer should work. The counter is just setting the timer mode to counter and trigger the COUNT task. You can set up the pwm pin toggle to actually trigger the count task of a timer through GPIOTE and PPI. Connect the PWM pin to a GPIOTE event. Through PPI, connect the GPIOTE event to the TIMER COUNTER task for any timer. When you are starting the measurement, you have set up another timer in timer mode, which you will start by setting the TIMER START task. When stopping, disable the PPI that counts the PWM and set the TIMER STOP task. Then you have a value for how long time you have done the measurement, and how many transitions the PWM has done during this time.

Reply
  • Using nrf_drv_timer should work. The counter is just setting the timer mode to counter and trigger the COUNT task. You can set up the pwm pin toggle to actually trigger the count task of a timer through GPIOTE and PPI. Connect the PWM pin to a GPIOTE event. Through PPI, connect the GPIOTE event to the TIMER COUNTER task for any timer. When you are starting the measurement, you have set up another timer in timer mode, which you will start by setting the TIMER START task. When stopping, disable the PPI that counts the PWM and set the TIMER STOP task. Then you have a value for how long time you have done the measurement, and how many transitions the PWM has done during this time.

Children
No Data
Related