Page 1 of 1

Doubts regarding PWMConfig

Posted: Wed Nov 16, 2016 6:16 pm
by ep.hobbyiest
I m using F401RE.
I want to generate 30Khz pwm freq with two channels based on later selection on which frequency is to operate.
here is my configuration.

Code: Select all

static PWMConfig pwmcfg = {
  30000,                                    /* 10kHz PWM clock frequency.   */
  1000,                                    /* Initial PWM period 1S.       */
  pwmpcb,
  {
   {PWM_OUTPUT_ACTIVE_HIGH, pwmc1cb},
   {PWM_OUTPUT_DISABLED, NULL},
   {PWM_OUTPUT_DISABLED, NULL},
   {PWM_OUTPUT_DISABLED, NULL}
  },
  0,
  0
};

typedef struct {
  uint32_t                  frequency;
  pwmcnt_t                  period;
  pwmcallback_t             callback;
  PWMChannelConfig          channels[PWM_CHANNELS];
} PWMConfig;


uint32_t frequency; is this timer base frequency?
pwmcnt_t period; is this pwm freq?

i gone through documentation, but it is confusing me?

Re: Doubts regarding PWMConfig

Posted: Wed Nov 16, 2016 8:03 pm
by Giovanni
Correct, timer frequency and PWM period in cycles.

Note that the frequency must be a value that can be obtained by the timer input clock, APB1 or APB2 depending on the timer, using the 16bits prescaler. Illegal values are caught by an assertion.

Giovanni

Re: Doubts regarding PWMConfig

Posted: Thu Nov 17, 2016 6:54 pm
by ep.hobbyiest
Giovanni wrote:Note that the frequency must be a value that can be obtained by the timer input clock, APB1 or APB2 depending on the timer, using the 16bits prescaler. Illegal values are caught by an assertion.
Giovanni


i gonna generate 40khz frequency on two channels for sine wave. if i m not wrong, then, in callback function i ll update duty cycle.