# Tag Info

## Hot answers tagged atmega328p

23

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 have to rework the code. A particular case is if the MCU is using a serial library, that expects interrupts to be working often enough to service individual ...

18

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 resistance of the MOSFETs (value found by experiment). This is not good for the chip, but as long as you don't leave it in this condition for an extended period,...

15

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 be optimized or omitted. See if any unnecessary library code is pulled in. (It should not be, but who knows) Good point from Jeroen3: Check if you need/have ...

11

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 prevents all other code from running at all. This is a big issue for anything other than trivial programs.

11

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 optimize library functions that mostly are (too) flexible for your specific need. Remove duplicated code in your own code. Use parameters for almost duplicated ...

11

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. You could for example power the device with current limited labotatory supply when bringing up a design so these kind of errors cause even less damage. I'd be ...

9

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 drive inputs as outputs. For most I/O, we will set pins as either inputs or outputs at startup and never change them later. This gives us only one line of code ...

8

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 variables. Your linker should also be able to report the sizes of functions; it probably won't do variable sizes, but you can infer those from the address of ...

8

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 company some years back where the product was using the ATMega8. When I arrived on the scene this product had three different source code builds to provide ...

6

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 the compiler optimization level? In gcc the option to optimize for minimum size is called -Os There is a facility called link time optimization that can further ...

5

A few things that I noticed right off the bat: As mentioned by JimmyB in the comments, you should not be connecting the crystal pins of the ATMEGA to the OSC1/OSC2 pins of the MCP2515. (See page 4) Your MCP2515 symbol does not have power or ground pins Your AVR chip has no decoupling capacitors You have a 22pF capacitor going from Aref to ground on your ...

5

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 thermo-sensor, try the LM34/LM35 series of analog sensors (Fahrenheit/Celsius, respectively) which put voltage, proportional to temperature, on their data pin.

4

can I use port A as digital output pins without ruining the microcontroller? Yes you can. Below table describes about Sink and source capabilities: VOH is when you try to output a high signal. The current should be less than a particular value which you can find in the same table. VOL is when you output a logic zero. Microcontroller can sink current and ...

4

Depends on what that pin is for. It may be required to link two grounds in the silicon, in which case it would cause an issue. You say it is linked, so it shouldn't be that bad. But ground pins are used for two other reasons. Thermal: a ground pin gives a nice thermal link to a large copper plane which can be used to suck heat out of the IC and stop it over ...

4

If you are looking for ways to reduce the size of your program code - besides having the optimizing compiler & linker chopping away some, and not using standard library functions, as others have noted, it also depends on the composition of program code how big it will be. first, try to find a way to show you what parts of your program is most offending ...

4

If I use this 3.7V battery, will this work well? The actual voltage of the battery will decrease from 4.2 V to 3.3 V, as the battery slowly goes from fully charged to fully discharged. The atmega328 accepts between 1.8 and 5.5 V power, so it will work under the full range of voltage from the battery without voltage regulation. Note however that the full 1....

4

Can confirm, on an arduino uno, 328p chip, if you connect a driven output to ground or VDD, it will kill that pin. I have accidentally done it several times in my early days with electronics. On other chips I work with, I'm pretty careful not to do this but more modern ones do seem less susceptible to this failure mode. For example, I accidentally set up a ...

3

While the practice is to allocate the minimum possible execution cycles inside an interruption, and beside other general hardware specifications, there are not technical limitations for increasing them, if there are not any other interruption to be executed. At attachInterrupt() Arduino Reference: Generally, an ISR should be as short and fast as possible....

3

Every micro-controller has a data sheet that mentions 'Electrical Characteristics'. As per Atmega 328 data sheet, Vcc can be of range $2.7 - 5.5V$

3

Is there a good way to solve this with virtually no overhead? There is no practical way to get 'virtually no overhead' in C on AVR. Code that looks like it should have low overhead often doesn't, and you have to look at the disassembly to see the real code. AVR has a RISC architecture that needs many instructions to do 'simple' operations. IN, OUT, and SBI/...

3

I noticed is a "jerk" to 7805 did it Any interruption in the 7805's ground connection would result in the 12v input being applied to the downstream circuitry, resulting in immediate damage. You really need to arrange things such that a "jerk to the 7805" is not possible, ie, solder the connection or use a good connector in a way that it is not under ...

2

Technically, it's not forbidden to even start an infinite loop inside an interrupt, so there is no top limit on ISR execution time. However, interrupts are most useful when you want to, well, interrupt your normal program flow to take a short action which must be carried out immediately, and the qualifiers "short" and "immediately" are naturally related: if ...

2

You can use the internal 1.1V bandgap reference to indirectly measure the voltage on the Vcc pin. This 1.1V reference is built into the chip and can be connected to the ADC by setting the MUX registers correctly. Full details here... https://wp.josh.com/2014/11/06/battery-fuel-guage-with-zero-parts-and-zero-pins-on-avr/

2

Your breadboard is missing basic components that are on the Uno. Connect all the power and Gnd pins on the 328P. Add 0.1uF caps from VCC, AVCC, and Aref (if making analog measurements). Add a 10uF to 100uF cap from Vcc to Gnd on the incoming 5V power rail. Add 10K pullup resistor from Reset pin to Vcc. Make sure the crystal caps are 22pF cap (18, 20, 22, in ...

2

The front page of the datasheet shows operation down to light load; 80% at 100 uA load. Although the 2 A output seems excessive for a remote, this device is a reasonable choice. If TI has one that has a lower maximum output current, you will gain a little more efficiency at low loads because the gate charge in the power MOSFETs will be lower. Gate charge is ...

2

If your project consists of multiple source files (as most projects do), you may also look at Link Time Optimization (commonly abbreviated LTO). It makes extra optimizations between objects (at link time, as the name suggests). You may look for a specific "Link time optimization" / "LTO" option in your IDE, or look for a place to add compiler flags. If ...

2

It sounds and looks from your schematic as if you may be attempting to power the project from the FTDI chip's very limited 3v3 regulator. If that is the case you are probably overloading it, especially when the radio is added. You should at minimum give your project its own 5v to 3v3 regulator (along with the capacitors that typically requires) if not a ...

2

The zener diode is connected the wrong way. Instead of being in series with the atmega it has to be in parallel, with the cathode connected to 5V and the anode connected to ground. In your case you don't really need a zener diode, because the 7805's voltage should be pretty stable (linear regulator) and I would say "paranoia" is not an argument ;). That ...

1

You have errors in the wiring. Don't connect display VDD to ground, but to 5V. That error has caused excess current to flow out of AVR IO pins, via LCD input protection diodes to ground. Also, don't connect the contrast pin Vo directly to ground either - just via resistor to ground, or the display will be too dark, just black squares. And finally, there is ...

1

Your circuit won't work because you have failed to account for the fact that MOSFETs are controlled by the voltage DIFFERENCE between their gate and source pins. The voltage you are applying to the gate is relative to ground, so if the source pin is also connected to ground then you have no problems since the voltage you are trying to apply to the gate is ...

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