AnsweredAssumed Answered

What difference between setting TIM_TimeBaseStructure.TIM_Prescaler and TIM_PrescalerConfig?

Question asked by duy.nguyen on May 14, 2013
Latest reply on May 16, 2013 by duy.nguyen
       As the subject above, can sb tell me about the difference between TIM_TimeBaseStructure.TIM_Prescaler and  TIM_PrescalerConfig?
As below is the code from ST Example Librabry:
[CODE]

__IO uint16_t CCR1_Val = 54618;

 PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 500000) - 1;

  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = 65535;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

  /* Prescaler configuration */
  TIM_PrescalerConfig(TIM3, PrescalerValue, TIM_PSCReloadMode_Immediate);

  /* Output Compare Timing Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = CCR1_Val; (CCR1_Val =
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC1Init(TIM3, &TIM_OCInitStructure);

  TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);
[/CODE]
and Handler
[CODE]
if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)
  {
    TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);

    /* LED4 toggling with frequency = 4.57 Hz */
    STM_EVAL_LEDToggle(LED4);
    capture = TIM_GetCapture1(TIM3);
    TIM_SetCompare1(TIM3, capture + CCR1_Val);
  }
[/CODE]
As the code above, why period is 65535, i've read a thread swhere about this issue and they said : "Here ARR is set to 65535. The objective was to generate an interrupt at every overflow of CC register and immediately sett the counter to zero so that the timer cannot go beyond CC value".
Is this true? Why when i use counter_down mode, and set period =1 , is going wrong?
Why when i use tim2 and set period at (2^32 -1) , it dun run as the same as tim3 with 65535 ( 2^16 -1 ) ?
Sorry for alot question, i'm a beginner with lots of question. Hope sb can help me. Thanks alot.

Outcomes