PWM signal with variable frequencies

48 views
Skip to first unread message

Oliver Kan

unread,
Feb 3, 2020, 4:56:46 AM2/3/20
to uavdevboard
Hi Guys,

I want to connect a passive buzzer to output 6 that needs variable PWM frequency, how I can generate a PWM signal and how to change the frequency of the PWM signal to control this buzzer ?

Thank you,
Oliver

Guy-François MESNIL

unread,
Feb 4, 2020, 2:12:34 PM2/4/20
to uavdevboard
Hi Oliver,
MatrioxPilot uses PWM output to control servos positions.
These outputs are based  on timer3 frequency which is, by default, 40 Hz or 200 Hz for multicopter. 
This frequency is fixed. That is the duration of the high pulse which is controlled, between 1 to 2 ms for positioning the servo into its entire course of 180°.
It is easy to change this high pulse duration but not to change the frequency 40 or 200 Hz dynamically.
As far as I know, classic buzzers generate a fixed tone as soon as they are powered on.
What do you mean exactely by PWM frequency?
Regards,
gfm

john andrews

unread,
Feb 5, 2020, 2:32:06 AM2/5/20
to uavdevboard
Hi Oliver 
Hi gfm 
each PWM signal has three different specifications: 
-frequency
-duty cycle  
-resolution 
so if you want to generate a pwm signal from UDB you must take into account these three  specifications 
the resolution is dependent to the frequency of pwm signal.
the same specifications you must take into account to control a passive buzzer with different pwm frequency and with different duty cycle (like a PIXHAWK buzzer)   
best wishes,
John, 

Oliver Kan

unread,
Feb 11, 2020, 5:40:00 AM2/11/20
to uavdevboard
Hi gfm and john,

passive buzzer needs different PWM frequency that you mention,
or a different servo like (BLS-2905)https://www.blue-bird-model.com/news_detail/15.htm?cfrom=1 that operates on 333 Hz,
so where I can change the PWM frequency and duty cycle to values are suitable with my experiment and with my devices.

Thank you,
Oliver

Guy-François MESNIL

unread,
Feb 12, 2020, 8:31:18 AM2/12/20
to uavdevboard
Hi Oliver,
In the current MatrixPilot versions, there is a special trigger action capacity connectable to output pin 6.
This function is designed to :
"
// Trigger Action
// Use the trigger to do things like drop an item at a certain waypoint, or take a photo every
// N seconds during certain waypoint legs.
"
Consequently, the PWM frequency and duty cycles are defined before the compilation and cannot be changed dynamically during the flight.
You will find more explanations in the config | options.h file.

If you want to command a passive buzzer at different tones and pitches you need to implement a special procedure to do that.
You can use, for example, two dedicated inputs to control the tone and the pitch (that you can include in libUDB | radioIn.c) 
and a dedicated function to output the signal to the buzzer on output6 (that you can include in libUDB | servoOut.c or MatrixPilot | behavior.c).
See Microchip AN655 to have a typical example and asm code for sine generator using digital outputs.

I believe that is the only method to achieve what you are looking for.

Regards,
gfm

Le lundi 3 février 2020 10:56:46 UTC+1, Oliver Kan a écrit :

Oliver Kan

unread,
Feb 13, 2020, 2:16:07 AM2/13/20
to uavdevboard
Thank you gfm,
I will try it

Oliver
Reply all
Reply to author
Forward
0 new messages