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).
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…
It is true that the SHUTDOWN task is marked as deprecated, but for devices affected by Errata 78 it is necessary to use this task to achieve low current consumption in sleep mode.
In future devices where…
Regarding the delay for stopping the timer and clearing the output pin, both these delays are consistent, so if shutting down the timer was slower than clearing the pin you would see it all the time…
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.
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?
A running timer will increase the sleep current considerably, yes, so I would recommend stopping it whenever the square wave is not needed.
The best way to do this is to activate the SHUTDOWN task in the timer, which disables it completely.
Having a PPI channel or a GPIOTE OUT channel enabled should not affect the sleep current significantly, but I will have to double check this to be sure and get back to you.
Ok, but timers SHUTDOWN task is marked in documentation as “Deprecated”?
Your idea for using timer to generate the basic frequency (I need 2730 Hz) is very good, I only struggle to find documentation or example how best to switch on /off this square wave with GPIOTE as I will use it for audio markers 1 to 4 beeps: let say 1 beep immediately after a button is pressed, 2 for long press, 3 , 4. Also beeps(and pauses between) could be short or long etc.
I anyway will use 1MHz(or less) timer source, so will spend less power at those frequencies, but looking to find optimal solution to switch off/on the 2730 burst in between beeps of a single audio prompt, then move timer and all other involved components (GPIOTE, PPI or whatever will use) in idle position waiting to start new audio prompt with minimum reinitializations.
Thank you and best regards
In future devices where this issue is fixed you would have to replace the SHUTDOWN task with the STOP task.
If you want to stop and start the timer at a slower rate you can use the app_timer to schedule this.
I made a small example based on ble_app_uart to show how you can configure the TIMER, PPI and GPIOTE peripherals, and use the app_timer to start and stop the timer repeatedly: