Hot answers tagged

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 <...
user avatar
  • 15.8k
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 ...
user avatar
  • 15.8k
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 ...
user avatar
  • 14.1k
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 ...
user avatar
  • 55.5k
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 ...
user avatar
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 ...
user avatar
  • 14.3k
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 ...
user avatar
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: ...
user avatar
  • 3,094
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 ...
user avatar
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 ...
user avatar
  • 5,759
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 ...
user avatar
  • 55.5k
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 ...
user avatar
  • 55.5k
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 ...
user avatar
7 votes
Accepted

avr-gcc keypad interfacing code problem

In an abstract manner the code does this: ...
user avatar
  • 1,412
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.
user avatar
  • 1,671
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 ...
user avatar
  • 165k
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 ...
user avatar
  • 8,436
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 ...
user avatar
  • 165k
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 12.8k
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 ...
user avatar
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 ...
user avatar
  • 3,132
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 32.6k
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 ...
user avatar
  • 8,374
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.
user avatar
  • 41
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: ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible