delayMicrosecond instruction not compiling for Mega 2560

Hello,

I have a simple code that I have written that is used to control a pulse motor. There is a hall switch that detects the position of the magnets on the rotor and fires the motor coil appropriately. I have used some math functions to use the frequency of the hall effect input as means to adjust the pulse duration coming from the controller. This allows my pulse to automatically adjust with the appropriate pulse width for the output.

The problem that I am having is that I cannot get the delayMicroseconds instruction to behave the same as the delay instruction. When I write the code for use with millis and delay, the code runs as to be expected. But when I adjust the code for use with micros and delayMicroseconds, I get this:

collect2.exe: error: ld returned 5 exit status

exit status 1 Error compiling for board Arduino/Genuino Mega or Mega 2560.

Here is the section of my code that uses millis and delay with no problems:

timestamp = millis(); //pulse calculation instructions

timeperiod = (timestamp - lasttimestamp); pulse1 = timeperiod*.5;

lasttimestamp = timestamp;

digitalWrite(13, HIGH); //motor pulse digitalWrite(12, HIGH); //timing light

delay(pulse1); //pulse duration

Here is a similar code using micros and delayMicroseconds in place of the previous instructions and DOES NOT COMPILE:

timestamp = micros(); //pulse calculation instructions

timeperiod = (timestamp - lasttimestamp); pulse1 = timeperiod*.5;

lasttimestamp = timestamp;

digitalWrite(13, HIGH); //motor pulse digitalWrite(12, HIGH); //timing light

delayMicroseconds(pulse1); //pulse duration

I have tried everything that I can think of trying to solve this but am all out of ideas. Here is my full code for supporting evidence:

int hallstate = 0; int lasthallstate = 0; unsigned long timestamp = 0; unsigned long lasttimestamp = 0; int timeperiod = 10; int pulse1 = 20;

void setup() {

pinMode(13, OUTPUT); //pulse pinMode(12, OUTPUT); //timinglight pinMode(10, INPUT); //hallinput

}

void loop() {

halltest:

hallstate = digitalRead(10); //check state of hall sensor

if(hallstate != lasthallstate) //check to see if state has changed {

goto function; }

else goto halltest;

function:

if(hallstate == 1) //pulse event instructions { timestamp = millis(); //pulse calculation instructions

timeperiod = (timestamp - lasttimestamp); pulse1 = timeperiod*.5;

lasttimestamp = timestamp;

digitalWrite(13, HIGH); //motor pulse digitalWrite(12, HIGH); //timing light

delay(pulse1); //pulse duration

digitalWrite(13, LOW); digitalWrite(12, LOW);

lasthallstate = hallstate; //store last time stamp for comparison with the next

}

if(hallstate == 0) //return to input monitoring {

lasthallstate = hallstate; goto halltest;

} }

Thanks,

Dave

Wow long time I had not seen goto

Try not doing pulse1 = timeperiod*.5; but   pulse1 = timeperiod >> 1; Any change?

Are you running on an old PC? Which IDE version?

When I copy your improperly posted code into the IDE, and verify it, I get:

Binary sketch size: 2,072 bytes (of a 30,720 byte maximum)

So, you need to post the EXACT error message that you see.

PaulS: When I copy your improperly posted code into the IDE, and verify it, I get: So, you need to post the EXACT error message that you see.

This is what I get when I 'copy error message':

Arduino: 1.6.11 (Windows XP), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

collect2.exe: error: ld returned 5 exit status

exit status 1 Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

I apologize for posting code incorrectly as I did not know there was a proper way.

Thanks

XP is beyond end of life. Google all the problems with XP and the newest versions of the IDE. Then, install an older version, say 0022, to match your obsolete OS.

Seen my question in answer #1??

Arduino: 1.6.11 (Windows XP) --> i think this is part of your pb (which you might get rid of by getting rid of the float division)

Thanks so much, I felt like I was going nuts. Its time to upgrade the old PC anyways...

Try the latest hourly build, it should have the "ld returned 5 exit status" error fixed.

Installing Arduino 1.0.6 resolved my issue for my XP base system.

Thanks