Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PWM library simpler way for on/off (enable/disable) than the example with SDK?

Is there a way to set duty cycle before app_pwm_enable(&PWM1) call ?

Or some other simple way to switch on and off a passive buzzer signal without every time at off/on cycle to go with complex sequence for setting duty value as per pwm_library example?

Let say some app like Morse Code where the frequency will be resonance of the buzzer and duty cycle will be constant 50 (or less).

Thanks

Parents
  • Hi 

    You mean you only want to turn on/off a simple square wave where the frequency and duty cycle will always be the same?

    If this is the case it might be easier just to use a timer to generate events, and connect them to  a GPIO through the GPIOTE and PPI peripherals. 

    Then you can set the frequency simply by changing the compare value in the timer. 

    Best regards
    Torbjørn

  • Ok, I tried the gpiote example and browse documentation. But still cant find what is(are) the way once I start the square wave, to stop it , then to restart it (with minimum operations)?

    While in stopped/idle mode – is there any of those components involved:  timer, gpiote, ppi  that would consumes excessive power (in a scale for a battery operated devices) that I have to be worry about?

    Thanks

  • Hi 

    If you are using the nrf_drv_gpiote driver already I would recommend using this driver instead of accessing registers directly, like in my example. After you initialize an out channel using nrf_drv_gpiote_out_init you should be able to read out the channel index, which you can then reference in the code. 

    You should be able to check in your other drivers if they use the TIMER1 module. Maybe you can change my code to use TIMER2 instead?

    Best regards
    Torbjørn

  • Hi Torbjørn,

    Still struggle to find easy way to get gpiote channel index after  nrf_drv_gpiote_out_init (). The best I could do is from nrfx_gpiote_out_task_get(pinNo) to get the task enum and after compare swithc/case with all nrf_gpiote_tasks_t  enums to get the channel index (0-7). Any better idea?

    Is there a way to check what timers are in use while at breakpoint in debugging? This to dig in the code for the timers seems have far more chances to miss some timer definition somewhere deep buried in the code?

    Thanks

  • Hi 

    You should be able to initialize an out channel, and then just use the nrf_drv_gpiote_out_task_addr_get function to get the task address directly. Then there is no need to know the channel index. 

    Just setup the PPI task endpoint with the task address provided. 

    Regarding which timers are enabled it should be possible to check this in the sdk_config.h file, assuming the other libraries use the nrfx_timer library. 
    It will have various defines on the form TIMERx_ENABLED or NRFX_TIMERx_ENABLED, showing which timers are enabled already. 

    Please note that if you use a SoftDevice it will use TIMER0, even if this is not reflected in sdk_config.h. 

    Best regards
    Torbjørn

  • Hi, but you have in your code, that you put as example before, couple lines that using gpiote channel index? 

     NRF_GPIOTE->TASKS_CLR[SOUND_GPIOTE_CH] = 1;

    NRF_PPI->CH[SOUND_PPI_CH_A].TEP = (uint32_t)&NRF_GPIOTE->TASKS_SET[SOUND_GPIOTE_CH];

    NRF_PPI->CH[SOUND_PPI_CH_B].TEP = (uint32_t)&NRF_GPIOTE->TASKS_CLR[SOUND_GPIOTE_CH];

    The only task address I could get right away is the out task I created in order to use nrf_drv_gpiote_out_init and it has same config as what you made with registers in your example?

    I by the way still didn't  clear all the mess I made with adding the code for the passive buzzer, but move one step better, by getting at least the sound working and I'm using 

    gpioteChIndex = (nrfx_gpiote_out_task_get(SS_SDK_CFG_BZR_PIN) % 48) / 4;

    But if I could rid of need of gpiote channel index would be better.

    Regards

  • Hi

    There are two functions called nrfx_gpiote_set_task_addr_get(nrfx_gpiote_pin_t pin) and nrfx_gpiote_clr_task_addr_get(nrfx_gpiote_pin_t pin)

    I believe these functions should provide the task addresses you need. 

    Best regards
    Torbjørn

Reply Children
No Data
Related