Hallo, meine Frage zur "Fast PWM" auf dem mega8A (4MHz ext. Quarz) ist zu folgenden Code. Arbeite mit #define TX_T1_B.
1 | /** self triggered transmission from buffer */
|
2 | ISR(CODINGTIMER_OCM) |
3 | {
|
4 | HW_Output(); |
5 | }
|
6 | |
7 | /** interupt routine on overflow */
|
8 | static inline void HW_Output(void) |
9 | {
|
10 | /* active transmission */
|
11 | g_ubSize--; |
12 | #ifdef TX_TIMER2
|
13 | OCR2 = g_uwOCR[g_ubSize]; |
14 | #endif
|
15 | #ifdef TX_T1_A
|
16 | OCR1A = g_uwOCR[g_ubSize]; |
17 | #endif
|
18 | #ifdef TX_T1_B
|
19 | OCR1B = g_uwOCR[g_ubSize]; |
20 | #endif
|
21 | if(uwCycle < D_CYC) |
22 | WrVal(g_uwOCR[g_ubSize], 0); |
23 | /* ready, initiate sync */
|
24 | if (g_ubSize == 0) |
25 | HW_Sync(); |
26 | }
|
27 | static inline void HW_TxInit(void) |
28 | {
|
29 | #ifdef TX_TIMER2 // timer 2
|
30 | /* initialize sync bit, init fast pwm */
|
31 | OCR2 = BIT_1; |
32 | TCNT2 = 0; |
33 | g_ubSize = TX_BITS; |
34 | TIFR |= (1<<TOV2); |
35 | TIMSK |= (1<<TOIE2); |
36 | #endif
|
37 | #ifdef TX_T1_A // timer 1 A
|
38 | OCR1A = stTx.uwBit1; |
39 | ICR1 = stTx.uwTx; |
40 | TCNT1 = stTx.uwTx-1; |
41 | g_ubSize = TX_BITS; |
42 | TIFR |= (1<<TOV1) | (1<<ICF1); |
43 | TIMSK |= (1<<OCIE1A); |
44 | #endif
|
45 | #ifdef TX_T1_B // timer 1 B
|
46 | OCR1B = stTx.uwBit1; |
47 | OCR1A = stTx.uwTx; |
48 | TCNT1 = 0xFFFF; |
49 | ICR1 = 0; |
50 | g_ubSize = TX_BITS; |
51 | TIFR |= (1<<TOV1) | (1<<ICF1); |
52 | TIMSK |= (1<<OCIE1B); |
53 | #endif
|
54 | }
|
55 | |
56 | static inline void HW_TxActive(void) |
57 | {
|
58 | /** inverted PWM(OCR set, OVF clr), prescaler by define */
|
59 | #ifdef TX_TIMER2 // atmega8A
|
60 | TCCR2 = (3<<WGM20) | (2<<COM20) | (PRES_BTX << CS20); |
61 | #endif
|
62 | #ifdef TX_T1_A // atmega8
|
63 | TCCR1A = (2<<WGM10) | (3<<COM1A0); |
64 | TCCR1B = (3<<WGM12) | (stTx.ubTxPresc << CS10); |
65 | #endif
|
66 | #ifdef TX_T1_B // atmega8
|
67 | TCCR1A = (3<<WGM10) | (3<<COM1B0); |
68 | TCCR1B = (3<<WGM12) | (stTx.ubTxPresc << CS10); |
69 | #endif
|
70 | }
|
Der Timer1 arbeitet mit Fast PWM, TOP = OCR1A . Das Register OCR1B ist ja gepuffert und die Aktualisierung erfolgt nur bei TOP. Muss ich nun wirklich einen Ueberlauf erzwingen damit ORC1B aktiv wird? Wie muss dieser Ueberlauf aussehen mit TCNT1 = 0x0000, mit TCNT1 = ORC1A-1 starten. Kann es im Simulator leiderns nicht testen da dieser einen Bug mit Timer1 hat (siehe Wiki). Hab leiderns kein Oszi und kann die PWM nicht ueberpruefen. Gruss daniel