cancel
Showing results for 
Search instead for 
Did you mean: 

Speed of PWM generated

nafaazayen
Associate II
Posted on March 11, 2008 at 12:51

Speed of PWM generated

1 REPLY 1
nafaazayen
Associate II
Posted on May 17, 2011 at 09:50

Hi,

I'm trying to generate 44100Hz out of the timer3 PWM output with PCLK 48MHZ.

unfortunately, PWM frequency is too slow.

here my code:

SCU_PCLKDivisorConfig(SCU_PCLK_Div2);

SCU_PLLFactorsConfig(192, 25, 2); /* Configure Factors FPLL = 96MHz */

SCU_PLLCmd(ENABLE);

SCU_MCLKSourceConfig(SCU_MCLK_PLL);

/*init */

/* GPIO4 clock source enable */

SCU_APBPeriphClockConfig(__GPIO4, ENABLE);

SCU_APBPeriphReset(__GPIO4, DISABLE);

GPIO_DeInit(GPIO4);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;

GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_Init(GPIO4,&GPIO_InitStructure);

TIM_StructInit(&TIM_InitStructure);

/* 44.100 KHz generation */

TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1;

TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;

TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;

TIM_InitStructure.TIM_Prescaler =0x1;

TIM_InitStructure.TIM_Pulse_Length_1=0x220;

/* Initialize the Timer 0 */

TIM_Init (TIM0, &TIM_InitStructure);

TIM_StructInit(&TIM_InitStructure);

/* PWM configuration */

TIM_InitStructure.TIM_Mode = TIM_PWM;

TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;

TIM_InitStructure.TIM_Prescaler =0x0;

TIM_InitStructure.TIM_Pulse_Level_1 = TIM_HIGH;

TIM_InitStructure.TIM_Period_Level = TIM_LOW;

TIM_InitStructure.TIM_Pulse_Length_1 =0xff;

TIM_InitStructure.TIM_Full_Period =0x300;

/* Initialize the Timer 3 */

TIM_Init (TIM3, &TIM_InitStructure);

void TIM0_IRQHandler(void)

{

Pulse +=0x220;

TIM_SetPulse(TIM3, TIM_PWM_OC1_Channel,sample);

/* Set the TIM0 OC1 value */

TIM_SetPulse(TIM0, TIM_PWM_OC1_Channel, Pulse);

/* Clear the TIM OC1 flag */

TIM_ClearFlag(TIM0, TIM_FLAG_OC1);

}

If there is something I'm doing wrong, please direct me with the right direction (code).

Thank you in advance,