Warning
This page is located in archive. Go to the latest version of this course pages.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
courses:be2m37mam:tasks:task03 [2019/10/03 10:36]
viteks
courses:be2m37mam:tasks:task03 [2019/11/14 13:47]
viteks [How timer / counter works]
Line 7: Line 7:
   * Use LED display on the Experimental shield   * Use LED display on the Experimental shield
   * Use button S1 to start/​stop/​clear stopwatch   * Use button S1 to start/​stop/​clear stopwatch
 +
 +==== How timer / counter works ====
 +
 +{{ :​courses:​be2m37mam:​tasks:​timer-1.svg |}}
 +
 +==== Timer TIM2 (pooling) ====
 +
 +<code c>
 +fine getbit(reg, bit)      (((reg) & (1U << (bit))) >> (bit))
 +
 +void initLED(void) {
 +    setbit(RCC->​AHB1ENR,​ 0);
 +    setbit(GPIOA->​MODER,​ 10);
 +}
 +
 +void initTIM2(void)
 +{
 +    /*
 +     * TIM2 je pripojen ke sbernici APB1, ktera bezi na 16MHz
 +     * frekvence pred TIM2 je zvojnasobena PLL
 +     */
 +    setbit(RCC->​APB1ENR,​ 0);  /* enable Clock for TIM2 */
 +    TIM2->​PSC = ?;                /* prescaler - doplnte podle potreby */
 +    TIM2->​ARR = ?;                /* autoreload - doplnte podle potreby */
 +    setbit(TIM2->​CR1,​ 0);        /* enable TIM2 */
 +    clearbit(TIM2->​SR,​ 0);       /* status TIM2 */
 +}
 +
 +int main(void)
 +{
 +    initLED();
 +    initTIM2();
 +
 +    while(1)
 +    {
 +        /* test na UEV (update event) ​   */
 +        if(getbit(TIM2->​SR,​ 0))
 +        {
 +            togglebit(GPIOA->​ODR,​ 5);
 +            /* vraceni status bitu na log 0 */
 +            clearbit(TIM2->​SR,​ 0);
 +        }
 +    }
 +}
 +</​code>​
  
courses/be2m37mam/tasks/task03.txt · Last modified: 2019/11/14 13:47 by viteks