Timer 0 und ich seh den Fehler nicht.

Gast #5593961
Lesenswert?

Leute ich seh den Fehler nicht,
ich will an Pin A3 eine PWM erzeugen aber der Timer läuft irgendwie 
nicht an ...

hier mal der eigentlich kurze Code, sieht da jemand einen Fehler?

Eigentlich sollte der doch laufen, hat sonst noch jemand eine idee?
1
#include <stdlib.h>
2
#include <avr/io.h>
3
#include <avr/interrupt.h>
4
//#include <avr/pgmspace.h>
5
//#include <inttypes.h>
6
//#include <avr/eeprom.h>
7
//#include <string.h>
8
//#include <util/delay.h>
9
//#include <avr/wdt.h>
10

11
/* define CPU frequency in Mhz here if not defined in Makefile */
12
#ifndef F_CPU
13
#define F_CPU 14745600UL
14
#endif
15

16

17

18

19
#define LED_DDR         DDRA
20
#define LED_PORT        PORTA
21

22
#define LED1            0
23
#define LED2            1
24

25
#define P_PORT      PORTA
26
#define P_DDR      DDRA
27
#define  P1_PIN      3
28
#define  P2_PIN      4
29

30

31

32

33
ISR(TIMER0_OVF_vect)
34
{
35
  P_PORT |= (1<<P1_PIN); 
36
  
37
}
38

39
ISR(TIMER0_COMP_vect)
40
{
41

42
  P_PORT &= ~(1<<P1_PIN);
43
}
44

45

46

47

48

49
int main(void)
50
{
51

52
  TCCR0 |= (1<<CS02) | (1<<CS00);              
53
  OCR0 = 0x80;                        
54

55
  P_DDR |= (1<<DDA3);
56
  P_DDR |= (1<<DDA4);
57

58

59
    sei();
60

61
  TIMSK |= (1<TOIE0) | (1<<OCIE0) ;
62
  P_PORT |= (1<<P1_PIN); 
63

64
while(1)
65
{
66

67
  return 0;
68

69
}
70
}
Beitrag #5593962 wurde von einem Moderator gelöscht.
Gast #5593997
Lesenswert?

Habe das so gändert, der Fehler bleibt:
1
int main()
2
{
3

4
  TCCR0 |= (1<<CS02) | (1<<CS00);              
5
  OCR0 = 0x80;                        
6

7
  P_DDR |= (1<<DDA3);
8
  P_DDR |= (1<<DDA4);
9

10

11
    sei();
12

13
  TIMSK |= (1<TOIE0)  ;
14
  //P_PORT |= (1<<P1_PIN); 
15

16
while(1)
17
{
18

19
  
20

21
};
22
return 0;
23
}
Gast #5594012
Lesenswert?

Der Timer läuft nicht eigentlich muss der ja laufen wenn ich den OVF 
Interrupt einschalte, habe gerade UART0 mal aktiviert, das senden klappt 
und er bleibt auch in der Endlosschleife, also das Programm wird nicht 
beendet.
aber der Pin toggelt einfach nicht in der ISR
Gast #5594025
Lesenswert?

Entshculdigung ich habe zwischenzeitlich die routine so einfach wie 
möglich gemacht:
1
#include <stdlib.h>
2
#include <avr/io.h>
3
#include <avr/interrupt.h>
4
//#include <avr/pgmspace.h>
5
//#include <inttypes.h>
6
//#include <avr/eeprom.h>
7
//#include <string.h>
8
//#include <util/delay.h>
9
//#include <avr/wdt.h>
10

11
/* define CPU frequency in Mhz here if not defined in Makefile */
12
#ifndef F_CPU
13
#define F_CPU 14745600UL
14
#endif
15

16
/* 19200 baud Kessel */
17
#define BAUD2 9600UL          // Baudrate
18
#define UBRR_VAL_U0 ((F_CPU+BAUD2*8)/(BAUD2*16)-1)   // clever runden
19

20

21
#define LED_DDR         DDRA
22
#define LED_PORT        PORTA
23

24
#define LED1            0
25
#define LED2            1
26

27
#define P_PORT      PORTA
28
#define P_DDR      DDRA
29
#define  P1_PIN      3
30
#define  P2_PIN      4
31

32

33
void USART_Transmit( char data )
34
{
35
  /* Wait for empty transmit buffer */
36
  while ( !( UCSR0A & (1<<UDRE0)) )
37
  ;
38
  /* Put data into buffer, sends the data */
39
  UDR0 = data;
40
}
41

42
ISR(TIMER0_OVF_vect)
43
{
44
  P_PORT ^= (1<<P1_PIN); 
45
  
46
}
47

48
ISR(TIMER0_COMP_vect)
49
{
50

51
  //P_PORT &= ~(1<<P1_PIN);
52
}
53

54

55

56

57

58
int main()
59
{
60

61
  TCCR0 |= (1<<CS02) | (1<<CS00);              
62
  OCR0 = 0x80;                        
63

64
  P_DDR |= (1<<DDA3);
65
  P_DDR |= (1<<DDA4);
66

67
 //USART0
68
     UBRR0H = UBRR_VAL_U0 >> 8;
69
     UBRR0L = UBRR_VAL_U0 & 0xFF;
70
  UCSR0B |= (1<<TXEN0);                // UART TX einschalten
71
 // UCSR0B |= (1<<RXEN0);
72
 // UCSR0B |= (1<<RXCIE0);
73
  UCSR0C |= (1<<URSEL0)|(1<<UCSZ00)| (1<<UCSZ01);    // Asynchron 8N1
74

75
    sei();
76

77
  TIMSK |= (1<TOIE0)  ;
78
  //P_PORT |= (1<<P1_PIN); 
79
USART_Transmit('L');  
80
while(1)
81
{
82

83

84

85
};
86
return 0;
87
}

da wird in der OVF Routine getoggelt, eigentlich...
Gast #5594193
Lesenswert?

Leute ich danke euch !!!
War echt zu spät gestern und ich habs echt übersehen, so ein Mist, ich 
hab echt an mir gezweifelt weil das ja eigentlich nicht viele Befehle 
sind.

So ein Mist, und dafür wertvollen Speicherplatz im Internet verwendet...

Vielen Dank, läuft...

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren