Doubt about PWMConfig Structure.
Moderators: RoccoMarco, lbednarz, tfAteba
Doubt about PWMConfig Structure.
Hi,
I am using example code for STM32F4 Discovery to generate PWM. It is defined as follow
static PWMConfig pwmcfg = {
10000, /* 10KHz PWM clock frequency. */
10000, /* PWM period 1S (in ticks). */
pwmpcb,
{
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL}
},
/* HW dependent part.*/
0
};
Here first two values are PWM frequency and period, third values is to initiate ADC conversion. Last value is HW dependent part which to be kept at zero. I am not clear about definition of fourth values and what it relates to and why it has four parameters ?? Please explain.
Sapan
I am using example code for STM32F4 Discovery to generate PWM. It is defined as follow
static PWMConfig pwmcfg = {
10000, /* 10KHz PWM clock frequency. */
10000, /* PWM period 1S (in ticks). */
pwmpcb,
{
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL}
},
/* HW dependent part.*/
0
};
Here first two values are PWM frequency and period, third values is to initiate ADC conversion. Last value is HW dependent part which to be kept at zero. I am not clear about definition of fourth values and what it relates to and why it has four parameters ?? Please explain.
Sapan
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Doubt about PWMConfig Structure.
Hi,
In the STM32 each PWM unit has four PWM channels, those constants define the mode of the four channels:
Channels 1 and 4 are active high, channels 2 and 3 are disabled, the NULL are the pointers to callbacks associated to each channel, in this case no callbacks are specified for channels.
Giovanni
In the STM32 each PWM unit has four PWM channels, those constants define the mode of the four channels:
Channels 1 and 4 are active high, channels 2 and 3 are disabled, the NULL are the pointers to callbacks associated to each channel, in this case no callbacks are specified for channels.
Giovanni
Re: Doubt about PWMConfig Structure.
Whats the difference between PWM clock frequency which is 10khz in this case and pwm period??
Re: Doubt about PWMConfig Structure.
PWM period is period in seconds...here 10000 = 1s, 1000 = 100 ms and so on...correct?
Re: Doubt about PWMConfig Structure.
PWM clock frequency is clock frequency to the internal PWM counter. PWM period is value in that counter. So, 10000 counts on 10kHz is exactly 1 second.
Re: Doubt about PWMConfig Structure.
Got it...was just playing around with those two values and checking the results on oscilloscope.
Re: Doubt about PWMConfig Structure.
Hi,
I want to use TIM8_CH2N on PB14 and TIM8_CH3N on PB15 to generate PWM outputs on these pins. Should I follow same procedure as given in sample code or do I need to do something different?
Regards,
Sapan
I want to use TIM8_CH2N on PB14 and TIM8_CH3N on PB15 to generate PWM outputs on these pins. Should I follow same procedure as given in sample code or do I need to do something different?
Regards,
Sapan
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Doubt about PWMConfig Structure.
It is the same, just take care to program the associated I/O pins correctly.
Giovanni
Giovanni
Re: Doubt about PWMConfig Structure.
I have made following setting to use PB14 and PB15 via TIM8_CH2N and TIM8_CH3N on discovery board.
I am not getting PWM on PB14 and 15. Do I need to do anything different or have I made mistake somewhere?
Code: Select all
/*pwmcfg8 - to be used for PWM8..i.e timer 8 */
static PWMConfig pwmcfg8 = {
1000000, /* 1MHz PWM clock frequency. */
20000, /* 20 ms time period*/
NULL,
{ /*CH2N and CH3N of Timer 8 are available for PWM. Enable those */
/* disable rest*/
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_DISABLED, NULL}
},
/* HW dependent part.*/
0
};
pwmStart(&PWMD8, &pwmcfg8);
palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(3));
palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(3));
/*This will generate pulse of 5ms on PB14 and 10ms on PB15 */
pwmEnableChannelI(&PWMD8, 1, PWM_FRACTION_TO_WIDTH(&PWMD8, 6000, 1500)); /*PB14 -> CH2N */
pwmEnableChannelI(&PWMD8, 2, PWM_FRACTION_TO_WIDTH(&PWMD8, 6000, 3000)); /*PB15 -> CH3N */
I am not getting PWM on PB14 and 15. Do I need to do anything different or have I made mistake somewhere?