cancel
Showing results for 
Search instead for 
Did you mean: 

About the timer capture register.

EChep
Associate

If you read the capture register like this

  uint16_t capch; 
  capch=*((uint16_t*)&TIM2_CCR3H);

This code will be compiled into an ldw instruction.The data is read incorrectly.

The following code gives the correct result.

    uint16_t capch;   
    ((uint8_t *)&capch)[0]=TIM2_CCR3H;
    ((uint8_t *)&capch)[1]=TIM2_CCR3L;

This means that the CCR has a shadow buffer register.

Could you tell me please, in what document about this said, thank you

1 REPLY 1
Uwe Bonnes
Principal III

CCR is constant until some capture happens. So a correct result is expected as long as no capture happens between the two reads. Try with the CNT register with no prescaler. Then you can see if some shadow buffer is involved.