TIMER 1 PWM Mode, What am I missing
Hi All,
I want to use timer 1 for my double pulse test. To start with though I want to get it going in a simple PWM mode at first.
I have gone trhough the reference amnual several times and looked at the block diagrams. I have got the registers intialized and the counter, counting. Howver I am gettting nothing at the output when I am trying to toggle the LED. What am I missing?
int init_TIM1()
{
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // Enabling Timer clock
RCC->AHBENR |= RCC_AHBENR_GPIOCEN; // Enabling Port C clock
GPIOC->MODER |= (1<<1); // Setting PC0 as alternate function
GPIOC->MODER |= (1<<3); //Setting PC1 as alternate function
GPIOC->OSPEEDR |= (1<<0) |(1<<1) | (1<<2) |(1<<3) ; // PC0, PC1 = High Speed
TIM1->CCMR1 |= (1<<5) | (1<<6); // Setting Channel 1 in PWM Compare mode 1
TIM1->CCMR1 |= (1<<13) | (1<<14); // Setting Channel 2 as PWM Compare mode 1
TIM1->CCMR1 |= (1<<3) | (1<<11); // Enabling OC1 and OC2 preload registers
TIM1->CCMR1 |= (1<<7) |(1<<15) ; // OCxRef is cleared as soon as a high level is detected on ocref_clr_int signal
TIM1->CR1 |= (1<<7); // Enabling the auto reload preload register for the timer (buffered)
TIM1->PSC = 6499; // PSC = 6500 (6499+1) = 36 Mhz / 6500 = 5538
TIM1->ARR = 5538; // approx 1 s delay
TIM1-> CCR1 = 2769;
TIM1->CCR2 = 5538;
TIM1->EGR |= (1<<5); // Enabling capture compare update generation
TIM1->CCER |= (1<<0) | (1<<4); // Enabling OC outputs for ch1 and ch2 which maps them to the pin
TIM1->BDTR |= (1<<15); // Main output enable
TIM1->EGR |= (1<<0); // Reintializing the counter and generates an update of the registers
TIM1->CR1 |= (1<<0); //enable counter
return(0);
}Cheers
