Pulse Width Counter using peripheral only

We have a hall sensor with pwm output encoding the information in the duty cycle of pwm. Now we would like to read the duty cycle without the use of an interrupt, but solely using the nrf52840 timer peripheral. 

It seems impossible to find an example on how to have the timer start counting on a rising edge, stop counting at the falling edge and placing the counter value in the CC register. That is actually all we need. We do not need an interrupt once the CC register has been updated nor do we need each single CC register value. We would like the OS to be in control of when a value is required, but it should be up to date, once we need the pulse with value.

Can you provide an example for this?

Thanks

Martin

Parents
  • Hi Martin

    Which SDK are you using? 

    It should be relatively straight forward to implement something like this. Essentially you need to set up two GPIOTE channels on the same pin, one configured to generate an event on a low to high transition, and one for the high to low transition. 

    Then you need to connect the first GPIOTE channel to the timer START task over PPI, and the second GPIOTE channel needs to be connected to the timer STOP, CLEAR and CAPTURE tasks (for this you will need an additional two PPI channels). 

    Then you can just read the corresponding CC register any time you want to know the value of the last pulse. 

    Best regards
    Torbjørn

Reply
  • Hi Martin

    Which SDK are you using? 

    It should be relatively straight forward to implement something like this. Essentially you need to set up two GPIOTE channels on the same pin, one configured to generate an event on a low to high transition, and one for the high to low transition. 

    Then you need to connect the first GPIOTE channel to the timer START task over PPI, and the second GPIOTE channel needs to be connected to the timer STOP, CLEAR and CAPTURE tasks (for this you will need an additional two PPI channels). 

    Then you can just read the corresponding CC register any time you want to know the value of the last pulse. 

    Best regards
    Torbjørn

Children
No Data
Related