55

A bootloader on a microcontroller is responsible for updating the main firmware over a communication channel other than the programming header. This is useful for updating firmware in the field over BLE, UART, I2C, SD cards, USB, etc. It would be extremely inconvenient to require customers to purchase programmers just to update the firmware on their ...


54

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.


36

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


35

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

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


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.


26

So that the loading process can recover from errors. Suppose there is a communication error or power disconnects during an upgrade. If the boot loader were part of the application you were upgrading then the user wouldn't be able to try again without using special hardware to reflash to boot loader. Some microcontrollers can't execute code from RAM. If the ...


25

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


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


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


22

Since the code snippet you're interested in isn't big, you could disassemble your compiled code, look at all the assembly instructions and count how many cycles they need. You can find the number of cycles for each instruction in the datasheet. If you have an oscilloscope, you can turn on a pin before the if statement and turn it off after your code snippet. ...


21

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


19

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

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


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

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


15

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


14

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


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

Let's do it! Say we have the code int main(void) { volatile uint8_t val = 0; while (1) { if ((PIND & (1 << PIND6)) == (1 << PIND6)) { val = 1; } else { val = 0; } } } Say we use AVR GCC with optimization flag -O1, then the disassembly of the relevant section looks like 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 ...


13

You have configured the PIC to output the internal clock signal on GP4 using #pragma config FOSC = INTRCCLK Replace INTRCCLK with INTRCIO.


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

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.


12

Just to add to Spehro's correct answer: Since the microcontroller you are using has only 8 pins, they necessarily must share functionality to provide the various features that the device is capable of. I just wanted to provide a sort of "roadmap" to help explain how the configuration works. Check out the pin function diagram on the datasheet page 2: You'...


11

I think it is actually possible to run LTSpice from the command line and have it run a transient simulation: On Windows: cd <wherever LTSpice is installed on your computer> scad3.exe -Run -b MyCircuit.asc On Linux: cd ~/.wine/drive_c/Program Files (x86)/LTC/LTspiceIV wine ./scad3.exe -Run -b MyCircuit.asc


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


11

To make code modular. If your A/D routine, for example, always sets up the A/D completely for whatever mode it uses it in, then that routine can be called at any time whether immediately after powerup or after the A/D was used in some other way. Code may jump back to the startup location to do a software reset. In that case, the settings may not be at the ...


11

Let's take some real world examples. I wrote a simple C program, which I think represents typical C code. Some could argue one way or another that it doesn't, but I think it will make my point. Here is the C code: unsigned short m [20]; int main() { unsigned char a, x, i; unsigned short b, y; unsigned long c, z; a = b = c = 0; for (...


11

A MISRA-C checker is much more than just a style checker; it enforces a set of software development guidelines for the C programming language developed by MISRA (Motor Industry Software Reliability Association in the UK). These guidelines are intended to facilitate code safety, portability and reliability regarding the use of ISO C in embedded systems. ...


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