Skip to main content
Visitor II
January 11, 2010
Question

Is X register available for writing TIMx_CCRyH/L registers ?

  • January 11, 2010
  • 4 replies
  • 1098 views
Posted on January 11, 2010 at 22:50

Is X register available for writing TIMx_CCRyH/L registers ?

    This topic has been closed for replies.

    4 replies

    st25Author
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:07

    I am investigating the usage of the PWM output. I found a code to write the TIM3_CCR2H/L registers at the TIM3_OC2Init function of the FWLib source code stm8s_tim3.c The source code behaves two 8-bit write operations for the timer registers as follows.

    /* Set the Pulse value */

    TIM3->CCR2H = (u8)(TIM3_Pulse >> 8);

    TIM3->CCR2L = (u8)(TIM3_Pulse);

    I assumed that the program would be more simple when the write operation is described as one 16-bit write operation like following.

    volatile u16 TIM3_CCR2 @ 0x00532F;

    :

    TIM3_CCR2 = (u16)TIM3_Pulse;

    But the program using a 16-bit variable to write the timer register has been failed, however the the line is certainly compiled into an LDW instruction sourced from X register.

    Why this program has been failed ? Is the WRITE operation order of the LDW instruction different from what the timer register expected ?

    ---

    noritan.org

    [ This message was edited by: st16 on 10-01-2010 15:34 ]

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:07

    Hi,

    I think that is a security mechanism that is consist to write first the CCR2H register before the CCR1H.

    Regards

    Anis

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:07

    Hi Anis,

    you're right, see reference manual pag. 161 paragraph 17.5.1 (it is for TIM1, but it's valid also for other timers). On 8-bits microcontrollers this kind of read and write mechanism protection is usual :) for r/w access of 16-bit or 10-bit registers as in the case of ADC converted value.

    brazov :(

    st25Author
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:07

    Hi Anis, brazov

    I assumes that the mechanism is for security reason and many other 8-bit MCU with 16-bit timer have same kind of one. It is reasonable for STM7 because STM7 has 8-bit registers only.

    But STM8 has 16-bit registers X and Y. I wonder why the firmware library is still using 8-bit access to the 16-bit timer registers and why STM8 will fail if access to the 16-bit register by the 16-bit X register.

    ---

    noritan.org