atmega162 TIMER3 Interrupt

#1463252
Lesenswert?

Hallo.

ich werde würde beim mega162 gerne 4xpwm (keine Soft-PWM) nutzen und 
zusätzlich noch einen timer (in diesem Fall Timer3) für Interrupt zB. 
Sekundenabläufe ect. nutzen.

Aber irgentwie fehlen beim timer3 OCR3A oder B ect..

Kann mir bitte Jemand etwas auf die Sprünge bringen, wie ich das in dem 
Fall realisieren kann?
#1463266
Lesenswert?

Andreas Scheuerer schrieb:
> Hallo.
>
> ich werde würde beim mega162 gerne 4xpwm (keine Soft-PWM) nutzen und
> zusätzlich noch einen timer (in diesem Fall Timer3) für Interrupt zB.
> Sekundenabläufe ect. nutzen.
>
> Aber irgentwie fehlen beim timer3 OCR3A oder B ect..
>
> Kann mir bitte Jemand etwas auf die Sprünge bringen, wie ich das in dem
> Fall realisieren kann?

sry wegen des langen codes aber ich bekomm keinen anhang rauf
1
_________________________________________________________________________
2

3
//----------------------------------------------------------------------
4
//
5
//----------------------------------------------------------------------
6
#define   F_CPU 19090000  // Taktferquenz des myAVR-Boards
7
#include  <avr\io.h>    // AVR Register und Konstantendefinitionen
8
#include   <math.h>  // Mathematische Funktionen
9
#include   <util/delay.h>
10
#include   <avr/interrupt.h>
11

12
//----------------Interupt Anfang--------------------------------------------------------
13

14
ISR (TIMER3_OVF_vect)
15
{
16
  t ++; 
17

18
  if (t >= 1024)
19
  {
20
    t = 0;
21
    
22
    
23
    
24
    
25
    //PORTB = ~ PORTB;          // Flankenwechsel für Tonfrequenz
26
  }
27
}
28

29
//----------------Interupt Ende----------------------------------------------------------
30
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
//----------------Entprellfunktion Anfang------------------------------------------------
32

33
inline uint8_t debounce(volatile uint8_t *port, uint8_t pin)
34
{
35
    if ( ! (*port & (1 << pin)) )
36
    {
37
        /* Pin wurde auf Masse gezogen, 100ms warten   */
38
        _delay_ms(50);  // max. 262.1 ms / F_CPU in MHz
39
        _delay_ms(50); 
40
        if ( *port & (1 << pin) )
41
        {
42
            /* Anwender Zeit zum Loslassen des Tasters geben */
43
            _delay_ms(50);
44
            _delay_ms(50); 
45
            return 1;
46
        }
47
    }
48
    return 0;
49
}
50

51
//----------------Entprellfunktion Ende--------------------------------------------------
52
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53
//----------------Tastenabfrage Anfang---------------------------------------------------
54
    
55
void tastenabfrage ()
56
{
57
    if (debounce(&PINC, PC0))
58
    {
59
      mode++;
60
      if (mode > 3)
61
      {
62
        mode = 0;
63
      }
64
    }
65
      
66
    if (debounce(&PINC, PC1))
67
    {
68
      if ((mode==0) || (mode==2) || (mode==3))
69
      {
70
        time++;
71
        if (time >9)
72
        {
73
          time = 9;
74
        }
75
      }
76
      else if ((mode==1))
77
      {
78
        color++;
79
        if (color >16)
80
        {
81
          color = 16;
82
        }
83
      }
84
    }
85
    else if (debounce(&PINC, PC2))
86
    {
87
      if ((mode==0) || (mode==2) || (mode==3))
88
      {
89
        time--;
90
        if (time >240)
91
        {
92
          time = 0;
93
        }
94
      }
95
      else if ((mode==1))
96
      {
97
        color--;
98
        if (color >240)
99
        {
100
          color = 0;
101
        }
102
      }
103
    }
104
}
105
//----------------Tastenabfrage Ende-----------------------------------------------------
106
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107
//----------------Mainfunktion Anfang----------------------------------------------------
108

