Page 2 of 2

Re: STM32F100 on STM32VL Discovery - PWM complementary

Posted: Thu Nov 20, 2014 8:19 pm
by bartocham
So the setting should be like:

Code: Select all

static PWMConfig pwmcfg = {
  10000, /* 10Khz PWM clock frequency */
  10,
  NULL,  /* No callback */
  /* Only channel 1 enabled */
  {
    {PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
  },
  0,
  0,
#if STM32_PWM_USE_ADVANCED
  0
#endif
};


Code: Select all

 /* Enables PWM output (of TIM1, channel 1) on LED connected to PA8 */
  palSetPadMode(GPIOA, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL);

  /* Enables PWM output (of TIM1, channel 1N) on LED connected to PB13 */
  palSetPadMode(GPIOB, 13, PAL_MODE_STM32_ALTERNATE_PUSHPULL);

  pwmStart(&PWMD1, &pwmcfg);
  pwmEnableChannel(&PWMD1, 0, 100);



???

Re: STM32F100 on STM32VL Discovery - PWM complementary

Posted: Thu Nov 20, 2014 8:26 pm
by Giovanni
Note that you set the period to 10 this means that you have 11 integer duty cycle settings for your PWM: 0...10. This means that you cannot set the duty cycle to 100, 10 is the maximum.

Both the period and the duty cycle are expressed as number of clock cycles.

Giovanni

Re: STM32F100 on STM32VL Discovery - PWM complementary

Posted: Wed Nov 26, 2014 12:29 pm
by bartocham
Hi Giovani,

Now it is clear. I'm wondering if it is possible to get 500kHz signal. Can I set PWMConfig like this:

Code: Select all

static PWMConfig pwmcfg = {
  5000000, /* 5MHz PWM clock frequency */
  10,
  NULL,  /* No callback */
  /* Only channel 1 enabled */
  {
    {PWM_OUTPUT_ACTIVE_HIGH | PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
  },
  0,
  0,
#if STM32_PWM_USE_ADVANCED
  0
#endif
};


Code: Select all

/* Enables PWM output (of TIM1, channel 1) on LED connected to PA8 */
  palSetPadMode(GPIOA, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL);

  /* Enables PWM output (of TIM1, channel 1N) on LED connected to PB13 */
  palSetPadMode(GPIOB, 13, PAL_MODE_STM32_ALTERNATE_PUSHPULL);

  pwmStart(&PWMD1, &pwmcfg);
  pwmEnableChannel(&PWMD1, 0, 5);

Re: STM32F100 on STM32VL Discovery - PWM complementary

Posted: Wed Nov 26, 2014 1:48 pm
by Giovanni
The clock frequency must be something you can obtain from the timer clock using an integer divider, so no.

If you try that an assertion will block you in pwmStart().

Giovanni

Re: STM32F100 on STM32VL Discovery - PWM complementary

Posted: Wed Nov 26, 2014 2:13 pm
by bartocham
So maybe you have some idea how to obtain that kind of PWM frequency?

Re: STM32F100 on STM32VL Discovery - PWM complementary

Posted: Wed Nov 26, 2014 2:17 pm
by Giovanni
Clocking the device to a frequency that can be divided by 5000000.

Giovanni