37

Could you write your code in assembly, convert it (manually) to machine code, Yes! Code can be written "out of your head" in binary, if you wish. Long (long long) ago this is how I started using (then) microprocessors. I and friends would write code in assembly language, compile it manually to machine code (something you can do "by inspection" after some ...


27

This is not a compiler issue: doing the division first here is the legal behaviour, as division and multiplication have equal precedence and are evaluated left-to-right. (Also, when in doubt: use parentheses; there's no penalty.) You are working with integers, so reading / 0xFFFF will always evaluate to 0 if reading is a uint16_t, unless reading == 0xFFFF. ...


24

Ah, you're missing the STATE MACHINE concept. That's where we can "write code" made out of TTL hardware chips: data-selectors, 4-bit counters, gangs of parallel flipflops. (But all those are the complicated parts, while the idea behind "state machines" is fairly simple.) "State-machine" is also commonly called "micro-code." Also called "bit-slice" or "...


23

Just like a procedural programming language goes through several steps (compile, assemble, link) to produce an executable, HDLs must pass through several processes before a usable configuration file for the FPGA is generated. These include Synthesis --- convert the HDL code into a netlist describing connections between logical elements. Mapping --- Convert ...


20

The MCU specified here is a Freescale MC9C08 series, which uses a slightly enhanced version of their HC08 architecture. This is an 8-bit core, which (like many such) has shorter instructions and faster access to "zero page" addresses than others. Zero-page addresses are only 8 bits long instead of 16 bits, so instructions referencing them can be 2 bytes ...


16

The AVR is a RISC architecture, so it has pretty basic hardware handling of interrupts. Most processors mess with the stack during interrupts, though there are a couple, most notably ARM and PowerPC, that use different methods. In any case, this is what the AVR does for interrupts: When an interrupt occurs, the processor hardware does these steps, which ...


16

Register Transfer Logic (RTL) is the result of the first translation phase, before it is mapped to the vendor-specific resources, which are not portable between vendors or even between different FPGA from the same vendor. Essentially RTL shows both the combinational logic and the synchronous registers (D flip flops), so state machines are recognizable. RTL ...


15

Depending on the CPU architecture there may be different instructions to access data at different address. Here is an example from Keil for one of their compilers. The near access has a certain memory limit, so you may give hints to the compiler to place some frequently used variables in an area that is accessible by shorter instructions (obviously ...


14

This is a fundamental C issue: you need to be extremely clear whether you're doing integer or floating-point arithmetic. uint16_t temperature = reading*0.076295; That promotes "reading" to "float", because 0.076295 is a float literal, then does the multiplication. uint16_t temperature = reading/0xFFFF*2.5*1000*2; The first two elements ...


12

Since you are using the MPLAB IDE with the XC8 C compiler, you can check the compatibility from the menu Configure->Select Device (green indicator means fully supported, yellow is partial, and red is not supported). Right now, the best choices would be Pickit 3, ICD3, or RealICE (in order of increasing price) Here are the compatible programmers, ...


11

The physical primitive of an FPGA is a configurable logic block (CLB). Each logic block is given a dedicated location in memory, so-called configuration memory, that determines how it is configured and where it connects to. HDL ultimately ends up as a bunch of ones and zeroes, a so-called bitstream that is placed in this configuration memory. Most FPGAs ...


10

Originally, in programmable machines, the programs were manually punched into paper tape or cards. Later they used a kind of typewriter to do the punching, and even later still the computers (as they had come to be known by then) could punch their own paper tape. It was, literally, sitting there with a card and manually making holes in it. Each column is ...


9

The C18 compiler supports the number-to-ascii family of standard C functions in stdlib.h: itoa(), ltoa(), ultoa() et cetera. Depending on which compiler / stdlib.h you have, the relevant function prototype would be: extern char * itoa(char * buf, int val, int base); // signed int extern char * utoa(char * buf, unsigned val, int base); // unsigned int ...


8

It seems that Sourcery CodeBench Lite for ARM is no longer available. Mentor Graphics appears to produce a Lite toolchain for other processors, but not for ARM. They now direct you to obtain a trial of their commercial toolchain for the ARM processors. Update 27 January 2015: the downloads are not available from these links anymore The last Sourcery ...


8

The most common cause for RAM exhaustion is using the String object or using lots of constant-character arrays (c-style string). Forutantly IDE 1.0.4 includes a fix to malloc which has plagued the String-object for a very long time. To reduce the RAM wasted by constant-character strings like: Serial.print("Hello World"); // This consumes RAM! You can ...


7

Follow the steps in this post to check your RAM usage: Checking memory footprint in Arduino My guess is that you have gone over as the RAM size of the ATTiny85 is 512 bytes. In your sketch, font will be stored in RAM. You want to store it in the FLASH program memory. Follow these instructions to do so: http://www.arduino.cc/en/Reference/PROGMEM


7

You said "small microcontroller and had no interfacing, no computer, no debugger, compiler, or assembler.". Well you can get by without the computer, debugger, compiler, or assembler, but you have to have some sort of interface to connect with the microcontroller in order to load the program. First of all, forget about any high level languages like C. ...


7

A processor is really a finite state machine (FSM) for implementing the machine code instructions. It reads the instructions from memory and uses the required hardware, such as the ALU, to implement them. Here is the data path of the MIPS architecture. source You have a control unit implementing said FSM and is responsible for ensuring the data is ...


6

The language is the same. You can either use Arduino IDE or Atmel Studio (http://www.engblaze.com/tutorial-using-atmel-studio-6-with-arduino-projects/) The Arduino libary is more of a wrapper to make it easy to do things, like digitalWrite, which you do not have by default in Atmel Studio (or you can define it yourself). With Atmel Studio you would flip a ...


6

I know it's an old post, but this might help others... Don't confuse toolchain with IDE. You might consider the IDE to be the last link in the toolchain, but a toolchain does not necessarily imply an IDE. Eclipse is an IDE that connects to many different toolchains. In my case (ARM gcc build [linker, compiler, assembler, etc] + automake) is my toolchain. I ...


6

So far the answer given limits itself to 8-bit PIC microelectronics, but the OP asked (in part): Why are there different compilers when one can do the job? Are certain compilers only used for specific microcontrollers? I will answer both of these questions together. Microchip makes not only 8-bit microcontrollers (PIC10, PIC12, PIC16, PIC18) but ...


6

As a practical matter, something like toggling JTAG pins manually would be very error-prone. To input a program of any decent size would take thousands of toggles. But theoretically, it's possible. If you're allowed to prepare the microcontroller in advance (or write a boot ROM for it), you could easily implement something like the external toggle switches ...


6

Yes, a debugger can tell you at any point in time how much memory is being used by the stack. Just check the current value of the stack pointer. Another thing you can try is to fill up all of the unused RAM area with some obvious bogus value, like 0xAAAA. Run your code for a while and then check the RAM to see how many of the bogus values were overwritten......


6

Can I expect a significant speedup? By which order of magnitude? Sure, by quite a lot. CRCs can be computed on data a byte a a time using a straightforward table lookup. A moderate-sized FPGA (say, a Xilinx XC6SLX75) will have a hundred or more blocks of internal dual-port RAM that allow 200 data streams to be processed in parallel at a rate of one byte per ...


6

Well you define ext0 but try to use ex0. No wonder linking fails.


6

In C, operators at the same level of precedence are evaluated in left-to-right order. So, in your first equation the division is done first. As a general rule in integer arithmetic you should try to perform the multiplications first, while avoiding overflow. Do the division last. But you have other concerns here. If you are using a 16-bit ADC then you should ...


5

While being the "manufacturer's own" compiler does have its marginal advantages, for Atmel Studio in this instance, the corresponding disadvantages are many: Less people will see and report bugs, or suggest improvements, than for a product with greater reach, such as IAR - Not just Atmel users buy IAR. So less fixes or enhancements will get released. Here ...


5

I assume you are talking about the PORT registers in the common hobby PICs. These chips do have bit level set and clear instructions, and a compiler can be expected to translate PortB.B0 = 1; to BSF PORTB, 0 BUT BUT BUT BUT BUT BUT BUT These bit set and bit clear instructions are executed as a full-8-bit read-modify-write cycle. The CPU reads the 8-...


5

The conventional way to achieve what you want is to hand code the delay subroutine in the native assembly language. Almost all development tool sets that are C compilers will have the capability to include assembly language modules into the build. A common trick used by experienced programmers is to first build the delay routine in C code as you have done. ...


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