This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

low power pulsewidth measurement: PPI & lfclk & S210 - some guidance needed

Dear all,

I need to measure a pulse width on a GPIO pin which is in between 100mseconds and 7.2 seconds long without the use of "regular" timers due to low power requirements. I am pretty sure this can be done with PPI and the 32.768 kHz lfclock ( which runs anyway due to S210 use ). But I am simply lost in the examples and driver docs. Especially as I base my work on the bikepower ANT+ example which uses the board support package and app_button. Due to this I cannot copy-paste any code example as this always conflicts with something in the BSP or app_button.

Is there a hint which drivers / app_whatever to "implement" into existing examples that use BSP and app_button to connect a GPIO via PPI to a lsclock counter/timer ?

I "simply" need to start a lsclock counter by a GPIO pin interrupt (Low-High) and stop it by a high-low interrupt. Sadly I seem to be unable to do implement this simple task into the existing example code. As my max pulsewidth is > 10 seconds, a 16 bit counter is not sufficient @ 32.768 kHz clock. I am not sure if I can handle timer overflows due to the softdevice interrupting my program at any time.

Anyhow, the RealTimeCounter is 24 bits which is enough for my purpose. So, with RTC prescaler = 0 ( as used in app_button like it seems..) I could store the current TICK count at the low-high interrupt and then compare to the TICK count at the high-low interrupt and that's it. The counter roll-over case could be handled outside the ISR.

Just: How to do it ?

Any help like "remove this driver, add that one, re-use this timer.. " is very appreciated.

Thanks a lot, Wolfgang

Parents
  • Ole, the SoftDevice IS enabled and works. I do get ANT+ messages "on air". Just, the GPIO ISR never fires and the reason is that sd_nvic_EnableIRQ does return an error ( I am still not able to get the return values as the debugger insists that the variable assigned to it ( usually err_code ) is "not in scope". So we are back to the original where nrf_drv_gpiote_in_init also returned an error. If you could get me some advice on how to get the returned error code, we likely could track it down better. I use Keil V5.17 and your SDK version 10 (not the Keil packs) and the ant_bpwr_tx_wheel_torque_button_s210 example code.

    Aaaah, so you say I need to enable the softdevice FIRST and THEN call sd_nvic_EnableIRQ() , correct ? OK, up to now I set up the softdevice last in my main().

    Nope, makes no difference. APP_ERROR_CHECK does never return if it checks the return value of sd_nvic_EnableIRQ() , no matter if I call sd_nvic_EnableIRQ() before or after softdevice setup...

    according to the sofdevice documentation there is only two possible errors for sd_nvic_EnableIRQ: Interrupt not available or priority not allowed... I have the feeling "something else" is using this interrupt already.

    This may help tracking it down: debugger info about GPIOTE

    GPIO20 ( which is what I used here ) looks good: image description

  • RK, thanks for the comment. 1) I do not know which of the two errors is returned. 2) I do not know if GPIOTE is an available interrupt. It is by the softdevice documentation, but maybe app_twi uses it ? 3) No, I did not set the interrupt priority, at least not that I know. I'll try to find out how to set the priority and report back here.

Reply
  • RK, thanks for the comment. 1) I do not know which of the two errors is returned. 2) I do not know if GPIOTE is an available interrupt. It is by the softdevice documentation, but maybe app_twi uses it ? 3) No, I did not set the interrupt priority, at least not that I know. I'll try to find out how to set the priority and report back here.

Children
No Data
Related