8

No, it will not be any faster. The extra instructions are to access the extra flash memory of the 2560. Instructions like EIJMP - Extended indirect jump, EICALL - Extended indirect call, etc. The compiler option -O3 optimises the most, but there are other options you can enable, such as -funroll-loops which will cause major code bloat but speed things up. ...


7

if and else if clauses are mutually exclusive. If the if is true then the else if cannot run. Therefore it must be the case that the code you posted is being executed twice (at least) - once for SLOT_1 and once for SLOT_2. Just so fast that you think it's happening at the same time.


6

Use the newest Arduino IDE, because some time ago the 'lto' option was added which is a major optimization for both speed and size. It is possible to test a few compiler options with the #pragma. Try for example these at the top of the sketch: #pragma GCC optimize("-O3") #pragma GCC optimize("-ffast-math") The 'fast-math' is dangerous, be careful with it. ...


4

There are three things that i can see that are holding your code back. AnalogRead in Arduino is very slow. The ADC in the chip is not the greatest but also the AnalogRead function will hold you there until a full read and conversion are complete. It may be possible to trigger a sample and conversion and read the answer later. Look for a chip that can ...


4

No, there isn't. But you do have a simple alternative: use WGM 14 (fast PWM with TOP = ICR1). Then the TOV1 flag will be set after the timer reaches TOP: TIMSK1 |= (1 << TOIE1); // enable Timer 1 overflow interrupt ISR(TIMER1_OVF_vect) {} // Timer 1 overflow vector Note that this waveform generation mode behaves very much like the CTC ...


4

Here: ldi r20, 0b00000010 ; CTC mode, int clk; sts TCCR1A, r20 ldi r20, 0b000000101 ; prescaler /1024 sts TCCR1B, r20 you are setting the bit WGM11 on TCCR1A. The timer then runs in mode 2 (PWM, Phase Correct, 9-bit) rather than mode 4 (CTC).


3

You need more decoupling capacitors - one per VCC and AVCC pin, plus a larger (10µF) for the whole chip. You need a pullup resistor (and maybe button) on RESET.


3

In the platform.txt file found in ~/Arduino15/packages/arduino/hardware/avr/1.6.17 or similar, you can change the three instances of -Os with -Ofast. The size of the code can increase dramatically though.


3

You wired the whole thing backwards. The proper wiring is Your board - Arduino MISO - D50 MOSI - D51 SCK - D52 Reset - D53 Vcc - 5V GND - GND This is kind of obvious from the picture: you would normally use the ISP connector of the target board.


3

On an ATmega2560, can ports have some pins used for analog inputs but others as digtial i/o? Yes, the ADC MUX controls the selection of the pin that is connected to the converter. This is independent of the digital pin control. Cheers! PS: See the Arduino core source code for further details on the ADC MUX control registers.


3

The target board was not reset. The "Arduino as ISP" sketch uses pin 10 to reset the target, not the SS pin. So even on Mega, wire reset of target to pin 10, not to pin 53. Is this an error communicating with the ISP (Arduino) or is it an issue with the ISP talking to the target (ATMega8B on USBAVR)? the first error "not in sync" is a problem with ...


3

Here is my guess what happens: Once the code in the if statement have run, the loop() only contains the incrementation of i. This will run very fast. After a rather short time (maybe someone here can make the calculation to get the time, that is needed) i will overflow, going from it's most positive value to it's most negative value, then incrementing ...


3

Use a logic level conversion IC. picture source http://msx-elektronika.pl/en/logic-level-converter


3

First, let me give a couple of suggestions on the programming style. There is no point in defining your own variables for accessing the hardware registers: the avr-libc does that for you, you just have to #include <avr/io.h>. Actually, you don't have to #include anything: the Arduino IDE automatically #includes Arduino.h, which in turn #includes avr/io....


2

Exactly one of the blocks in if{..} else {...} will be executed. Your misunderstanding is elsewhere.


2

