Rev 477 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 477 | Rev 496 | ||
---|---|---|---|
1 | #include "main.h" |
1 | #include "main.h" |
2 | 2 | ||
3 | volatile unsigned int CountMilliseconds = 0; |
3 | volatile unsigned int CountMilliseconds = 0; |
4 | volatile unsigned char UpdateMotor = 0; |
4 | volatile unsigned char UpdateMotor = 0; |
5 | volatile unsigned int beeptime = 0; |
5 | volatile unsigned int beeptime = 0; |
6 | int ServoValue = 0; |
6 | int ServoValue = 0; |
7 | 7 | ||
8 | enum { |
8 | enum { |
9 | STOP = 0, |
9 | STOP = 0, |
10 | CK = 1, |
10 | CK = 1, |
11 | CK8 = 2, |
11 | CK8 = 2, |
12 | CK64 = 3, |
12 | CK64 = 3, |
13 | CK256 = 4, |
13 | CK256 = 4, |
14 | CK1024 = 5, |
14 | CK1024 = 5, |
15 | T0_FALLING_EDGE = 6, |
15 | T0_FALLING_EDGE = 6, |
16 | T0_RISING_EDGE = 7 |
16 | T0_RISING_EDGE = 7 |
17 | }; |
17 | }; |
18 | 18 | ||
19 | 19 | ||
20 | SIGNAL (SIG_OVERFLOW0) // 9,8kHz |
20 | SIGNAL (SIG_OVERFLOW0) // 9,8kHz |
21 | { |
21 | { |
22 | static unsigned char cnt_1ms = 1,cnt = 0; |
22 | static unsigned char cnt_1ms = 1,cnt = 0; |
23 | // TCNT0 -= 250;//TIMER_RELOAD_VALUE; |
23 | // TCNT0 -= 250;//TIMER_RELOAD_VALUE; |
24 | 24 | ||
25 | if(!cnt--) |
25 | if(!cnt--) |
26 | { |
26 | { |
27 | cnt = 10; |
27 | cnt = 10; |
28 | cnt_1ms++; |
28 | cnt_1ms++; |
29 | cnt_1ms %= 2; |
29 | cnt_1ms %= 2; |
30 | if(!cnt_1ms) UpdateMotor = 1; |
30 | if(!cnt_1ms) UpdateMotor = 1; |
31 | CountMilliseconds++; |
31 | CountMilliseconds++; |
32 | if(Timeout) Timeout--; |
32 | if(Timeout) Timeout--; |
33 | } |
33 | } |
34 | 34 | ||
35 | if(beeptime > 1) |
35 | if(beeptime > 1) |
36 | { |
36 | { |
37 | beeptime--; |
37 | beeptime--; |
38 | PORTD |= (1<<PD2); |
38 | PORTD |= (1<<PD2); |
39 | } |
39 | } |
40 | else |
40 | else |
41 | PORTD &= ~(1<<PD2); |
41 | PORTD &= ~(1<<PD2); |
42 | 42 | ||
43 | if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) timer0_MM3(); // Kompass auslesen |
43 | if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) timer0_MM3(); // Kompass auslesen |
44 | } |
44 | } |
45 | 45 | ||
46 | 46 | ||
47 | void Timer_Init(void) |
47 | void Timer_Init(void) |
48 | { |
48 | { |
49 | TCCR0B = CK8; |
49 | TCCR0B = CK8; |
50 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
50 | TCCR0A = (1<<COM0A1)|(1<<COM0B1)|3;//fast PWM |
51 | OCR0A = 0; |
51 | OCR0A = 0; |
52 | OCR0B = 120; |
52 | OCR0B = 120; |
53 | //TCNT0 = -TIMER_RELOAD_VALUE; // reload |
53 | //TCNT0 = -TIMER_RELOAD_VALUE; // reload |
54 | //OCR1 = 0x00; |
54 | //OCR1 = 0x00; |
55 | 55 | ||
56 | TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3; |
56 | TCCR2A=(1<<COM2A1)|(1<<COM2A0)|3; |
57 | TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22); |
57 | TCCR2B=(0<<CS20)|(1<<CS21)|(1<<CS22); |
58 | 58 | ||
59 | // TIMSK2 |= _BV(TOIE2); |
59 | // TIMSK2 |= _BV(TOIE2); |
60 | TIMSK2 |= _BV(OCIE2A); |
60 | TIMSK2 |= _BV(OCIE2A); |
61 | 61 | ||
62 | TIMSK0 |= _BV(TOIE0); |
62 | TIMSK0 |= _BV(TOIE0); |
63 | OCR2A = 10; |
63 | OCR2A = 10; |
64 | TCNT2 = 0; |
64 | TCNT2 = 0; |
65 | - | ||
66 | } |
65 | } |
67 | 66 | ||
68 | // ----------------------------------------------------------------------- |
67 | // ----------------------------------------------------------------------- |
69 | 68 | ||
70 | unsigned int SetDelay (unsigned int t) |
69 | unsigned int SetDelay (unsigned int t) |
71 | { |
70 | { |
72 | // TIMSK0 &= ~_BV(TOIE0); |
71 | // TIMSK0 &= ~_BV(TOIE0); |
73 | return(CountMilliseconds + t + 1); |
72 | return(CountMilliseconds + t + 1); |
74 | // TIMSK0 |= _BV(TOIE0); |
73 | // TIMSK0 |= _BV(TOIE0); |
75 | } |
74 | } |
76 | 75 | ||
77 | // ----------------------------------------------------------------------- |
76 | // ----------------------------------------------------------------------- |
78 | char CheckDelay(unsigned int t) |
77 | char CheckDelay(unsigned int t) |
79 | { |
78 | { |
80 | // TIMSK0 &= ~_BV(TOIE0); |
79 | // TIMSK0 &= ~_BV(TOIE0); |
81 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
80 | return(((t - CountMilliseconds) & 0x8000) >> 9); |
82 | // TIMSK0 |= _BV(TOIE0); |
81 | // TIMSK0 |= _BV(TOIE0); |
83 | } |
82 | } |
84 | 83 | ||
85 | // ----------------------------------------------------------------------- |
84 | // ----------------------------------------------------------------------- |
86 | void Delay_ms(unsigned int w) |
85 | void Delay_ms(unsigned int w) |
87 | { |
86 | { |
88 | unsigned int akt; |
87 | unsigned int akt; |
89 | akt = SetDelay(w); |
88 | akt = SetDelay(w); |
90 | while (!CheckDelay(akt)); |
89 | while (!CheckDelay(akt)); |
91 | } |
90 | } |
92 | 91 | ||
93 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
92 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
94 | // Servo ansteuern |
93 | // Servo ansteuern |
95 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
94 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
96 | SIGNAL(SIG_OUTPUT_COMPARE2A) |
95 | SIGNAL(SIG_OUTPUT_COMPARE2A) |
97 | { |
96 | { |
98 | static unsigned char timer = 10; |
97 | static unsigned char timer = 10; |
99 | 98 | ||
100 | if(!timer--) |
99 | if(!timer--) |
101 | { |
100 | { |
102 | TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3; |
101 | TCCR2A=(1<<COM2A1)|(0<<COM2A0)|3; |
103 | ServoValue = Parameter_ServoNickControl; |
102 | ServoValue = Parameter_ServoNickControl; |
104 | if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
103 | if(EE_Parameter.ServoNickCompInvert & 0x01) ServoValue += ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
105 | else ServoValue -= ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
104 | else ServoValue -= ((long) EE_Parameter.ServoNickComp * (IntegralNick / 128)) / 512; |
106 | 105 | ||
107 | if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin; |
106 | if(ServoValue < EE_Parameter.ServoNickMin) ServoValue = EE_Parameter.ServoNickMin; |
108 | else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax; |
107 | else if(ServoValue > EE_Parameter.ServoNickMax) ServoValue = EE_Parameter.ServoNickMax; |
109 | 108 | ||
110 | //DebugOut.Analog[10] = ServoValue; |
109 | //DebugOut.Analog[10] = ServoValue; |
111 | OCR2A = ServoValue;// + 75; |
110 | OCR2A = ServoValue;// + 75; |
112 | timer = EE_Parameter.ServoNickRefresh; |
111 | timer = EE_Parameter.ServoNickRefresh; |
113 | } |
112 | } |
114 | else |
113 | else |
115 | { |
114 | { |
116 | TCCR2A =3; |
115 | TCCR2A =3; |
117 | PORTD&=~0x80; |
116 | PORTD&=~0x80; |
118 | } |
117 | } |
119 | } |
118 | } |
120 | 119 |