Hello,
Approaches for Hyperbolic and Linear Frequency Modulation in an MCU with a PWM frequency of 50kHz are in the codes below.
PWM interrupt is entered every 20us (50kHz) and the next PWM pulse widths are calculated by executing the codes below. Frequency modulations do not work within the same PWM interrupt. They are separate codes.
The time t can take various values from 250 milliseconds to 15 seconds and is determined at the beginning of the program.
Related codes include floating-point arithmetic. These calculations should not take more than a few microseconds, possibly more than 5 microseconds.
After the modulation values are calculated, these values should be converted to PWM Duty and go to the driver from the relevant pin.
Can you give information about how long this process will take for your Cortex-M4F or other floating-point supported products?
Can you share your suggestions for optimizing the code?
---------------------Hyperbolic Freq. Modulation-----------------------
#define PI = 3.14159265
int f_start, f_stop;
float pulseWidth, k, t;
k = ( f_start - f_stop ) / f_start / f_stop / pulseWidth;
*****************PWM Interrupt********************
cos[2 * PI * ( log[k * t + (1 / f_start)] ) / k];
*****************PWM Interrupt********************
---------------------Hyperbolic Freq. Modulation-----------------------
-------------------------Linear Freq. Modulation-----------------------------
#define PI = 3.14159265
int BW, f_start, f_stop;
float pulseWidth, t;
*******************PWM Interrupt*********************
cos[2 * PI * (f_start * t + 0.5 * ( BW / pulseWidth) * t * t)];
*******************PWM Interrupt*********************
-------------------------Linear Freq. Modulation-----------------------------