23 votes
Accepted

What's the maximum time an interrupt service routine can take to execute on ATmega328P?

If nothing else is running in the MCU, then you are free to take as long as you like in the ISR. But, this is a bad habit to get into, and it means that if you want to do anything else, you'll likely ...
Neil_UK's user avatar
  • 166k
19 votes
Accepted

Seven-segment display seems to draw little current

First of all +1 for measuring your display. Too often we get questions here about "I saved money by buying cheap from Alibaba but it don't work. Now please spend you valuable time helping me out". ...
Oldfart's user avatar
  • 14.4k
18 votes
Accepted

Due to overcurrent, shouldn't I be extremely cautious when setting an I/O pin as Output?

As others have said, you shouldn't have a problem as long as you double check your code. If you do get it wrong, by and large the ATMega IO pins will limit themselves to about ~80mA due to internal ...
Tom Carpenter's user avatar
17 votes
Accepted

Is it safe to drive I/O pins of an unpowered AVR ATmega328P?

You may be interested in EEVBlog's video about powering an MCU without connecting the power pins. If you drive the I/O pins on the MCU, you may end up powering up the MCU through its protection diodes....
tangrs's user avatar
  • 1,039
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 ...
Oldfart's user avatar
  • 14.4k
14 votes
Accepted

How does USART know which port to use for IO?

The ATMega328P has only one hardware USART, hence you don't have to tell it anything. The USART is connected to PD0 (RXD) and PD1 (TXD) and you can't change it. If you want to do serial on another ...
jonathanjo's user avatar
12 votes

Is the ATMEGA328P's serial baud rate quantised?

It is a fully digital system. It must operate in discrete steps. This is the formula from the datasheet: UBRR register is 16 bits wide (UBRRL + UBRRH), so it can only lead to 65536 possible baud ...
filo's user avatar
  • 8,951
11 votes
Accepted

Atmega328P - How is brown-out-detection supposed to work?

The brown out detector will put the chip into reset mode if the voltage on the Vcc pin drops below the threshold. When in reset, all GPIO pins go into high impedance mode and no code executes. When ...
bigjosh's user avatar
  • 10.1k
11 votes

What's the maximum time an interrupt service routine can take to execute on ATmega328P?

In the worst case, an ISR can run until the next interrupt of the same type occurs again. But in general, it's poor design practice to spend more time in an ISR than absolutely necessary, because it ...
Dave Tweed's user avatar
  • 173k
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 ...
Michel Keijzers's user avatar
11 votes

Due to overcurrent, shouldn't I be extremely cautious when setting an I/O pin as Output?

You should be cautious but not terrified about it. Setting a pin output and driving it to the other direction will cause a lot of current to flow, but it also does not blow up in smoke immediately. ...
Justme's user avatar
  • 149k
9 votes

Due to overcurrent, shouldn't I be extremely cautious when setting an I/O pin as Output?

Considering this type of circuit is avidly encouraged, how it doesn't seem to bring any troubles? Because when engineers set up the I/O for their device, they are careful to ensure that they do not ...
Graham's user avatar
  • 6,150
9 votes
Accepted

Possible to buy Atmega328p with programmed Flash and EEPROM?

In my experience, this has only economical for gigantic production runs; the cost of this value-add service can be high (I've been quoted a multiple of the price of each controller.) Consider the cost ...
Adam Lawrence's user avatar
8 votes

Timer 1 (16 bit): Why is overflow interrupt sometimes missed?

The problem is that you are not eliminating the actual issue with the ATOMIC statement- the counter is incrementing in hardware and there will be times when an interrupt is pending but not completed. ...
Spehro Pefhany's user avatar
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 ...
Michael Karas's 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 ...
Graham's user avatar
  • 6,150
8 votes
Accepted

What is the '0x04' next to 'DDRB' in the ATmega328 datasheet?

For the lower 64 IO registers, there are two addresses. The first (0x04 in this example) is used for access using certain I/O instructions such as out (write to IO ...
Tom Carpenter's user avatar
8 votes
Accepted

I'm trying to create a clock. Rate my first schematic design

The digit power circuit will not work as drawn. You need to flip the transistors around and reduce the base resistor values by a factor of ~20. Edit: since you're multiplexing, the power and thermal ...
vir's user avatar
  • 18.4k
7 votes
Accepted

Is power cycle reset different from reset pin reset?

Is power cycle reset different as compared to reset pin reset? Yes. There are some semiconductor behaviours where only loss of power will allow previous behaviour to resume. An SCR is a type of ...
SamGibson's user avatar
  • 17.9k
7 votes
Accepted

is a voltage regulator required for atmega328p when powering from boost converter at a set voltage?

is a voltage regulator required for atmega328p when powering from boost converter at a set voltage? No it is not. The ATMega is "just" some logic circuits in a chip. So is the CPU in your PC and in ...
Bimpelrekkie's user avatar
  • 80.8k
7 votes
Accepted

Is the ATMEGA328P's serial baud rate quantised?

As already mentioned, this quantization is fundamental to the architecture, which can only divide the source clock by an integer. However, your problem is quite avoidable. The ATmega UART can ...
Chris Stratton's user avatar
7 votes
Accepted

LED- Resistor, does the position matter?

No, it does not matter. There are several cases: The LED works: in this case the resistor will limit the current flow, and does not matter if it is before or after, since it is connected serial. The ...
Michel Keijzers's user avatar
7 votes

7-segment 4-digit display ghosting

You are turning two digits on at once by writing the 'or' first and then the &. The new one will have the segment drive for the old one on for a short period of time- enough to create perceptible ...
Spehro Pefhany's user avatar
6 votes

Why there are 7 pins in I/O PORT C of Atmega328P as against 8 pins normally?

There are no more leads on the package. If you look at the die of the ATmega328p (on wikipedia) you will see 32 wire bonding points. But there are less leads on the package, choices have been made, ...
Jeroen3's user avatar
  • 23k
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 ...
filo's user avatar
  • 8,951
6 votes

Detecting a break condition over UART on ATmega328P

You don't have to configure anything. If there is a too long low pulse on receive wire, so that the stop bit is not idle, you get a framing error flag in the status register for the received byte. So ...
Justme's user avatar
  • 149k
6 votes
Accepted

Need help to understand an Arduino Capacitance-Meter program

The unknown capacitor forms a capacitive voltage divider together with the stray capacitance of the leads and input pin. When the output pin of the Arduino goes from 0V to 5V, this voltage divider ...
Klas-Kenny's user avatar
  • 4,837
5 votes
Accepted

27 pin Arduino Microcontroller

On the pcb I have, i see only 27 pins for the microcontroller This is very hard to believe, unless some idiot designed the board. Even if only 27 pins are actually used in a circuit, any competent ...
Olin Lathrop's user avatar
5 votes

Is it safe to drive I/O pins of an unpowered AVR ATmega328P?

No. At the input of most pins on a device such as the AVR ATmega328 there are diodes to protect the chip from electrostatic discharge (ESD). These diodes connect to the supply rail of the device. If ...
Kevin White's user avatar
  • 33.2k

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