Hi All,
when I'm coding interrupts routines , I have the habit to save the Special Register and restore it when exiting the interrupt.
I'm not very confident with Atmel (I use rather PIC) and i'm surprised that this is not used except in RX.pde (readRawRC()).
I added the "uint8_t oldSREG = SREG ... SREG = oldSREG" to all the ISR's of the software but can't try due to the bad weather actually (I don't fly indoor).
By the way, I'm flying Multiwii since 1.6 thru 1.8P2 with a tricopter.
It is flying very well and is more reactive than a KK (Thanks Alex and all contributors) , BUT , I always have problems with flips and sometimes crashes due to the ACC drifts (NK or BMA180). I have always +/- non recoverable drifts with the sticks after about 1-2 minutes and only switching off the ACC saves the copter.
I tried the LEVEL_PDF which seems to be more quiet but not a lot of experience on it ( 3 flights).
FCWii board Atmel 328
WM+ genuine
NK genuine or BMA180
Regards
flyman777
BUG? - Save SREG ??
-
- Posts: 2261
- Joined: Sat Feb 19, 2011 8:30 pm
Re: BUG? - Save SREG ??
Please, can you post the code segment where you have added this modification? I also am having a very random weird behavior that I can not seem to debug on an Arudunio Mega 1280.
Thank you.
Thank you.
Re: BUG? - Save SREG ??
Hi copterrichie,
thank you for reply.
I added in def.h:
#define Save_SREG uint8_t oldSREG = SREG;
#define Restore_SREG SREG = oldSREG;
in Output.pde:
ISR(TIMER0_COMPA_vect) {
static uint8_t state = 0;
static uint8_t count;
Save_SREG
......
OCR0A+= 250;
}
Restore_SREG
}
#endif
in RX.pde:
#if !defined(SERIAL_SUM_PPM) && !defined(SPEKTRUM)
ISR(PCINT2_vect) { //this ISR is common to every receiver channel, it is call everytime a change state occurs on a digital pin [D2-D7]
uint8_t mask;
uint8_t pin;
uint16_t cTime,dTime;
static uint16_t edgeTime[8];
static uint8_t PCintLast;
Save_SREG
..........
#if defined(FAILSAFE)
if (mask & 1<<THROTTLEPIN) { // If pulse present on THROTTLE pin (independent from ardu version), clear FailSafe counter - added by MIS
if(failsafeCnt > 20) failsafeCnt -= 20; else failsafeCnt = 0; }
#endif
Restore_SREG
}
#endif
in Serial.pde:
ISR_UART {
Save_SREG
UDR0 = s[tx_ptr++]; /* Transmit next byte */
if ( tx_ptr == point ) { /* Check if all data is transmitted */
UCSR0B &= ~(1<<UDRIE0); /* Disable transmitter UDRE interrupt */
tx_busy = 0;
}
Restore_SREG
}
As i said before, I can't try this yet because no free time and/or too bad weather.
I think that this random behavior of ACC must be settled before more and more improvements of the MultiWii software.
All my bests
flyman777
thank you for reply.
I added in def.h:
#define Save_SREG uint8_t oldSREG = SREG;
#define Restore_SREG SREG = oldSREG;
in Output.pde:
ISR(TIMER0_COMPA_vect) {
static uint8_t state = 0;
static uint8_t count;
Save_SREG
......
OCR0A+= 250;
}
Restore_SREG
}
#endif
in RX.pde:
#if !defined(SERIAL_SUM_PPM) && !defined(SPEKTRUM)
ISR(PCINT2_vect) { //this ISR is common to every receiver channel, it is call everytime a change state occurs on a digital pin [D2-D7]
uint8_t mask;
uint8_t pin;
uint16_t cTime,dTime;
static uint16_t edgeTime[8];
static uint8_t PCintLast;
Save_SREG
..........
#if defined(FAILSAFE)
if (mask & 1<<THROTTLEPIN) { // If pulse present on THROTTLE pin (independent from ardu version), clear FailSafe counter - added by MIS
if(failsafeCnt > 20) failsafeCnt -= 20; else failsafeCnt = 0; }
#endif
Restore_SREG
}
#endif
in Serial.pde:
ISR_UART {
Save_SREG
UDR0 = s[tx_ptr++]; /* Transmit next byte */
if ( tx_ptr == point ) { /* Check if all data is transmitted */
UCSR0B &= ~(1<<UDRIE0); /* Disable transmitter UDRE interrupt */
tx_busy = 0;
}
Restore_SREG
}
As i said before, I can't try this yet because no free time and/or too bad weather.
I think that this random behavior of ACC must be settled before more and more improvements of the MultiWii software.
All my bests
flyman777
Re: BUG? - Save SREG ??
I think the status register SREG is save automatically by the compiler. In my listing for the rx interrupt, there are the following lines:
0x3f = SREG
cu
quax
Code: Select all
ISR (USART_RX_vect)
5fc: 1f 92 push r1
5fe: 0f 92 push r0
600: 0f b6 in r0, 0x3f ; 63
602: 0f 92 push r0
......
63c: 0f 90 pop r0
63e: 0f be out 0x3f, r0 ; 63
640: 0f 90 pop r0
642: 1f 90 pop r1
644: 18 95 reti
0x3f = SREG
cu
quax
-
- Posts: 2261
- Joined: Sat Feb 19, 2011 8:30 pm
Re: BUG? - Save SREG ??
Quax, what about the other ISR's? I believe there are three or four.
P.S. Is this true for all versions of IDE?
P.S. Is this true for all versions of IDE?
Re: BUG? - Save SREG ??
Quax is correct, By default all ISR hadlers restore SREG (as well as any other register that's modified in the interrupt hanler).
Except... If you specify option ISR_NAKED the handler will not produce any prolog or epilog and you need to take care of all the details yourself.
More details here.
Except... If you specify option ISR_NAKED the handler will not produce any prolog or epilog and you need to take care of all the details yourself.
More details here.
-
- Posts: 2261
- Joined: Sat Feb 19, 2011 8:30 pm
Re: BUG? - Save SREG ??
Thank you and back to the drawing board for me.
Re: BUG? - Save SREG ??
Hi itain,
thanks for the tip, all is clear for me . It was a trial and I am not confident with AVR compiler (use only Arduino022) .
Will try now the last dev.
cheers
flyman777
thanks for the tip, all is clear for me . It was a trial and I am not confident with AVR compiler (use only Arduino022) .
Will try now the last dev.
cheers
flyman777