cancel
Showing results for 
Search instead for 
Did you mean: 

TIM2 Output compare problems ?

hervett
Associate II
Posted on November 12, 2008 at 08:44

TIM2 Output compare problems ?

5 REPLIES 5
hervett
Associate II
Posted on May 17, 2011 at 12:51

Hello everybody.

I just want to test my timers in order to generate a 400 kHz signal. I do that with TIMER 2 . My PLLCLK is at 16 MHz ( 8*2 ), so I change the value of the prescaler in order to divide my PLLCLK and so create a signal. And it works......but not for all the value of the prescaler. I try at the beginning with small frequencies and it works, but for a value under 140 ( 0x94), I have something strange, or bad frequencies on the output. But for all the value upper than 0x94 or something like that, it works perfectly, with a beautiful signal and a good frequencie. I have try to fix my prescaler to a good value and change my CCR1_VAL in order to divide frequencie, but it is the same. I really don't understand why !!!!! I find that problem very strange. I put on attached files, all the lines concerning my TIM2, and they are the same than the examples of the library.

I'm using RIDE in order to write and debug my program and transfer it to the STM32F10B eval card.

Really thank you.

:D

brianforde9
Associate II
Posted on May 17, 2011 at 12:51

I had similar problems. Try the folowing...

The (lvPreScaler * 2) below is necessary because of the clock multiplier in the timer clock.

static void lfSampleRateInitialise(unsigned ivFreq)

{

TIM_TimeBaseInitTypeDef lsTimeBase;

RCC_ClocksTypeDef lsRCC_ClocksStatus;

unsigned lvPeriod, lvPreScaler;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);

RCC_GetClocksFreq(&lsRCC_ClocksStatus);

lvPeriod = lsRCC_ClocksStatus.PCLK1_Frequency / ivFreq;

lvPreScaler = (lvPeriod / 0x10000) + 1;

lvPeriod /= lvPreScaler;

lsTimeBase.TIM_Period = lvPeriod - 1;

lsTimeBase.TIM_Prescaler = (lvPreScaler * 2) - 1;

lsTimeBase.TIM_ClockDivision = TIM_CKD_DIV1;

lsTimeBase.TIM_CounterMode = TIM_CounterMode_Down;

TIM_TimeBaseInit(TIM3,&lsTimeBase);

TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update);

return;

}

Regards,

Brian F.

hervett
Associate II
Posted on May 17, 2011 at 12:51

Oh ok Thank you, I will try that and i will say to you if it is OK !!

Thanks again

hervett
Associate II
Posted on May 17, 2011 at 12:51

Hello !

I fixed my problem. But sory i didn't use your solution :D

Instead of make my output frequency of 400 kHz ( so a frequency of 800 Khz for the timer) with the prescaler ( fix my CCR1_VAL and the period ). I changed the period. So the frequency of my TIM2 is PLLCLK ( 16 MHZ ), Prescaler = 0x0 , CCR1_VAL = 0x00 but i've put 0x14 for the period( 16Mhz / 20 = 800 kHz ), and it works perectly.

I hope it will help people with the same problem. !!

See you

hervett
Associate II
Posted on May 17, 2011 at 12:51

I need a lot of coffeeeeee !!

I thought that my problem was fix, but still the same problem after I modified my interupt priority. I have a lot of problems with the priority ! I don't know how to use them. I have my RTC, EXTI9_5, EXTI15_10 and EXTI2, and really don't know why I have troubles !!!!

I will spend again my afternoon on that !!:-Y

If someone has an idea !

Bye