cancel
Showing results for 
Search instead for 
Did you mean: 

How to use oscillator as a TIMER clock source ?

hazall
Associate III
#define ExternalOSCport GPIOA
#define ExternalOSCTimer TIM1
#define ExternalOSCpin GPIO_Pin_8
 
voidClock_Config(){
 
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
 
NVIC_InitTypeDef   NVIC_InitStructure;
GPIO_InitTypeDef   GPIO_InitStructure;
 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); //Clock enable 
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 
GPIO_InitStructure.GPIO_Pin = ExternalOSCpin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(ExternalOSCport, &GPIO_InitStructure);
 
GPIO_PinAFConfig(ExternalOSCport, GPIO_PinSource8, GPIO_AF_2); //alternate func
 
 
ExternalOSCTimer->CR2 &= 0XFF7F;
ExternalOSCTimer->PSC = 0; //set prescale value
ExternalOSCTimer->SMCR |= (uint16_t)(TIM_TS_TI1FP1 | TIM_SMCR_SMS  ); // external mode 1
ExternalOSCTimer->CR1 &= (uint16_t)(~((uint16_t)TIM_CR1_CEN));  //disable timer counting
ExternalOSCTimer->EGR = (uint16_t)TIM_EGR_UG;  //disable timer counting
ExternalOSCTimer->CR1 &= (uint16_t)(~((uint16_t)TIM_CR1_ARPE));  
 
ExternalOSCTimer->SR &= (uint16_t)~TIM_SR_CC2IF ;
ExternalOSCTimer->DIER |= TIM_IT_Update; //???
 
TIM1->EGR |= TIM_EGR_UG; 
 
NVIC_EnableIRQ(TIM1_CC_IRQn);
 
 
}

I am using stm32f030c8

This is my configuration code. Sometimes I am missing clock pulses. Thats my problem.

0 REPLIES 0