Here, i am working on STM32F401 controller, where i am using PLL with HSI working at 72MHz freq. The timer is generating a PWM output but instead of generating 24 pulses as per my requirement it is only generating 6 pulses. Hence 2 pulses for every 8 inputs. Where can it be wrong, as i am newly working on high frequencies i am not sure.
uint8_t pwmData[24]={61,61,61,61,61,61,61,61, 39,39,39,39,39,39,39,39, 39,39,39,39,39,39,39,39};
int main()
{
RCC_Init();
GPIOA_PCLK_EN;
// PWM Alternate Functionality
pwm.pGPIOx = GPIOA;
pwm.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_AF;
pwm.GPIO_PinConfig.GPIO_PinAltFunMode = 1;
pwm.GPIO_PinConfig.GPIO_PinNumber = 0; // Timer 1 Channel 1
GPIO_Init(&pwm);
// Enable clock for timer 2
TIM2_EN;
// Timer CCER bit enable
TIM2->TIMx_CCER |= (1<<0);
// ARPE bit enable
TIM2->TIMx_CR1 |= (1 << 7);
// Enable OC1PE bit and OC1M bit
TIM2->TIMx_CCMR1 |= ((6 << 4)|(1 << 3));
// Generate 1ms delay from 16MHz clock, pre-scalar value is 16000-1
TIM2->TIMx_PSC = 1 - 1;
// Store the count in ARR
TIM2->TIMx_ARR = 90-1; // 100 milliseconds
// Enable UG bit in EGR
TIM2->TIMx_EGR |= (1 << 0);
// Timer Count = 0
TIM2->TIMx_CNT = 0; // counter reset
// Timer enable
TIM2->TIMx_CR1 |= (1 << 0); // Timer2
while(1)
{
for(int i=0;i<24;i++)
// Set duty cycle
TIM2->TIMx_CCR1 = pwmData[i];
}
}