cancel
Showing results for 
Search instead for 
Did you mean: 

possible silicon errata on TIMx capture/compare prescalers

jeff239955_stm1
Associate II
Posted on July 18, 2008 at 11:32

possible silicon errata on TIMx capture/compare prescalers

17 REPLIES 17
lanchon
Associate III
Posted on May 17, 2011 at 12:39

a few comments.

should be something like:

// called for every CC4I trigger

void TIM2_IRQHandler(void)

{

static u16 CH4_last;

u16 CH4;

CH4 = TIM2_CCR4

P = (u16)(CH4 - CH4_last);

CH4_last = CH4;

}

volatile P;

should be:

Prescaler set to 8

1 / (1000/8 Hz) = 8ms

8ms * 1 MHz = 8000

P equals 1000, incorrect. Should equal 8000.

and what's this?

// timer frequency = 1MHz

/ 74MHz/7400 = 1MHz

TIM2_PSC = 7400;

74MHz? the part max freq is 72MHz. and why 7400? why multiply by 100?

with a 72MHz clock and a 7400 value in the PSC the counter frequency should be 72Mhz/7401, or about 9.728KHz.

with this counter frequency, an 8x CC prescaler and a 1000Hz input, the observed value of P should be:

1 / (1000/8 Hz) = 8ms

P should be around 8ms * 9.728KHz or 78

for a 1MHz counter @ 72MHz use:

TIM2_PSC = 71;

jeff239955_stm1
Associate II
Posted on May 17, 2011 at 12:39

I made the changes to the TIM2 isr.

Code:

// Use to set prescaler to 1, (1000Hz / 1 = 1000Hz)

// connect TI4 to IC4 (Figure 95)

//TIM2_CCMR2_INPUT_CAPTURE_MODE = (0 << TIM2_CCMR2_INPUT_CAPTURE_MODE_IC4PSC)

// | (1 << TIM2_CCMR2_INPUT_CAPTURE_MODE_CC4S);

// use to set prescaler to 8 (1000Hz / 8 = 250Hz)

// connect TI4 to IC4 (Figure 95)

TIM2_CCMR2_INPUT_CAPTURE_MODE = (3 << TIM2_CCMR2_INPUT_CAPTURE_MODE_IC4PSC)

| (1 << TIM2_CCMR2_INPUT_CAPTURE_MODE_CC4S);

// enable CH4 interrupt (TIM2_IRQHandler called on CC4I trigger (Figure 95)

TIM2_CCER = (1 << TIM2_CCER_CC4E);

// enable CH4 capture

TIM2_DIER = (1 << TIM2_DIER_CC4IE_BIT)

// timer frequency = 1MHz

// 72MHz/(71 + 1) = 1MHz

TIM2_PSC = 71;

// TIM2 count up

// TIM2 rolls over to zero then starts again

// enable timer

TIM2_CR1 = 1;

// slave mode controller unused

TIM2_CR2 = 0;

You are definitely right, I made errors in those calculations. Here are the corrections.

Prescaler set to 1:

1000 Hz applied input clock

1/(1000 Hz) = 1ms

1ms * 1 MHz = 1000

frequency (the variable) equals 1000, correct

Prescaler set to 8 (divide the applied 1000 Hz input clock by 8)

1000/8 Hz = 250 Hz

1/(250 Hz) = 4ms

4ms * 1 MHz = 250

frequency (the variable) equals 1000, incorrect. Should equal 250.

TIM2 Prescaler:

72 MHz /(TIM2_PSC + 1) = TIM2 clock fequency

72 MHz /(71 + 1) = 1 MHz

TIM2_PSC = 71

Unfortunately the results are still the same. It still appears the prescaler is not functioning in the silicon.

jeff239955_stm1
Associate II
Posted on May 17, 2011 at 12:39

I made the same mistake again! Sorry, thank you for catching it.

Prescaler set to 8 (divide the applied 1000 Hz input clock by 8)

1000/8 Hz = 125 Hz

1/(125 Hz) = .008s

.008s * 1 MHz = 8000

frequency (the variable) equals 1000, incorrect. Should equal 8000.

What I mean is that no matter what the prescaler is, the frequency variable is always 1000. It’s like the prescaler is not dividing the input at all and it is stuck at 1 even though the prescaler it is set to 8. I verified it is indeed set to 8 by reading and then returning the value of the prescaler register.

For example:

>P equals 1000, incorrect. Should equal 8000.

Even though the prescaler equals 8, the variable P still equals 1000 even though exactly as you said P should equal 8000 instead.

lanchon
Associate III
Posted on May 17, 2011 at 12:39

I insist:

Prescaler set to 8

1/(1000Hz/8) = 8ms (1000Hz/8 = 125Hz!)

8ms*1MHz = 8000

P equals 1000, incorrect. Should equal 8000.

> the results are still the same

what do you mean? the change of TIM2_PSC *must* have affected the capture. exactly what vale are you capturing?

lanchon
Associate III
Posted on May 17, 2011 at 12:39

ok, got it. but you're saying that before and after the change of TIM2_PSC the value in P is the same. if that's true (confirm), then you can be sure that your code is not working as intended. have you changed the 1000Hz input frequency for instance? what happens to P? you say the CC prescaler is not working but it seems many other things are not working either.

jeff239955_stm1
Associate II
Posted on May 17, 2011 at 12:39

>ok, got it. but you're saying that before and after the change of TIM2_PSC the value in P is the same. if that's true (confirm)

Sorry I mean the prescaler of the individual timer channel, not the prescaler TIM2_PSC of the timer itself. For example, the prescaler for CH4 are bits 3:2 of TIM2_CCMR2 (capture compare mode register 2), that is the prescaler I mean.

When CH4 is programed for a prescaler of 8 (bits were read back after writing to confirm it is equals 8) in TIM2_CCMR2, P still equals 1000 even though as we are predicting it should equal 125 (1000/8=125).

lanchon
Associate III
Posted on May 17, 2011 at 12:39

please reread my post!

with TIM2_PSC at 7400 P reads as 1000

then with TIM2_PSC at 71 P reads also as 1000

so...

>before and after the change of TIM2_PSC the value in P is the same. if that's true (confirm), then you can be sure that your code is not working as intended.

jeff239955_stm1
Associate II
Posted on May 17, 2011 at 12:39

>with TIM2_PSC at 7400 P reads as 1000

This was a mistake in my post, TIM2_PSC is correctly set to 71.

The only line of code being changed in the entire program is this:

Code:

<BR>// Use to set prescaler to 1, (1000Hz / 1 = 1000Hz) <BR>// connect TI4 to IC4 (Figure 95) <BR>//TIM2_CCMR2_INPUT_CAPTURE_MODE = (0 << TIM2_CCMR2_INPUT_CAPTURE_MODE_IC4PSC) <BR>// | (1 << TIM2_CCMR2_INPUT_CAPTURE_MODE_CC4S); <BR> <BR> <BR>// use to set prescaler to 8 (1000Hz / 8 = 125Hz) <BR>// connect TI4 to IC4 (Figure 95) <BR>TIM2_CCMR2_INPUT_CAPTURE_MODE = (3 << TIM2_CCMR2_INPUT_CAPTURE_MODE_IC4PSC) <BR> | (1 << TIM2_CCMR2_INPUT_CAPTURE_MODE_CC4S); <BR>

Keeping the first line and commenting the second or keeping the second and commenting the first does not change P as I assume it should (the purpose of a prescaler).

[ This message was edited by: jeff.heiss on 18-07-2008 15:18 ]