Problems using micros() function and PWM signal.

Hi there,

Im trying to measure a motor speed and give a PWM input for controlling a DC Motor from Labview using LIFA and Arduino UNO.

Im using External Interrupt number 0 (int.0) which is on pin 2 to detect falling edge of a infrared barrier sensor and measuring the period in microseconds using micros function, then sending it to Labview to convert it to speed in rpm.
I am also trying to send a PWM signal in pin 10 which uses timer 2, not timer 0 as micros function.

Im connecting this PWM pin to an H-bridge L293 "correctly" i think cause nothing has overloaded or so. My motor do makes a little sound (something like a constant and very quiet beeep) when i put inputs like 150 PWM or so but nothing has burned and I have a DC source that measures less than 0.8 A for the motor which is OK according to technical specifications.

This works fine if I give PWM input of 255 or 0 as the velocity measures i get are very very stable but if I give an input of something between 0-255, the velocity measures i get are wrong by far and arent stable what so ever.

I completed my project using two Arduinos, one for the PWM output and one for the velocity measure and worked perfectly stable but i want to do this with only one.

Here is my "modified" code of the Arduno LIFA with case 0x03 for sending the 4 bytes of the period to LABVIEW. I also attached a print screen of the part where I read the 4 bytes in LABVIEW.

Thanks in advance.

Code.rar (2.02 KB)

LABVIEW CASE.png