Doubts regarding PWMConfig

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Doubts regarding PWMConfig

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Doubts regarding PWMConfig

Post 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
ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: Doubts regarding PWMConfig

Post 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.
Post Reply