SWARM-Bot Firmware  v1.0
Mobile robot OS - Embedded C/C++
__timer0__.h File Reference

Header file for timer0.c. More...

#include <__swarm_wold__.h>
Include dependency graph for __timer0__.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void _timer0_init (void)
 
void _timer0_init_prescaler (uint16_t prescaler)
 
unsigned long _micros0 (void)
 
unsigned long _millis0 (void)
 

Detailed Description

Header file for timer0.c.

  • File: timer0.h
  • Compiler: GCC-AVR
  • Supported devices: Tested on 328p
  • AppNote: Discrete PID controller
Author
Swarm robot graduation project workgroub
Mechatronics Program for the Distinguished
$Name$
Revision
1

$RCSfile$

Date
/19/2021 9:03:51 AM

Definition in file __timer0__.h.

Function Documentation

◆ _micros0()

unsigned long _micros0 ( void  )

Returns the microseconds passed since timer initialize

55 {
56 
57  if ((TIFR0 & (1 << TOV0)) && (TCNT0 < 255))
58  {
59  _timer0_ovf_cnt++;
60  }
61  return _TICK_US_0*((_timer0_ovf_cnt << 8) + TCNT0);
62 }

Referenced by _dead_reckon().

Here is the caller graph for this function:

◆ _millis0()

unsigned long _millis0 ( void  )

Returns the milliseconds passed since timer initialize

64 {
65 
66  if ((TIFR0 & (1 << TOV0)) && (TCNT0 < 255))
67  {
68  _timer0_ovf_cnt++;
69  }
70  return _TICK_MS_0*(((_timer0_ovf_cnt << 8) + TCNT0));
71 }

◆ _timer0_init()

void _timer0_init ( void  )

Initialize Timer/Counter 0 with clock prescaler of 1024 (244 Hz overflow at 16 MHz)

15 {
16  TCCR0A |= (1 << COM0A1) | (0 << COM0A0) | (1 << COM0B1) | (0 << COM0B0);
17  TCCR0A |= (1 << WGM01) | (1 << WGM00);
18 
19  TCCR0B |=(1 << CS02) | (0 << CS01) | (0 << CS00);
20  TIMSK0 |= (1 << TOIE0);
21  sei();
22 }

Referenced by board_init().

Here is the caller graph for this function:

◆ _timer0_init_prescaler()

void _timer0_init_prescaler ( uint16_t  prescaler)

Initialize Timer/Counter 0 with costume prescaler (see the datasheet)

Parameters
[in]prescalerprescaler 1,2,4,8,255,1024
25 {
26  TCCR0A |= (1 << COM0A1) | (1 << COM0A0) | (1 << COM0B1) | (1 << COM0B0);
27  TCCR0A |= (1 << WGM01) | (1 << WGM00);
28 
29 
30  int __CS__ = 0;
31 
32  switch (prescaler)
33  {
34 
35  case 1:
36  __CS__ = 1;break;
37  case 8:
38  __CS__ = 2;break;
39  case 64:
40  __CS__ = 3;break;
41  case 256:
42  __CS__ = 4;break;
43  case 1024:
44  __CS__ = 5;break;
45  default:
46  TCCR0B &= 0b11111000 ; __CS__ = 0;break;
47 
48  }
49 
50  TCCR0B |= __CS__;
51  TIMSK0 |= (1 << TOIE0);
52 }