109
main ()            
110
{
111
  // hier Init-Code eintragen
112

113
  unsigned int i = 0;
114
  uint8_t mode = 0;
115
  uint8_t time = 0;
116
  uint8_t color = 0;
117
  uint8_t cr[] = {255, 255,255,255,255,255, 0, 0, 0, 0, 0, 0, 160, 160, 255, 255, 255};
118
  uint8_t cg[] = {0, 0, 128, 128, 255, 255, 255, 255, 144, 2555, 0, 0, 0, 0, 0, 0, 255};
119
  uint8_t cb[] = {0, 0, 0, 0, 0, 0, 0, 0, 144, 255, 255, 255, 255, 255, 255, 255, 255};
120
  uint8_t cw[] = {0, 128, 0, 128, 0, 128, 0, 128, 0, 0,0, 128, 0, 128, 0, 128,  255};
121
  
122
  DDRB  = (1<<PB0) | (1<<PB1) | (1<<PB2);   // Ausgang
123
  DDRD  = (1<<PD5);         // Ausgang
124
  DDRE  = (1<<PE2); // Ausgang
125
  
126
  DDRC &= ~( ( 1 << DDC0 ) | ( 1<<DDC1) | ( 1<<DDC2)); // Eingänge
127
  PORTC |= (1<<PC0) | (1<<PC1) | (1<<PC2); // Pullup
128

129
  //COM1B1 für OCR1B(OC1B) notwendig
130
  TCCR0 = (1<<COM01) | (1<<COM00) | (1<<WGM00) /*| (1<<WGM01)*/ | (1<<CS00)| (1<<CS01);
131
  TCCR1A = (1<<COM1A1) | (1<<COM1A0) | (1<<COM1B1) | (1<<COM1B0) /*| (1<<WGM11)*/ | (1<<WGM10);
132
  TCCR1B = (1<<CS10) | (1<<CS11);
133
  TCCR2 = (1<<COM20) | (1<<COM21) | (1<<WGM20) | (1<<CS10) | (1<<CS11);
134
  //Timer3 für interupt
135
  TCCR3B = (1 << CS30);
136
  TIMSK |= (1<<OCIE3);
137
  
138
  sei();
139
  
140
  // Schleifenanfang Mainloop
141
  while(true)
142
  {
143
    /*OCR0 = 128;
144
    OCR1A  = 128; //360 Werte * 40 = 14400
145
    OCR1B  = 128; //360 Werte * 40 = 14400
146
    OCR2  = 128;
147
    */
148

149
//----------------Tastenabfrage Ende-----------------------------------------------------
150
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151
//----------------Auswahl Modus Anfang---------------------------------------------------
152
    if (mode == 0)//Sanfter Farbwechsel[  ]
153
    {  
154
      cr
155
    }
156
    else if (mode == 1)//Manuelle Farbwahl (0-16)[OK]
157
    {
158
      OCR0 = cr[color];
159
      OCR1A  = cg[color]; 
160
      OCR1B  = cb[color]; 
161
      OCR3A  = cw[color];
162
    }
163
    else if (mode == 2)//Sprunghafter Farbwechsel[  ]
164
    {
165
      color = 0;
166
      while (PINC & (1 << 0))
167
      {
168
      
169
      }
170
    }
171
    else if (mode == 3)//Sonnenaufgang[  ]
172
    {
173
      
174
    }
175
//----------------Auswahl Modus Ende-----------------------------------------------------
176
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177
//---------------------------------------------------------------------------------------    
178
      
179
  }//-----------Schleifenende Whileloop------------------------------------------------
180
        
181
}//---------------Schleifenende Mainloop-------------------------------------------------
#1463521
Lesenswert?

Andreas Scheuerer schrieb:
> Stefan Ernst schrieb:
>>
1
ISR (TIMER3_OVF_vect)
2
>> ...
3
>>  TIMSK |= (1<<OCIE3);
4
>>
Das passt in gleich zweifacher Hinsicht nicht.
>
> Kannst du mir auch erklären warum, bzw. wie ich es richtig machen kann?

OCIE3            _O_utput _C_ompare _I_nterrupt _E_nable Timer-3
TIMER3_OVF_vect  Overflow Interrupt für Timer 3

Was passt da jetzt nicht zusammen?

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