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 ...


19

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". These days LED's are very efficient. They no longer need the 20mA the first generation required. 1mA or less is not uncommon. So, yes, you drive these straight ...


16

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. If, after the diode drop, your VCC ends up being below or above the minimum voltage required to drive your MCU (or draw more current than the internal ...


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 ...


12

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 settings. Look also at section "24.11. Examples of Baud Rate Setting" and table 24-4 of the datasheet.


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 ...


9

From the datasheet: The maximum voltage on any pin other than _RESET is specified as "Vcc + 0.5V". If the chip is unpowered, Vcc is 0, so no -- you cannot safely apply any voltage above 0.5V. If you want to share an I/O between two parts, where one of them may be unpowered, you need some kind of switch.


8

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 the supply voltage again rises back above the threshhold for a minimum period of time, the chip will come out of reset and start executing code at the reset ...


8

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. It's worse because the C int operations take a lot of cycles on an 8-bit processor, but it would show up even in tight asm code. If you don't have any other ...


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 ...


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 ...


7

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 component where this behaviour (i.e. only loss of power allows previous state to resume) is normal, and SCR-like structures exist within most ICs. Is this an ...


7

The AREF pin has no required connection. If an external reference is needed, it can be connected to the AREF pin, but then care has to be taken to not connect AREF to an internal voltage source. If an internal reference is used, the "best practice" is to externally decouple the reference by connecting a small capacitor between AREF and ground, but this is ...


7

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 your smartphone. Both of these are powered directly from switched regulators (usually buck converters but that doesn't matter that much) and they work fine! ...


7

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 operate in two modes; one where it needs a clock at 16x the baud rate, and another where the clock need only be 8x. You are using the 16x mode, which means that you ...


7

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 LED does not work: Electricity flows through the LED: it would go through the resistor anyway, either if it is before or after the LED. Electricity does not ...


6

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 board designer will put down the pads for all 28 pins. Pads are not only for making electrical connections, but also to mechanically anchor the part. Granted, ...


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

Is it correct to connect ULN2803 in parallel to achieve more max current per channel? See Tony's comment below. However yo have another problem: ULN2803 has high VCEsat, so your 5V motor will only receive 3V or so (i.e. it will work... but only marginally). I would use several dual MOSFETs in SO8 packages. These cost 50 cents each, they're small and easy ...


5

It is very difficult to see, but as far as I can tell it looks like you have the wrong pinout for the 555 timer. The pins on the right-hand side should be numbered 5-8 from the bottom up, not from the top down: If you have it connected the way the picture shows, I expect that's why it's giving you problems.


5

This looks like a mess waiting to catch fire or electrocute someone. You don't say where this is, but almost certainly some part of the AC line is tied to ground somewhere. That means you have a hidden conduction path from somewhere in the "AC Supply" block to the source of both FETs. The only way the concept is valid is if this "AC Supply" block is a ...


5

Have I understood the concept of multitasking right? there are different flavours of "multitasking", some more sophisticated than others. in a nutshell, it is about time sharing to provide the perception of concurrency. How can I allocate time slices for a "Task" or is it not possible in this case? your approach to multitasking is less conventional. ...


5

simulate this circuit – Schematic created using CircuitLab


5

The ATOMIC_BLOCK is executed without interruption but the instructions inside are not executed in the same time. From "oc = timer1OverflowCount;" to "c = TCNT1;" TCNT1 is incremented and is not the same as when reading oc. The error shows when the overflow occurs inside the ATOMIC block and timer1OverflowCount cannot be updated and even the interrupts ...


5

The pin on your MCU won't sustain a nominal voltage of 3.3 volts except under very light loading conditions. What I think is happening is that as you draw 17 mA, the pin voltage is drooping down to something smaller than 3.3 volts. You can check this with a multimeter of course. I would like my LED to run at 40mA Trying to take 40 mA from your MCU pin is ...


5

To light the LED, using the resistor to define the current, it doesn't matter which order they go in. There may be some other non-electrical reasons for preferring one over the other in specific circumstances. For instance, if you connect the LED directly to the PSU +ve, then accidentally shorting the LED to ground, as you might do with an untidy ...


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

The cleanest way to build a USB MIDI device would be to use a microcontroller that supports USB natively, and implement the USB MIDI protocol directly. Otherwise, the easiest way to get USB MIDI support is to take apart some cheap USB MIDI interface and duct-tape it to your circuit.


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