Ping Ultrasonic Sensor Help!
robo1
Posts: 2
hey guys,
well i working on a robot for school and i used the parallax board to connect the sensor and get some values. it was easy to do the setup and all well now my question is how would i interface the same sensor on a logicflex(intel). im having difficulty doing that i have do alot of research can seem to find a way to do it. well below is the data sheet:
http://www.jkmicro.com/documentation/pdf/BrocLogicFlex.pdf
thank you
well i working on a robot for school and i used the parallax board to connect the sensor and get some values. it was easy to do the setup and all well now my question is how would i interface the same sensor on a logicflex(intel). im having difficulty doing that i have do alot of research can seem to find a way to do it. well below is the data sheet:
http://www.jkmicro.com/documentation/pdf/BrocLogicFlex.pdf
thank you
Comments
One possibility would be to continue to use the Stamp as a peripheral processor for the PING. The Stamp would simply get readings from the PING and send the values as numbers (digits followed by a space or carriage return) to the PC via one of the serial ports.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
#include <stdio.h>
#include <dos.h>
//
unsigned int GetTickCount(void){
/* Created: 2/5/2009
Author: AC
Purpose: uses striaght up assembly to latch the current 'tick count' of the 8254 counter (coutner 1),
assuming it's running at the full speed, and nobody has (expletive)ed with the PSCLK.
Each 'count' is about .8380951104us / 2
*/
__asm{
pushf // save interrupt state
cli // disable interrupts for the duration
mov ax, 0x80 // command to latch coutner 0
out 0x43, al // latch the coutner
in al, 0x42 // Get LSB
mov ah, al // Save LSB
in al, 0x42 // Get MSB
xchg al, ah // switch them around to be right
popf // restore interrupts
}
//printf("%u\n", _AX);
return (_AX);
}
main()
{
unsigned int count;
int i=0;
outportb(0x65,0x01); /*set port to output*/
outportb(0x60,0x00); /* set the port to low*/
outportb(0x60,0x04);/*trigger the port*/
delay(5/1000); /*Delay according to of 5 microseconds*/
outportb(0x60,0x00); /* set the port to low*/
outportb(0x65,0x00);/* set the port to low*/
while(inportb(0x60)==0x00){
count=GetTickCount();
printf("PORT A: %X\n",count); /*read and print port A value*/
i=i+1;
if(i>=20)
break;
}
return 0 ;
}
1) You probably need a short delay after setting the port to low. I'd make it 50ms. If the PING is somehow falsely triggered while you're setting up things, this allows it to finish its cycle and become ready to be properly triggered.
2) The "delay" routine probably only allows integer arguments. Your "5 / 1000" is not legal. I don't know what it actually would do, but you're not going to get the 5us delay.
3) Again, you probably need a short delay after setting the port back to low after the pulse. The PING has a "hold off" period of about 750us before it sends its echo pulse and you want to wait at least 500us to 600us before looking for the pulse.
These microsecond delays can be done with a set of nested FOR loops, but you'll have to do some experimenting to see what the counts have to be. For example, the following will result in some delay:
Put this in a short program that displays a message before and after the loops and time the delay with a stopwatch. You may even need a 3rd loop around this to get enough of a delay to time by hand. Alternatively, you could use a delay like this to blink an LED and use a scope to time the pulses.