52

The code optimizer has analyzed the code and from what it can see the value of choice will never change. And since it will never change, there's no point in checking it in the first place. The fix is to declare the variable volatile so that the compiler is forced to emit code that checks its value regardless of the optimization level used.


37

Yes, C++ is certainly suitable for embedded systems. First let's clear up a couple of misconceptions about the difference between C and C++: In an embedded micro, you're always going to need to use high level languages carefully if you're concerned about time or space constraints. For example, many MCUs don't handle pointers well, and so are very ...


33

In general, going from 8 to 16 to 32 bit microcontrollers means you will have fewer restraints on resources, particularly memory, and the width of registers used for doing arithmetic and logical operations. The 8, 16, and 32-bit monikers generally refers to both the size of the internal and external data busses and also the size of the internal register(s) ...


29

Yes, it's almost certainly a good move to learn to use C as well as possible (C++ will give you a helpful starting point, although as leftaroundabout notes, there will still be plenty to pick up, especially the differences between coding for small embedded systems compared to writing for something like Windows) given it's ubiquity. Most microcontrollers ...


28

I wrote the simulation engine that powers CircuitLab from scratch: from the sparse matrix library up through component models and simulation modes. My co-founder wrote the front-end. It ended up being an unbelievably huge programming project, but one I'm quite proud of. If you're up for the challenge, writing a circuit simulator may be one of the most ...


27

If you are familiar with \$\LaTeX\$, you can use circuitikz to draw nice circuits by writing code. Example. More Examples


26

They make ZIF (zero-insertion-force) sockets for basically every package available. Such as QFN: Or SSOP: And yes, they do make ZIF sockets for BGA devices. And programmers that support many sockets at once: Or for really large volumes, completely automated programmers with an integrated robot: It's not hard to imagine how something like that could be ...


26

Q: Do Electrical Engineers Use Microcontrollers? Yes. Absolutely. From simple toys to complex manufacturing processes and robots. It is not a skill that will hurt you to know. Learn as much about them as you can.


24

Designing by rules of thumb you found on the internet someplace is a bad idea. The right way is to understand the issues, them make intelligent tradeoffs. There is nothing wrong with a system that takes a interrupt, clears the hardware condition, then sets a flag for foreground code to do the remainder of the processing when it gets around to it. The ...


23

Learn C, and get a cheap microcontroller development board, like an MSP430 or ARM Cortex, and at least write and load a few C programs. I have a computer science degree and a software development background, mostly C++ programming for games and now iOS games and apps, but my last job was a semi-pro EE gig that started with doing a bunch of firmware ...


23

Bit banging is creating the whole series of pulses in software, instead of relying on a piece of hardware inside the microcontroller. Many microcontrollers have a hardware SPI, and then all you have to do is write a byte to the output register, and the SPI controller will shift the data out, and at the same time receive data from the slave. You can get an ...


22

You cannot extend the program memory (flash). TI produces the same chip with double the flash and RAM, but nothing else changed: TM4C1230D5PMI. If you cannot use a chip with larger flash, you will have to reduce your code size: Disable debugging, such as the expensive printf function. A printf that supports floating point output will typically set you ...


20

If you have the space for a header, that's probably the best option, and the slightly staggered pins Majenko recommends is a good way to hold a connector in place without adding complexity. But here's an alternative approach, for boards where you don't have space to fit a header, or the standard header doesn't accomplish all your programming/setup/board ...


18

First of all: forget about "embedded" as that is not a useful distinction. The all-important property is "resource-constrained". The most important resource is often time, in which case we talk about real-time systems, but it can also be memory or power. New language adoption is hard and rare. It requires re-training, new tools, and finding a good way to ...


17

Any language can be suitable for an embedded system. Embedded just means: part of a larger apparatus, as opposed to a free-to-use computer. The question has more relevance when asked for a (hard-)real-time or limited-resources system. For a real-time system C++ is one of the highest languages that is still appropriate when programming for stringent time ...


17

