2011-07-11 12:38 PM
Hi guys!
I need to get counter to work in PWM1 mode to generate codec clock and feed it with this clock and synchronise signal with frequency of master codec clock divided by 256. Repetition counter seemed to be perfect solution. But below configuration (I have also tried to use standard library) does not work as it suppose to:void TIM1_Config (void)
{ NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef IO_InitStruct;/* TIM1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_TIM1, ENABLE);/* Enable the TIM1 GPIO on PA10 */
IO_InitStruct.GPIO_Pin = GPIO_Pin_10; IO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; IO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &IO_InitStruct);TIM1->CR1 = 0x00000000; // default
TIM1->PSC = 0x00000001; // set max prescaler TIM1->ARR = 0x000000FF; // set max reload count TIM1->CCR3 = 0x00000080; // set PWM start value TIM1->RCR = 0x0000000A; // set to check if working TIM1->CCMR2 = 0x00000068; // set PWM mode 1 TIM1->CCER = 0x00000100; // enable CH3 output TIM1->BDTR = 0x00008000; // set MOE bit to enable TIM1 TIM1->EGR = 0x00000001; // enable update // TIM1->DIER = 0x00000009; // enable interrupts->below TIM1->CR1 = 0x00000001; // enable timer/* Enable the TIM1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_TIM16_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_Init(&NVIC_InitStructure);TIM1->DIER |= TIM_IT_Update;
TIM1->DIER |= TIM_IT_CC3; } CC3 and Update interrupts are generated on each timer overflow. CC3 is OK but update interrupt shouldn't be generated, it should wait for RCR to decrease to zero. But RCR does not decreases (i set a memory watch in Keil debugger window). What I am doing wrong? More info: I am using STM32VL-Discovery board. Clock is fed from 4.096MHz quartz crystal. I am scaling crystal to run at 32.768MHz (I know it is more than it suppose to but it runs OK). Below I attach interrupt routines: void TIM1_UP_TIM16_IRQHandler(void) { if ((TIM1->SR & TIM_IT_Update) != 0) // check interrupt source { PCMSYNC = ~PCMSYNC; TIM1->SR &= ~TIM_IT_Update; // clear UIF flag } }void TIM1_CC_IRQHandler(void)
{ if ((TIM1->SR & TIM_IT_CC3) != 0) // check interrupt source { PCMSYNC = 0; TIM1->SR &= ~TIM_IT_CC3; // clear UIF flag } } I appreciate any help!