21
votes
Accepted
Avr-gcc using repeated addition instead of MULU instructions
Assuming that you want to optimize for speed:
Unless you really find out how many cycles it takes if you use mul, you can't compare.
So let’s try:
If you use the <...
18
votes
Accepted
Why doesn't the compiler use directly LSR
According to C language specification any value whose size is less than the size of int (depends on the particular compiler; in your case ...
15
votes
Compress .hex file for micro-controller
You can not compress the hex code, you can only try to reduce it.
Try different? compiler settings (maximum optimization and optimize for size)
Pick your way through the source code and see what can ...
13
votes
Why GCC compiler omitting some code?
You could try making the loop actually do something. As it stands the compiler is quite rightly saying "This loop is doing nothing - I'll get rid of it".
So you could try a construct I use ...
11
votes
Compress .hex file for micro-controller
The MCU cannot execute compressed code.
However, there are some things you can do:
Instead of using full fledged library functions, create some or all of the functions yourself; this way you can ...
10
votes
Convert the type of calculation result in if() to uint8_t
rxWritePos is already uint8_t so obviously the cast (uint8_t)rxWritePos is nonsense - you ...
9
votes
Accepted
Why GCC compiler omitting some code?
Since in one comment you state that "each CPU tick is worthy" I suggest using some inline assembly to make your delays loop just as you want. This solution is superior to the various ...
9
votes
Accepted
Convert the type of calculation result in if() to uint8_t
You need parentheses around the whole expression: (uint8_t)(rxWritePos-1).
If rxWritePos = 0:
...
8
votes
Compress .hex file for micro-controller
In addition to the excellent suggestions provided in the other answers here I want to comment that there can be a huge difference in how much compilers (and linkers) can optimize code.
I worked at a ...
8
votes
Compress .hex file for micro-controller
The first step for any kind of optimisation is find out what's doing it.
Your first move should be to get the linker to dump the address of every identifier in the build. That's all functions and all ...
7
votes
Interrupt Management - Large AVR Projects
The first rule of using interrupts: Keep them very short.
When an interrupt occurs, whether it is enabled or not, and whether it is currently servicing an interrupt or not, an Interrupt Fired flag ...
7
votes
Accepted
Receiving a whole string from USART on ATMEGA16?
Straight off I see two issues - one sneaky, and one which shows a bit of a lack of understanding.
The sneaky one is this line:
char REC;
REC is used within your ...
7
votes
Avr-gcc does not compile correctly without optimizations, but works (badly) with -Os
You'll need to inspect the output of avr-objdump to see what exact instructions were generated for your code. Incidentally, it would be helpful to include your C ...
7
votes
Accepted
6
votes
Why GCC compiler omitting some code?
Yes you could assume that. If you declare variable i as volatile you tell the compiler not to optimise on i.
6
votes
avr-gcc keypad interfacing code problem
Here is your code with the comments that it should have had all along added in, plus tables showing exactly what the shift operations are doing (the latter shouldn't be necessary for any experienced C ...
6
votes
Compress .hex file for micro-controller
There is no "practical" way to run compressed code on an AVR so your problem becomes "how do I optimize the size of my firmware".
Toolchain tricks (ie. you don't have to modify your code):
What is ...
5
votes
Accepted
How can I bind a local variable to AVR's rXX register?
Don't declare your variable as volatile. That pretty much forces the compiler to use a memory location, and to access it on every loop iteration. Use ...
5
votes
How can I bind a local variable to AVR's rXX register?
The conventional way to achieve what you want is to hand code the delay subroutine in the native assembly language. Almost all development tool sets that are C compilers will have the capability to ...
5
votes
Accepted
UART with PC : Reciving absurd characters in PC
Your baud rate divisor seems to select a baud rate of 19200 instead of 9600:
baud = (clock speed) / ( 16 * (UBRR + 1) )
Try to set ...
5
votes
i'm using atmega32 to do an automatic railway gate project i wrote the code ,but i have a problem with it that it doesn't give me the required output?
when i burn it on the kit it doesn't work .
what is the wrong with this code ??
Who knows? Could be anything. You haven't told us how you know it doesn't work. But that is not relevant, I will tell ...
5
votes
Push button counting
You need to be aware that as written your code will spin around the while loop dozens if not 100's of times seeing the one or the other of the switches pressed. Since your IF statement only checks for ...
5
votes
Accepted
Atmega328p ADC - value keeps returning zero when connected
The DS18x20 series are digital thermometers using the One-Wire protocol on their data pin. Look up any of the Dallas/Maxim DS18b20 libraries to use this one.
If, on the other had, you want an analog ...
4
votes
Accepted
ISR, volatile and ATOMIC_BLOCK
Non-AVR-specific answer:
Jumping into an ISR from a normal execution thread generally requires a context switch, where the current state of the CPU is saved somewhere (stack, shadow registers) so ...
4
votes
Accepted
ATmega128 Extended I/O
That AVR instruction set can support a maximum of 64 I/O locations. Why is that? Does the AVR instruction set take in 6 bits for an I/O location?
Most AVR instructions put their arguments as part of ...
4
votes
Accepted
AVR USART Random Behaviour
It is a good habit to flush serial input buffer on your PC before starting to use it to ensure sender and receiver are synchronized. One useful trick is not to send your raw data, but encapsulate it ...
4
votes
Accepted
Difference and compatibility between AVR xxxA and xxx/xxxV series
The ATtiny13 is the original version and uses a different process technology than the ATtiny13A. The A-suffixed parts are fabricated with a low power process marketed as "picoPower", and the main ...
4
votes
What is STM8 hardware and software interrupt latency?
The STM8 takes 9 clock cycles to go to the ISR. And takes 9 clock cycles to return.
Reference: STM8 programming manual (Doc No. PM0044) pg. 14.
4
votes
avr-gcc float macro error
I got it!
As Dave Tweed suggested in a comment, the issue was not the declaration itself but the way I was using that macro. In other lines I was doing this:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
avr-gcc × 118avr × 90
atmega × 30
c × 24
microcontroller × 21
interrupts × 10
avrdude × 10
attiny × 8
atmega328p × 8
uart × 7
arduino × 6
compiler × 6
spi × 5
atmel × 5
gcc × 5
led × 4
assembly × 4
atmel-studio × 4
assembler × 4
pwm × 3
serial × 3
adc × 2
embedded × 2
lcd × 2
programming × 2