Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-15 Thread Joerg Wunsch
Keith Gudger <[EMAIL PROTECTED]> wrote: > Now your main routine may have an old value > for that variable. Even with volatile, if the interrupt had happened a few clocks later, you'd read the old value as well. -- cheers, J"org .-.-. --... ...-- -.. . DL8DTL http://www.sax.

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-15 Thread Chip Webb
When the volatile attribute is used on a global variable, the compiler will not optimize away accesses to that variable. If you are using a global variable to communicate between an ISR and a "main" routine, you probably need to use the volatile keyword in the variable declaration in order t

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-15 Thread Keith Gudger
Excuse me if I'm wrong, but the following statement: >If the main > function has interrupts turned off (either globally, or the specific ISR > interrupt enable), then it can happily use a non-volatile variable > shared with the ISR. I think may cause trouble. When the compiler optimizes your code

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-15 Thread David Brown
- Original Message - From: "Lars Noschinski" <[EMAIL PROTECTED]> > * Lars Noschinski <[EMAIL PROTECTED]> [2005-09-06 21:59]: > >You must declare the global variable as volatile (or as register), if > >you want to modify in an ISR. Wrong - that's neither necessary nor complete (there is

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-14 Thread Rich Neswold
Wasn't it 14-Sep-2005, at 07:05PM, when Lars Noschinski said: > Speaking of this, if I have an variable which is initialized during > startup and only accessed /in/ an ISR, am I on the safe side, if don't > declare it as volatile, right? Yes. -- Rich Nes

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-14 Thread Lars Noschinski
* Lars Noschinski <[EMAIL PROTECTED]> [2005-09-06 21:59]: You must declare the global variable as volatile (or as register), if you want to modify in an ISR. Speaking of this, if I have an variable which is initialized during startup and only accessed /in/ an ISR, am I on the safe side, if don'

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-08 Thread David Brown
- Original Message - From: "Vincent Trouilliez" <[EMAIL PROTECTED]> > > There's for sure a lot of potential for improvement, but declaring > > something "top-priority" because that's your opinion won't do > > anything. There are many similar minor improvements that could be > > made, th

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-08 Thread E. Weddington
David Brown wrote: I think most or all of the avr-gcc team follow this list. They are always interested in ideas leading to a better compiler, but it is up to *them* what is "top-priority". Right, and that's because it's a volunteer project and there is a limited amount of time. Currently

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-08 Thread David Brown
- Original Message - From: "Vincent Trouilliez" <[EMAIL PROTECTED]> > On Wed, 2005-09-07 at 16:41 +0200, Joerg Wunsch wrote: > > "David Brown" <[EMAIL PROTECTED]> wrote: > > > > > ..., and it will also change "multiply by constant" into a series of > > > shifts and adds. The target chip

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Vincent Trouilliez
> There's for sure a lot of potential for improvement, but declaring > something "top-priority" because that's your opinion won't do > anything. There are many similar minor improvements that could be > made, they probably sum up to maybe 10...20 % of possible savings if > really *all* of them wer

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Joerg Wunsch
Vincent Trouilliez <[EMAIL PROTECTED]> wrote: > Can't we just have an command line option to force the use of the > H/W multiplier ? Nope, because it doesn't make sense. It needs to be fixed, OK, but it doesn't make the slightest sense to start hacking up command-line option workarounds for not

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread ericw
Quoting Galen Seitz <[EMAIL PROTECTED]>: > Because I wanted more control over multiplies, I've started creating > routines like these: > > > extern inline uint16_t > mult_u16_u8u8(uint8_t a, uint8_t b) > { > uint16_t product; > asm ( > "mul %1, %2""\n\t" > "movw %0, r0"

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Galen Seitz
Joerg Wunsch <[EMAIL PROTECTED]> wrote: > "David Brown" <[EMAIL PROTECTED]> wrote: > > > ..., and it will also change "multiply by constant" into a series of > > shifts and adds. The target chip has a hardware multiplier and > > divider, but they are slower than the shift-and-add sequences. > >

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Vincent Trouilliez
On Wed, 2005-09-07 at 16:41 +0200, Joerg Wunsch wrote: > "David Brown" <[EMAIL PROTECTED]> wrote: > > > ..., and it will also change "multiply by constant" into a series of > > shifts and adds. The target chip has a hardware multiplier and > > divider, but they are slower than the shift-and-add s

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Joerg Wunsch
"David Brown" <[EMAIL PROTECTED]> wrote: > ..., and it will also change "multiply by constant" into a series of > shifts and adds. The target chip has a hardware multiplier and > divider, but they are slower than the shift-and-add sequences. Unfortunately, AVR-GCC also does this, even though the

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread David Brown
> > For such things it is interessting to use fixed point math. > > If you want to divide 200 data Bytes by 13 you can do > > > > fac = 256 / 13; (* Only one div needed *) > > for i := 0 to 199 do > >data[i] = data[i] shl 8 * fac; > > > > and you need only 1 div and man muls. > > > > For da

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Vincent Trouilliez
> For such things it is interessting to use fixed point math. > If you want to divide 200 data Bytes by 13 you can do > > fac = 256 / 13; (* Only one div needed *) > for i := 0 to 199 do >data[i] = data[i] shl 8 * fac; > > and you need only 1 div and man muls. > > For data-filters you norm

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Vincent Trouilliez
On Wed, 2005-09-07 at 13:46 +0200, Joerg Wunsch wrote: > Vincent Trouilliez <[EMAIL PROTECTED]> wrote: > > > all I did was gather all the commands found in your avr-libc PWM > > demo project, put them all in a bash script like this : > > If you use the Makefile that comes with the demo, you can

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Joerg Wunsch
Vincent Trouilliez <[EMAIL PROTECTED]> wrote: > all I did was gather all the commands found in your avr-libc PWM > demo project, put them all in a bash script like this : If you use the Makefile that comes with the demo, you can say "make demo.s" to see the compiler-generated assembly file. It h

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Alex Wenger
Hello, Vincent Trouilliez schrieb: > Talking of instruction, I just noticed that there is a MUL instruction > in my ATmega32 but no DIV instruction ! How is that even possible... > even age old 8051 has a division instruction... so we can do quick > multiplications with the AVR, but need 50 times

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread David Brown
> > Talking of instruction, I just noticed that there is a MUL instruction > in my ATmega32 but no DIV instruction ! How is that even possible... > even age old 8051 has a division instruction... so we can do quick > multiplications with the AVR, but need 50 times more cycles to do a > division ??

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Vincent Trouilliez
On Wed, 2005-09-07 at 11:54 +0200, Joerg Wunsch wrote: > > Oh, that's interesting... because as soon as I compile my small > > programs, I rush to check to have a look at the assembler output, > > ... > > At the assembler output (filename.s), or at the disassembler output > (filename.lss)? I gues

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Vincent Trouilliez
> ...Similarly, "CLR rx" is just "EOR rx, rx". Oh yes, forgot to mention this one but I did notice it as well in my programs ! Thanks for clearing this one too :-) -- Vince ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Vincent Trouilliez
> I guess, it's easier for the compiler to do things in a consistent way. Yes I guess so too.. I didn't mean to complain about the looks of the assembler output... after all if you use a compiler it's because you don't want to write your own assembler to start with, so you can't possibly complain

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread David Brown
> > generated with basic -O optomisation is far easier to read and understand than code > > generated with -O0, since it keeps variables in registers instead of the > > stack. > > Oh, that's interesting... because as soon as I compile my small > programs, I rush to check to have a look at the asse

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Joerg Wunsch
Vincent Trouilliez <[EMAIL PROTECTED]> wrote: > Oh, that's interesting... because as soon as I compile my small > programs, I rush to check to have a look at the assembler output, > ... At the assembler output (filename.s), or at the disassembler output (filename.lss)? I guess it's the latter.

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Lars Noschinski
* Vincent Trouilliez <[EMAIL PROTECTED]> [2005-09-07 11:32]: Oh, that's interesting... because as soon as I compile my small programs, I rush to check to have a look at the assembler output, to get the hang of things, and am often very confused by the way the compile does things, it's often very

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Vincent Trouilliez
> There is a problem in your code also - you are not making > flag=0 after you send back the character. HTH. > > Nayani Hi Nayani, no it's not a problem at all, it only means that it would react only once, which was all I wanted/needed it to do in order to prove that ISR to main communication was

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread Vincent Trouilliez
> generated with basic -O optomisation is far easier to read and understand > than code > generated with -O0, since it keeps variables in registers instead of the > stack. Oh, that's interesting... because as soon as I compile my small programs, I rush to check to have a look at the assembler out

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-07 Thread David Brown
> Hello Vincent, > > To be able to modify/access a variable in interrupt, > declare it as "volatile". That's not good advice - there is no reason to use "volatile" on all variables used by interrupt routines. That would lead to unnecessarily slower code. All you need to do is remember what "vol

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-06 Thread Parthasaradhi Nayani
Hello Vincent, To be able to modify/access a variable in interrupt, declare it as "volatile". Secondly, to test your code, turn off optimization (s=0) in your make file. There is a problem in your code also - you are not making flag=0 after you send back the character. HTH. Nayani --- Vincent T

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-06 Thread Johnathan Corgan
Vincent Trouilliez wrote: > unsigned char flag, bin; //global variables Try making 'flag' volatile: volatile unsigned char flag; unsigned char bin; What's probably happening is the compiler, not seeing that 'flag' is modified anywhere in the while loop, isn't reloading it every loop iteration

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-06 Thread Vincent Trouilliez
> Try making 'flag' volatile: Thanks chaps, that did it :-) > What's probably happening is the compiler, not seeing that 'flag' is > modified anywhere in the while loop, isn't reloading it every loop > iteration Must be that, 'cause I looked at the assembler output closely enough to see that t

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-06 Thread Christopher X. Candreva
On Tue, 6 Sep 2005, Vincent Trouilliez wrote: > Problem : on my ATmega32, after several experiments (only just started > using it, learning...), I am suffering a big problem. It seems that when > I declare a variable as global, then modify it within an interrupt > routine, the 'main' function can'

Re: [avr-gcc-list] Global variables and ISRs ???

2005-09-06 Thread Lars Noschinski
* Vincent Trouilliez <[EMAIL PROTECTED]> [2005-09-06 21:37]: Problem : on my ATmega32, after several experiments (only just started using it, learning...), I am suffering a big problem. It seems that when I declare a variable as global, then modify it within an interrupt routine, the 'main' funct

[avr-gcc-list] Global variables and ISRs ???

2005-09-06 Thread Vincent Trouilliez
Hi gents, After the highly technical thread that just ended today, I would like to pick your brains on something much lower flying so to speak, sorry for that ! ;-) Problem : on my ATmega32, after several experiments (only just started using it, learning...), I am suffering a big problem. It se