Hallo Leute,
ich bin gerade dabei ein Programm zu schreiben welches das Taktsignal
für einen Schrittmotor alla Atmel Application Note AVR446 erzeugt. Ich
verwende also den 16bit timer eines AVR (attiny2313).
Der Wert des Output Compare Registers des Timers wird in der ISR
berechnet und gesetzt. dazu benötige ich einige Variablen aus der
Berechnung des vorangegangenen Timer Interrupts. Daher hab ich jetzt
globale Variablen für diese Werte (Datentyp = uint16_t) angelegt. Wenn
ich dies variablen jetzt aber volatile mache explodiert mein Program-
und Data-Speicher.
ohne volatile:
1 | AVR Memory Usage
|
2 | ----------------
|
3 | Device: attiny2313
|
4 |
|
5 | Program: 1494 bytes (72.9% Full)
|
6 | (.text + .data + .bootloader)
|
7 |
|
8 | Data: 97 bytes (75.8% Full)
|
9 | (.data + .bss + .noinit)
|
EINE variable als volatile
1 | AVR Memory Usage
|
2 | ----------------
|
3 | Device: attiny2313
|
4 |
|
5 | Program: 4862 bytes (237.4% Full)
|
6 | (.text + .data + .bootloader)
|
7 |
|
8 | Data: 361 bytes (282.0% Full)
|
9 | (.data + .bss + .noinit)
|
Zum einen kann ich nicht ganz nachvollziehen weshalb eine uint8_t
Variable plötzlich so viel speicher verbraucht. Kann mir das evtl.
jemand erklähren?
Zum zweiten möchte ich natürlich gerne wissen ob man das irgendwie
optimieren kann.
PS: hier noch die betrefende Codestelle:
1 | //================================================================= globals ===
|
2 | uint16_t accelerationStop; //volatile uint16_t accelerationStop;
|
3 | uint16_t decelerationStart;
|
4 | uint16_t goal;
|
5 | uint16_t currentStep; //volatile uint16_t currentStep;
|
6 | uint16_t counterValue; //volatile uint16_t counterValue;
|
7 | uint8_t refreshCounterValue; //volatile uint8_t refreshCounterValue;
|
8 | uint8_t busy; //volatile uint8_t busy;
|
9 |
|
10 | //===================================================================== isr ===
|
11 | ISR(TIMER1_COMPA_vect) {
|
12 |
|
13 | if (refreshCounterValue) {
|
14 | if (currentStep <= accelerationStop) { //acceleration mode
|
15 | counterValue = counterValue - ((2 * counterValue) / (4 * (currentStep + 1) + 1));
|
16 | counterValue = counterValue / 2;
|
17 | } else if ((currentStep) >= decelerationStart) { //deceleration mode
|
18 | accelerationStop++;
|
19 | counterValue = ((4 * accelerationStop * counterValue + counterValue) / (4 * accelerationStop - 1));
|
20 | counterValue = counterValue / 2;
|
21 | accelerationStop -= 2;
|
22 | }
|
23 |
|
24 | OCR1AH = (uint8_t) (counterValue >> 8);
|
25 | OCR1AL = (uint8_t) (counterValue & 0xFF);
|
26 |
|
27 | currentStep++;
|
28 | if (currentStep >= goal) {
|
29 | TIMSK &= ~(1 << OCIE1A);
|
30 | busy = 0;
|
31 | }
|
32 | refreshCounterValue = 0;
|
33 | PORTB &= ~(1 << PB3);
|
34 | } else {
|
35 | refreshCounterValue = 1;
|
36 | PORTB |= (1 << PB3);
|
37 | }
|
38 | }
|