Re: PWM period vs. frequency
Posted: Wed Apr 17, 2013 12:01 am
Shame on me, the frequency defined in PWM configuration is ought to be underneath timer frequency, not PWM frequency. I misread the configuration.
This makes things clear though it forces the user to read the spec of the MCU anyway to define the correct period.
For instance for PIC32 it makes following equations:
This makes things clear though it forces the user to read the spec of the MCU anyway to define the correct period.
For instance for PIC32 it makes following equations:
Code: Select all
#define PWM_FREQ_HZ 14000ULL
#define PB_FREQ_HZ MIPS_CPU_FREQ
// PWM Frequency = 1/[({PWM Period} + 1) * Tpb * Tp]
// Tp := timer prescaler
// Tpb := 1/Fpb
// Fpb := peripheral bus clock frequency
// PWM Period = [Fpb/({PWM Frequency} * Tp)] - 1
// PWM resolution = log2(PWM Period)
// ---
// max(map(lambda Tp: (log2((PB_FREQ_HZ/(PWM_FREQ_HZ*Tp))-1), Tp), (1, 2, 4, 8, 16, 32, 64, 256))) -> (12.48, 1)
// to achieve max resolution for given PWM frequency 1:1 timer prescaler fits best