I would suggest always including a header in that kind of quantity (small). If you get to larger quantities you can consider pads for pogo pins (you'd have to make a fixture to hold the PCB in alignment) or, in your quantities, you could use one of the Tag Connect cables which require only holes and unpopulated pads (they snap onto the board). As well as ...


16

I managed to solve that problem. If anybody encounters similar problem, here's what I've done: I used ST-Link v2 and ST-Link Utility. In setting, I set "Connect under reset" and SWD interface (I'm not sure about frequency). Then I press the reset button on my board and clicked "Target" -> "Erase chip" and just after clicking I released the button - It ...


16

It is possible to make a circuit out of logic gates that would be able to initialize and display characters onto a 16x2 LCD character mode module. It is also possible to make a circuit out of logic gates that could take the output of a standard matrix keypad or even a PS2 type keyboard and route that keyboard data to the LCD module. The big thing to think ...


15

Can An Operational Amplifier Circuit Be Made Entirely Out Of Diode Nand And Nor Gates? This apparently simple-enough question is somewhat ambiguous and can be answered several ways. Spehro has assumed that you convert the input to a digital value and perform digital arithmetic on it. So he says the answer is yes. ScottMcP takes your question at face value, ...


14

My advice, stick with the C++ derived Arduino language or use raw C/C++. It's ideally suited to microcontrollers. But, if you like esoteric languages: Occam via concurrency.cc BASIC via DK-Basic Java via NanoVM Forth via amforth


14

Running a simulation multiple times and changing multiple component values is a bit more involved than just changing one (which is not so bad) Here is the concept for changing one value: Add a .param statement using the SPICE directive icon on the far right, e.g. for a resistance value .param X=R To use it you would enter {x} into the resistor value, ...


14

The language in this case is exactly the same. The Arduino environment happens to have some extra libraries (just more C code) that 'wrap' the access to the actual hardware registers (DDRx, PORTx, INx, etc.) with slightly more user-friendly functions. This increases the overhead (more instructions need to be executed for the same operation) but increases ...


14

If the system clock is 16 MHz and the prescaler is 256, you timer will run on \$ \large \frac{16\,MHz}{256} = \small 62500\,Hz \$ , so there will be an increment in every \$ \large \frac{1}{62500\,Hz} = \small 16\, \mu s \$. An interrupt will be generated when the counter's value is 31249. If we calculate this time: \$ \small 16\, \mu s \times 31250\, ticks =...


14

Check out SKiDL (https://github.com/xesscorp/skidl), this is along the lines you're thinking. Edit (as req'd): SKiDL allows procedural description of all circuits (rather than just digital), instead of graphically entering your schematic. The netlist output can then be imported into layout software. It will also perform ERC checks, and is extensible. This ...


13

Many programs can draw a schematic. None that I know of can draw a good schematic: One that emphasizes the most important information, and arranges the circuit in a clear and easy to understand way. If you're just looking for a hardware description language (no graphical schematic output), VHDL and Verilog are widely used to define (digital) circuits to be ...


12

This particular job may not, but the product would likely include a microcontroller and perhaps be controlled by a more powerful embedded system. Note that it mentions 'troubleshooting' (but not writing) "firmware". It's also possible this job description was written by someone (for example, an HR person) who doesn't really understand the engineering ...


12

I always add space for an ICSP header, even if it's not populated. I have three ways of doing it at the moment depending on situation. One of my designs has a very fine pitch header for which I have built an adapter (0.6mm solid core wire is perfect for it): I use this connector when space is at an absolute premium. (Sorry it's blurred, my phone's camera ...


12

Yes, it would work just fine. Actually, the development tools for most FPGAs allow you to program the external flash directly through the FPGA's own JTAG connection, eliminating the need for a separate programming interface for the flash.


11

I hope to add more light than heat to this discussion about C++ on bare metal and resource constrained systems. Problems in C++: Exceptions are especially a RAM problem as the required "emergency buffer" (where the out of memory exception goes for example) can be larger than the available RAM and is certainly a waste on microcontrollers. For more info see ...


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