In fact, the basic Arduino Mega (with the ATmega 1280) utilizes an FT232RL, so yes, it will work if you connect it correctly. It is only the newer Mega2560 (along with the similar-generation Uno, etc) which utilizes an ATmega16u2 or similar as the USB bridge. Generally speaking, the bootloader doesn't care - you should be able to use either target chip ...


2

It does actually seem to work with CTC mode and ICRn as TOP, by using the TIMER1_CAPT_vect interrupt. // CTC mode with ICRn as TOP TCCR1A &= ~(1 << WGM10); TCCR1A &= ~(1 << WGM11); TCCR1B |= (1 << WGM12); TCCR1B |= (1 << WGM13); // enable interrupt TIMSK1 |= (1 << ICIE1); // TOP value ICR1 = 100; // interrupt at TOP ...


2

Connector X1 has the pins you want. ICSP is shared with the SPI pins. Wire those to your ICE in the same way as you wire the SPI pins of the ICSP header on a normal Arduino to an ICE.


2

That error is common and usually means you either have the wrong board selected or the wrong port. Check the tools menu. Be sure you have the port for the programmer and not the port for the board if the board is also connected.


2

There are a few things very wrong here. First problem: you are clocking Timer 2 with the prescaler set to 1. This means the timer will roll over every 256 CPU cycles. Your input signal, on the other hand, has a period of 25 µs, which is 400 CPU cycles (I am assuming a 16 MHz Arduino). Unless you know beforehand that the phase difference ...


2

There isn't any interrupt code in what you posted. What exactly is the problem? One important note is that you shouldn't try to print to Serial line in the interrupt handler as serial is itself driven from interrupts which are switched off during your handler code. If all you really want to do is to print something every 10ms then you don't need any ...


2

I think you have a problem with your math here, not with your code. What you are simulating is very similar to a 1-dimensional random walk. According to the linked MathWorld page, for such a process “the most probable number of sign changes in a walk is 0”. If, at some point in your program, the loop starts with note == 6, and then it starts randomly going ...


2

A transistor amplifies current, not voltage. The first thing to check is the current of your LEDs. In your current configuration, it is between 25 and 30 mA. This is too high for most LEDs. Check the datasheet of your LEDs for the actual forward voltage, and current rating. To calculate the value for the resistor in your circuit, use Kirchhoff's and Ohm's ...


2

Just a follow up in case someone else has the same problem. One solution is Nick's answer in his comment, which grabs the far addresses first in the setup, storing them in an array, and using them. I // Each array contains 32000 values const byte VALUES_1[] PROGMEM = { 1, 0, 1, .... 0 }; const byte VALUES_2[] PROGMEM = { 1, 1, 0, .... 0 }; const byte ...


2

If you are not afraid of getting your hands dirty by touching hardware registers, you can access those pins bare-metal style, using port manipulation. You will have to read the datasheet, specifically the section “External Interrupts” if that's what you are after. This works with the stock Arduino core (or even without core), which may be interesting from a ...


2

There's a couple of things wrong here: You are just getting the last read value doubled: x_offset += x_offset; However x_offset is always replaced with the lates reading. You're not summing anything. To get anything other than 0 out of dividing an integer by 2000 the value stored in the integer would have to be > 2000. But since you can only store a ...


2

Each processor has different registers, things that control stuff like interrupts, input and output. I would not expect code written for one processor, especially if it directly accesses the registers, to work on another processor. You would need to look at the datasheet for the Atmega2560 and see how to control its pin change interrupts.


2

I think the issue is with the menuChoice() function. Try replacing it with this: int menuChoice() { int selection = 0; const byte bufferSize = 16; char inputBuffer[bufferSize + 1]; if(Serial.available() > 0){ // 50 bytes more in compile size using parseInt() vs // char buffer and atoi(). // selection = Serial.parseInt(); Serial....


2

For an infra-red remote control you generally can't. Those don't normally have the concept of button release. Normally there are two kinds of buttons on a remote: Burst code Repeat code The first sends a short burst of the same code. This allows for a function to be run once per button press. The second sends the same code over and over again constantly ...


2

Answer is simple. You assign 38400 to a variable of type int. The signed range of integer values that can be stored in 16 bits is −32,768 through 32,767;


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