cancel
Showing results for 
Search instead for 
Did you mean: 

[Solved] How can I use the Arduino microseconds delay of SPC-560P?

gl2
Associate III
Posted on June 29, 2015 at 13:09

I have this sensor HY-SRF05 with 5 pins. In Arduino using the function delayMicroseconds () to manage the operation of the sensor so:

Arduino code:

/*

Tested with HY-SRF05, HC-SR04

Assuming a room temp of 20 degrees centigrade

The circuit:

* VVC connection of the sensor attached to +5V

* GND connection of the sensor attached to ground

* TRIG connection of the sensor attached to digital pin 12

* ECHO connection of the sensor attached to digital pin 13

*/


const
int
TRIG_PIN = 12;

const
int
ECHO_PIN = 13;


void
setup() {

// initialize serial communication:

Serial.begin(9600);


pinMode(TRIG_PIN,OUTPUT);

pinMode(ECHO_PIN,INPUT);

}


void
loop()

{

long
duration, distanceCm, distanceIn;


// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

digitalWrite(TRIG_PIN, LOW);

delayMicroseconds(2);

digitalWrite(TRIG_PIN, HIGH);

delayMicroseconds(10);

digitalWrite(TRIG_PIN, LOW);

duration = pulseIn(ECHO_PIN,HIGH);


// convert the time into a distance

distanceCm = duration / 1 / 2 ;

distanceIn = duration / 74 / 2;


if
(distanceCm <= 0){

Serial.println(
''Out of range''
);

}

else
{

Serial.print(distanceIn);

Serial.print(
''in, ''
);

Serial.print(distanceCm);

Serial.print(
''cm''
);

Serial.println();

}

delay(1000);

}

Of SPC560P how can I do? The board does not handle microseconds. Best regards Gianluca.
1 ACCEPTED SOLUTION

Accepted Solutions
gl2
Associate III
Posted on July 01, 2015 at 12:05

Ok, the function osalThreadSleepMicroseconds it works.

Thanks. 

Best regards

Gianluca

View solution in original post

7 REPLIES 7
Erwan YVIN
ST Employee
Posted on June 29, 2015 at 13:57

Hello Gianluca ,

you have to use :

osalThreadSleepMilliseconds(100);

Best regards Erwan
gl2
Associate III
Posted on June 29, 2015 at 15:10

But 100 milliseconds are 10,000 microseconds. I'd need 2 and 10 microseconds.

Best regards

Gianluca

Erwan YVIN
ST Employee
Posted on June 29, 2015 at 16:31

Sorry ,

it is a bad copy-paste You can use the osal macro

#define osalThreadSleepMicroseconds(usec) osalThreadSleep(OSAL_US2ST(usec))

Best regards Erwan
gl2
Associate III
Posted on June 29, 2015 at 21:00

Yes I know. Sorry for bad formatting in the last message, I do not know how it happened. Thanks.

Best Regards

Gianluca

Erwan YVIN
ST Employee
Posted on June 30, 2015 at 10:10

No Problem 😉

Every people (Customers & Moderators) are struggling everyday on this forum based on Sharepoint solution 😉

Best regards

 

                     Erwan

gl2
Associate III
Posted on July 01, 2015 at 12:05

Ok, the function osalThreadSleepMicroseconds it works.

Thanks. 

Best regards

Gianluca

Erwan YVIN
ST Employee
Posted on July 02, 2015 at 09:51

Hello Gianluca ,

Good news 😉

   Best regards

                 Erwan