Problem mit Timer Atmega8515

Gast #1094936
Lesenswert?
• ▲
▼
Hi Leute,

ich habe eine Problem mit dem Timer beim Atmega8515.

Hab mich so gut es ging durch das Datenblatt gewurstelt, doch irgendwo 
klemmt es noch.

Leider finde ich nirgends einen Beispiel Code und mit dem Tutorium komme 
ich auch nicht recht weiter.

Hier mein Code.
1
/* Test Timer Atmega8515 STK 500 */
2

3
 
4
#include <avr/io.h>          // (1)
5
#include <inttypes.h>
6
#include <avr/interrupt.h>
7
#include <stdlib.h>
8
#define F_CPU 8000000UL
9

10
uint16_t count_overflow=0;
11
int timer;
12

13
int main (void) {            // (2)
14
   DDRB  = 0xff;             // (3)
15
   PORTB = 0xff;
16
   //DDRA  = 0x0;
17
   
18
   int i;
19
   i = 1;
20
   
21

22

23
 // Timer0 (8Bit): Normal-Mode(0), Prescaler 1/1024
24
  TCCR0 = (0<<FOC0)|(0<<WGM00)|(1<<COM01)|(0<<COM00)|(0<<WGM01)|(1<<CS02)|(0<<CS01)|(1<<CS00);
25
  TIMSK = (0<<OCIE1B)|(0<<OCIE1A)|(1<<TOIE1); // Overflow ON
26

27
  sei(); // interupts global on
28

29

30
   while(1) {
31
   
32
   if(i == 0 && timer == 1) {
33
   PORTB = 0xf0;
34
   i=1;
35
   timer = 0;
36
   }
37
   
38
   if(i == 1 && timer == 1) {
39
   PORTB = 0x0f;
40
   i=0;
41
   timer = 0;
42
   }
43
   
44

45

46
   } 
47

48

49
}
50

51

52
// Timer0 Overflow Interrupt ------------------------------
53
ISR (TIMER0_OVF_vect)
54
{
55
  count_overflow++; 
56
  if (count_overflow >= 4000)
57
  {
58
    timer = 1;
59
    count_overflow = 0; // reset counter
60
  }
61
} //-------------------------------------- Ende TOV0_INT */

Kann es sein das für die Verwendung des Timers noch etwas an den Fuse 
Bits eingestellt werden muss?

FUSE_BITS = -u -U lfuse:w:0xff:m -U hfuse:w:0xd9:m

Danke für eure Hilfe wünsch schon mal einen guten Rutsch

Gruß Sebastian
Gast #1094960
Lesenswert?
• ▲
▼
Super danke das war es!

Für alle nach mir, hier nochmal mein Funktionsfähiger Code!
1
/* Test Timer Atmega8515 STK 500 */
2

3
 
4
#include <avr/io.h>          // (1)
5
#include <inttypes.h>
6
#include <avr/interrupt.h>
7
#include <stdlib.h>
8
#define F_CPU 8000000UL     /* Takt STK 500 mit  */
9

10
volatile uint16_t count_overflow=0;
11
volatile int timer;
12

13
int main (void) {            // (2)
14
   DDRB  = 0xff;             // (3)
15
   PORTB = 0xff;
16
   //DDRA  = 0x0;
17
   
18
   int i;
19
   i = 1;
20
   
21

22

23
 // Timer0 (8Bit): Normal-Mode(0), Prescaler 1/1024
24
  TCCR0 = (0<<FOC0)|(0<<WGM00)|(1<<COM01)|(0<<COM00)|(0<<WGM01)|(0<<CS02)|(0<<CS01)|(1<<CS00);
25
  TIMSK = (0<<OCIE1B)|(0<<OCIE1A)|(1<<TOIE0); // Overflow ON
26

27
  sei(); // interupts global on
28

29

30
   while(1) {
31
   
32
   if(i == 0 && timer == 1) {
33
   PORTB = 0xf0;
34
   i=1;
35
   timer = 0;
36
   }
37
   
38
   if(i == 1 && timer == 1) {
39
   PORTB = 0x0f;
40
   i=0;
41
   timer = 0;
42
   }
43
   
44

45

46
   } 
47

48

49
}
50

51

52
// Timer0 Overflow Interrupt ------------------------------
53
ISR (TIMER0_OVF_vect)
54
{
55
  count_overflow++; 
56
  if (count_overflow >= 4000)
57
  {
58
    timer = 1;
59
    count_overflow = 0; // reset counter
60
  }
61
} //-------------------------------------- Ende TOV0_INT */

Danke guten Rutsch

Sebastian
Gast #1094968
Lesenswert?
• ▲
▼
Super danke das war es!

Für alle nach mir, hier nochmal mein Funktionsfähiger Code!
1
/* Test Timer Atmega8515 STK 500 */
2

3
 
4
#include <avr/io.h>          // (1)
5
#include <inttypes.h>
6
#include <avr/interrupt.h>
7
#include <stdlib.h>
8
#define F_CPU 8000000UL    
9

10
volatile uint16_t count_overflow=0;
11
volatile int timer;
12

13
int main (void) {            // (2)
14
   DDRB  = 0xff;             // (3)
15
   PORTB = 0xff;
16
   //DDRA  = 0x0;
17
   
18
   int i;
19
   i = 1;
20
   
21

22

23
 // Timer0 (8Bit): Normal-Mode(0), Prescaler 1/1024
24
  TCCR0 = (0<<FOC0)|(0<<WGM00)|(1<<COM01)|(0<<COM00)|(0<<WGM01)|(0<<CS02)|(0<<CS01)|(1<<CS00);
25
  TIMSK = (0<<OCIE1B)|(0<<OCIE1A)|(1<<TOIE0); // Overflow ON
26

27
  sei(); // interupts global on
28

29

30
   while(1) {
31
   
32
   if(i == 0 && timer == 1) {
33
   PORTB = 0xf0;
34
   i=1;
35
   timer = 0;
36
   }
37
   
38
   if(i == 1 && timer == 1) {
39
   PORTB = 0x0f;
40
   i=0;
41
   timer = 0;
42
   }
43
   
44

45

46
   } 
47

48

49
}
50

51

52
// Timer0 Overflow Interrupt ------------------------------
53
ISR (TIMER0_OVF_vect)
54
{
55
  count_overflow++; 
56
  if (count_overflow >= 4000)
57
  {
58
    timer = 1;
59
    count_overflow = 0; // reset counter
60
  }
61
} //-------------------------------------- Ende TOV0_INT */

Danke guten Rutsch

Sebastian

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.