Timer Synchronization
Hello!
Use stm32f107vc.
I'm trying to synchronize two
timers
(TIM3 and TIM5), as including the externaltrigger
. Configure them, as described in RM0008page
386:void TIM3(void)
{
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
TIM3->PSC = 70 - 1;
TIM3->ARR = 25000 - 1;
TIM3->DIER &=~ TIM_DIER_UIE;
// (MMS=001)
TIM3->CR2 |= TIM_CR2_MMS_0; /*!<Bit 0 */
TIM3->CR2 &=~ TIM_CR2_MMS_1; /*!<Bit 1 */
TIM3->CR2 &=~ TIM_CR2_MMS_2; /*!<Bit 2 */
// (TS=100)
TIM3->SMCR &=~ TIM_SMCR_TS_0; /*!<Bit 0 */
TIM3->SMCR &=~ TIM_SMCR_TS_1; /*!<Bit 1 */
TIM3->SMCR |= TIM_SMCR_TS_2; /*!<Bit 2 */
// (SMS=110)
TIM3->SMCR &=~ TIM_SMCR_SMS_0; /*!<Bit 0 */
TIM3->SMCR |= TIM_SMCR_SMS_1; /*!<Bit 1 */
TIM3->SMCR |= TIM_SMCR_SMS_2; /*!<Bit 2 */
// (MSM=1)
TIM3->SMCR |= TIM_SMCR_MSM;
TIM3->CNT = 0;
}
void TIM5 (void)
{
RCC->APB1ENR |= 1<<3;
TIM5->PSC = 70 - 1;
TIM5->ARR = 25000 - 1;
TIM5->DIER &=~ TIM_DIER_UIE;
// (TS=001)
TIM5->SMCR |= TIM_SMCR_TS_0; /*!<Bit 0 */
TIM5->SMCR &=~ TIM_SMCR_TS_1; /*!<Bit 1 */ // TS=001
TIM5->SMCR &=~ TIM_SMCR_TS_2; /*!<Bit 2 */
// (SMS=110)
TIM5->SMCR &=~ TIM_SMCR_SMS_0; /*!<Bit 0 */
TIM5->SMCR |= TIM_SMCR_SMS_1; /*!<Bit 1 */
TIM5->SMCR |= TIM_SMCR_SMS_2; /*!<Bit 2 */
TIM5->CNT = 0;
}
As a result,
taking
the registers at the request of both CNT timers USART to get these values:if
TIM5-> ARR = 25000 - 1, and TIM3-> ARR = 25000 - 1; register values CNT same (eg,TIM5_CNT=
0x5936 andTIM3_CNT=
0x5936 orTIM5_CNT=
0x728 andTIM3_CNT=
0x728).but
if
TIM5-> ARR = 50000 - 1, and TIM3-> ARR = 25000 - 1; register values CNT, in theory, should differ by 25000 (0x61A8
), but really they are, for example, like this -TIM5_CNT=
0x22D4 andTIM3_CNT=
0x216F or such -TIM5_CNT=
0x556D andTIM3_CNT=
0xB5B0(0x22D4 - 0x216F = 0xDE (222) and 0xB5B0 - 0x556D = 0x6043(24643))
.In what could be the problem? Maybe something is wrong configured?