Can't seem to wrap my head around this new sensor. Here's the best description of this sensor's operation yet:
"A short ultrasonic pulse is transmitted at the time T1, reflected by an object. The senor receives this signal and converts it to an electric signal. The next pulse can be transmitted when the echo is faded away. This time period is called cycle period. The recommend cycle period should be no less than 10ms. If a 10μs width trigger pulse is sent to the signal pin, the Ultrasonic module will output some 40kHz ultrasonic signal and detect the echo back, each back pulse width is 150us so there is different to HC-SR04 module.The measured distance we can’t use the echo pulse width to calculate by the formula, but can be calculated by
Formula: distance = (T2 – T1 – 250Us) * (High speed of sound(340M/S)) / 2 // 250us is circuit delay’s time.
The arduino demo you can reference to HC-SR04, but you should note that transmitted signal is LOW to HIGH trigger and you should not use pulseIn() function for the pulse width, however you need start a Timer for count T1 and T2."
I also have this from what seems to be the manufacturer:
Main technical parameters:
1: Voltage: DC3.8-5.5V
2: Static current: less than 8mA
3: Output TTL level
5: Detection Range: 0cm-1500mm 6: High Accuracy: up to 3mm
(2) the module automatically sends eight 40khz square wave, automatically detects whether a signal retur(3) a signal back, through the ECHO output 10 signal, TRIG = 1 to the ECHO is the ultrasonic duration of time from launch to return. Test distance = (time * High speed of sound (340M / S)) / 2;
(4) When the TRIG from 0 -> 1, the main control panel starts a timer to control the 10ms timeout control measurements, the time when the timeout 10ms 150us ECHO 0 still no signal that there is no obstacle.
Module main features:
(1) ultra-miniature, only the equivalent of two transmitting and receiving the first of the area, has been unable to be small.
(2) blind spot (8mm, forming a triangle within the larger error).
(3) fast response, 10ms measurement period, not easy to lose high-speed targets.
(4) transmitting the first, receiving the first close, and the measured linear relationship between the basic objectives (8mm or large within the triangle, this is the transmitting and receiving first determined the physical shape).
(5) module has LED indication, easy to observe and test!
- Sensor is activated with a trigger pulse >=10uS at logic LOW.
- The echo pin remains high until timeout (10ms) or the reflected sonar pulses are received.
- If an echo is heard, the echo pin will be held low for 150uS.
- If timeout occurs, the echo pin will be held down for 10mS.
This is the code I've been tinkering on for a PICAXE 20X2:
#no_data
#no_table
symbol trig = C.2 'Define output pin for Trigger pulse
symbol echo = B.1 'Define input pin for Echo pulse, also interrupt pin
symbol echo_pin = pinB.1 'for use in timeout sequence
symbol IntCheck = bit0
symbol range = w1 '16 bit word variable for range
symbol R1 = C.7 'motor vars
symbol R2 = C.6
symbol L1 = C.4
symbol L2 = C.3
symbol ServoPin = B.0 'B.2 for testing
symbol piezo = C.0
symbol T1 = w2 '4-5
symbol T2 = w3 '6-7
symbol T3 = w4 '8-9
symbol T4 = w5 '10-11
high trig 'set trigger pin high
sensor_start:
DEBUG
wait 1
hintsetup %00000010 ; enable INT1 only, falling edge trigger
setintflags %00000010,%00000010 'activate INT1
timer3 = 0 'reset timer var
tmr3setup %10010001 'activate background timer3, 1:2 prescalar = 1uS/increment
low trig 'low to activate sensor
pauseus 2 'equals 2 * 10uS
high trig
T1 = timer3 'start time for distance calculations
sensor_dist:
if IntCheck = 0 then goto sensor_dist 'IntCheck = 1 when interrupt runs, stops loop
IntCheck = 0 'resets var after interrupt
if range = 9999 then goto sensor_start 'interrupt sub returns range=9999 if timeout occurs
T3 = T2 - T1- 250 'time between sending and receiving sonar signal
T4 = T3 * 1000 'picaxe sucks at math
T4 = T4/135
range = T4/2 'approximate calc for inch/second
goto sensor_start
interrupt:
T2 = timer3 'time when reflection is received
pauseus 15 'length of non-timeout pulsewidth = 150uS
if echo_pin = 0 then 'if echo_pin is still low, timeout occurred, ie no object found
range = 9999 'value for timeout condition
endif
IntCheck = 1 'stops sensor_distance goto loop
hint1flag =0 'reset INT1 flag
DEBUG
return
The major problem I'm facing is the interrupt never gets triggered by a falling edge and the program loops the "sensor_dist" subroutine. It only refreshes the debug terminal once so I know it never gets to the second debug in the interrupt sub.
Any input valued, thanks.