Skip to main content
jeff239955_stm1
Associate II
July 18, 2008
Question

possible silicon errata on TIMx capture/compare prescalers

  • July 18, 2008
  • 17 replies
  • 2131 views
Posted on July 18, 2008 at 11:32

possible silicon errata on TIMx capture/compare prescalers

    This topic has been closed for replies.

    17 replies

    lanchon
    Associate III
    May 17, 2011
    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;

    lanchon
    Associate III
    May 17, 2011
    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.

    lanchon
    Associate III
    May 17, 2011
    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?

    jeff239955_stm1
    Associate II
    May 17, 2011
    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.

    jeff239955_stm1
    Associate II
    May 17, 2011
    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 ]

    lanchon
    Associate III
    May 17, 2011
    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
    May 17, 2011
    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).