STM32F100 on STM32VL Discovery - PWM complementary

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

Moderator: RoccoMarco

bartocham
Posts: 27
Joined: Sun Feb 09, 2014 4:31 pm

Re: STM32F100 on STM32VL Discovery - PWM complementary

Post 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);



???
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F100 on STM32VL Discovery - PWM complementary

Post 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
bartocham
Posts: 27
Joined: Sun Feb 09, 2014 4:31 pm

Re: STM32F100 on STM32VL Discovery - PWM complementary

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

Re: STM32F100 on STM32VL Discovery - PWM complementary

Post 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
bartocham
Posts: 27
Joined: Sun Feb 09, 2014 4:31 pm

Re: STM32F100 on STM32VL Discovery - PWM complementary

Post by bartocham »

So maybe you have some idea how to obtain that kind of PWM frequency?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F100 on STM32VL Discovery - PWM complementary

Post by Giovanni »

Clocking the device to a frequency that can be divided by 5000000.

Giovanni
Post Reply