PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Probleme mit SRF10



PhilippW
05.01.2006, 18:31
Hallo!

Ich hab mir neulich SRF10-Module von Roboter-teile.de (danke Jörg für die schnelle Lieferung :-)) bestellt und diese an meine C-Control angeschlossen, doch irgendwie wollen die nicht so richtig...
Durch die Informationen, die hier im Roboternetz und im Internet zu finden sind, habe ich es zumindest schon geschafft, eine Messung zu starten, nur das Auslesen der Register will noch nicht so richtig.
Mal kommen relativ gut aussehende Werte aus dem Low-Byte und mal sind es nur Nullen. High ist ständig 0.
Am I²C-Bus kann es nicht liegen, da mein Kompass-Modul dort problemlos funktioniert...

Vielleicht habt ihr ja noch ne Idee...

Danke schon mal im Voraus.

Mit freundlichen Grüßen

Philipp


Hier der Code:



Define SDA Port[3]
Define SCL Port[4]

Define I Byte
Define I2C_Daten Byte
Define I2C_Zaehler Byte

SDA = On
SCL = On


gosub I2C_Start
I2C_Daten = 224
gosub I2C_Write
I2C_Daten = 2
gosub I2C_Write
I2C_Daten = 100 'Range
gosub I2C_Write
gosub I2C_Stop

gosub I2C_Start
I2C_Daten = 224
gosub I2C_Write
I2C_Daten = 1
gosub I2C_Write
I2C_Daten = 1 'Gain
gosub I2C_Write
gosub I2C_Stop

#Loop

gosub I2C_Start
I2C_Daten = 224
gosub I2C_Write
I2C_Daten = 0
gosub I2C_Write
I2C_Daten = 81
gosub I2C_Write
gosub I2C_Stop

Pause 10

gosub I2C_Start
I2C_Daten = 224
gosub I2C_Write
I2C_Daten = 3
gosub I2C_Write
gosub I2C_Stop
gosub I2C_Start
I2C_Daten = 225
gosub I2C_Write
gosub I2C_Read
Print I2C_Daten 'LOW
gosub NoAck
gosub I2C_Stop

gosub I2C_Start
I2C_Daten = 224
gosub I2C_Write
I2C_Daten = 2
gosub I2C_Write
gosub I2C_Stop
gosub I2C_Start
I2C_Daten = 225
gosub I2C_Write
gosub I2C_Read
Print I2C_Daten 'HIGH
gosub NoAck
gosub I2C_Stop

Goto Loop


'********************* I²C Standardroutinen*******************
#I2C_Start
SDA = OFF
SCL = OFF
return

#I2C_Stop
SDA = OFF
SCL = ON
SDA = ON
return

#I2C_Write
for i = 1 to 8
SDA = OFF
if (I2C_Daten and 128) = 128 then SDA = ON
pulse SCL
I2C_Daten = I2C_Daten shl 1 '1 Bit nach links schieben
next
pulse SCL
return

#I2C_Read
I2C_Daten = 0
deact SDA
for i = 1 to 8
I2C_Daten = I2C_Daten shl 1
SCL = ON
if SDA then I2C_Daten=I2C_Daten + 1
SCL = OFF
next
return

#Ack
SDA = 0
pulse SCL
return

#NoAck
SDA = 1
pulse SCL
return

PhilippW
05.01.2006, 22:01
Ich hab irgendwie das Gefühl, das es mit der Ack, bzw. NoAck-Sache zusammenhängt...
Hat nicht irgendeiner ne Idee? Ich hab schon alles ausprobiert, aber nichts hilft...

Manf
05.01.2006, 22:42
Hast Du es hiermit schon verglichen?
Manfred

http://www.the-starbearer.de/Praxis/Microkontrollerpraxis/ccontrol/CControl-I%B2C.htm#icdigital

PhilippW
05.01.2006, 22:48
Ja... vom Inhalt in der For-Schleife ist es mit meinem Programm soweit identisch... es will aber irgendwie nicht funktionieren...

m.a.r.v.i.n
06.01.2006, 08:44
Hallo Philipp,

nach dem Start der Messung muß man beim SRF10 70ms warten, bis das gültige Ergebnis vorliegt. Ich kenn die C-Control nicht so gut, bedeutet 'Pause 10' 10ms warten?

Gruß Peter

PhilippW
06.01.2006, 10:11
Hallo!



nach dem Start der Messung muß man beim SRF10 70ms warten, bis das gültige Ergebnis vorliegt. Ich kenn die C-Control nicht so gut, bedeutet 'Pause 10' 10ms warten?

Pause 10 bedeutet soweit ich weiß, dass er 10 mal den internen Timer (20ms) durchläuft...
Bei Pause 50 stoppt das Programm dann für eine Sekunde...

Philipp

Suggarman
06.01.2006, 10:13
Ich kenn die C-Control nicht so gut, bedeutet 'Pause 10' 10ms warten?


Nein, es sind 10*20ms.

mfg

Stefan

PicNick
06.01.2006, 11:21
Vergleich einmal mit dem Beispiel. Und zwar wegen der Reihenfolge der abfragen (SFR08 /SFR10 = jacke wie hose)
Du holst, glaub ich low und high einzeln ab. das wär nicht so gut.

https://www.roboternetz.de/wissen/index.php/Sensorarten#SRF08_Programmbeispiel

PhilippW
06.01.2006, 13:48
Hallo, Robert!


Du holst, glaub ich low und high einzeln ab. das wär nicht so gut.

Ich hab mir noch mal dein Beispiel von hier (https://www.roboternetz.de/phpBB2/zeigebeitrag.php?t=7564&highlight=srf10) angesehen und den Inhalt im Loop folgendermaßen verändert:



gosub I2C_Start
I2C_Daten = 224
gosub I2C_Write
I2C_Daten = 0
gosub I2C_Write
I2C_Daten = 81
gosub I2C_Write
gosub I2C_Stop

Pause 20

gosub I2C_Start
I2C_Daten = 224
gosub I2C_Write
I2C_Daten = 2
gosub I2C_Write
gosub I2C_Stop
gosub I2C_Start
I2C_Daten = 225
gosub I2C_Write
gosub I2C_Read
gosub Ack
Print I2C_Daten 'High
gosub I2C_Read
gosub NoAck
Print I2C_Daten 'Low
gosub I2C_Stop


Nun fragt das Programm nicht mehr getrennt ab, es kommen aber überwiegend Nullen zurück...
Erst wenn ich mit meiner Hand nah über den Sensor gehe, ändern sich die Werte im Low-Byte auf Zahlen bis etwa 20...
High ist weiterhin 0.

PicNick
06.01.2006, 16:39
Du mußt mal schauen/messen ob "Hand ganz nahe" nicht vielleicht eh' etwa 20 Zentimeter sind.
Ich würde mir die Sache mit "Range" u. "Gain" im DS mal genau anschauen, Vielleicht ist der Junge einfach schwerhörig

PicNick
06.01.2006, 16:45
Ich les grad' nach, da steht, man solle eher mit höherem Gain beginnen und dann solange herabsetzen, bis er nicht mehr jeden Furz mißt, sondern nurmehr interessante Objekte

PhilippW
06.01.2006, 16:49
Nun, die Werte ändern sich zwar mit der Entfernung der Hand, haben aber nichts mit der wirklichen Entfernung zu tun...
Range wird als 100 und Gain als 1 bei jedem Programmstart eingestellt.
Der Entfernungswert steht aber nur im Low-Byte...
Auffällig ist auch, dass die meisten Rückgabewerte 0 (im High- als auch im Low-Byte) sind und zwischendurch besagte Werte kommen.

PhilippW
06.01.2006, 17:07
Ich les grad' nach, da steht, man solle eher mit höherem Gain beginnen und dann solange herabsetzen, bis er nicht mehr jeden Furz mißt, sondern nurmehr interessante Objekte

Ich hab jetzt mal Range auf 255 und Gain auf 16 gesetzt... Maximalwerte also.
Die Nullen bleiben zu meiner Verwunderung (im Low-Byte) aus und die gegebenen Werte entsprechen auch der tatsächlichen Entfernung (hab mit nem Lineal gemessen).
Nur im High-Byte ändert sich nichts. Dort werden weiterhin nur Nullen ausgegeben...

PicNick
06.01.2006, 17:09
Naja, Moment. Das low Byte reicht ja immerhin für 2,5 m. Welche Reichweite soll der Seppel denn haben ?

PhilippW
06.01.2006, 17:26
Naja, Moment. Das low Byte reicht ja immerhin für 2,5 m. Welche Reichweite soll der Seppel denn haben ?

Also das Gerät selbst kann ja bis zu 6m messen...
Mir würden aber Entfernungen bis 3m schon reichen... je mehr, desto besser...
Wenn ich das Ding mit Maximalwerten betreibe, ergeben sich keine Werte über etwa 190 im Low-Byte.
Das bedeutet ja einerseits, dass High gar nicht erst über Null kommt, aber andererseits, dass Gegenstände im Raum den Schall wegen des breiten Winkels reflektieren...
Aber wie kann ich denn dann Entfernungen über 2,5 m messen? Das hängt doch dann mit der Verstärkung zusammen...

Ich glaub, solangsam wirds was... :-)

PicNick
06.01.2006, 17:44
In der Doku steht, man muß mit Gain und range rumprobieren
Range = 100 sollte für etwa 4,4 m reichen.
Jetzt mußt du wohl mit Gain rumwursteln.
Fang halt wirklich mit 16 an und geh dann runter

PhilippW
06.01.2006, 19:27
Ersteinmal danke für die Hilfe!

Ich hab jetzt ein wenig rumprobiert...
Geeinigt hab ich mich auf Range/Gain = 100/8.
Laut Datenblatt reicht das für etwa 2m...
Allerdings erhalte ich manchmal Werte von 135 im Low- und 1 im High-Register, was einer Entfernung von 3,91m (oder irre ich?) entsprechen würde...
Ich vermute, dass das irgendwie mit den Reflektionen am Fußboden zusammenhängt, da die Häufigkeit des Vorkommens dieser Werte steigt, je geringer der Winkel des Sensors zum Boden hin ist.

PicNick
07.01.2006, 10:02
..Reflektionen am Fußboden ..
Kann gut sein. IMHO sollte der Sensor nicht zu tief montiert sein. Der Schall reflektiert auf jedem Fliegenschiß

PhilippW
07.01.2006, 21:08
Das stimmt allerdings...

gordo
17.01.2006, 13:58
hab mit range und gain herumexperimentiert, allerdings kommen keine sinnvolen werte heraus. das lowbyte wandert zwischen 0 und 165. manchmal kommen aber ziemlich viele nullen hintereinander! lese die werte mit dem terminal programm von windows ein (bei 9600baud)

timing-probleme?!

ich verwende zur ansteuerung das programm von H.J. Windt
unter http://www.robot-electronics.co.uk/shop/Examples.htm


'----------------------------------------------------------------------------------------------------'
'************************************************* *********************'
'* WINDT SYSTEMS *'
'* SRF08 RANGE VIA EMULATED I2C BUS v1.3 for CCIUM2.01 with CCIAB2.0 *'
'* H.J. WINDT *'
'* 2005 *'
'************************************************* *********************'
'----------------------------------------------------------------------------------------------------'
'This software, with the C-Control I Unit M2.01 mounted on the C-Control I Application Board 2.0,'
'will fire the SRF08 and read the light-sensor and 1st range and display the data on the LCD'
'as Light and Range.'
'Communication with the SRF08 is via an emulated I2C bus, this is due to the fact that the'
'standard I2C "IIC" software for the CCIUM2.01 does NOT check for clock stretching!'
'The emulated SDA line is via port 4.'
'The emulated SCL line is via port 5.'
'Feel free to use and share this software!'
'----------------------------------------------------------------------------------------------------'
'**************** I/O PORTS ****************'
define sda port[4]
define scl port[5]
define lcd_light_off port[16]
'*******************************************'
'**************** VARIABLES ****************'
define control_flags byte[1]
define i2c_nack bit[1]
define i2c_last bit[2]
define i2c_nack_count byte[2]
define i2c_byte byte[3]
define i2c_out_bit bit[24]
define i2c_in_bit bit[17]
define loop byte[4]

define light byte[6]
define range word[4]
define range_high_byte byte[7]
define range_low_byte byte[8]
'*******************************************'
'**************** CONSTANTS ****************'
define srf08_gain 31 'SRF08 GAIN / DEFAULT = 31'
define srf08_range 255 'SRF08 RANGE / DEFAULT = 255'
'*******************************************'
'****************** SETUP ******************'
print"#ON_LCD#"; : print"#INIT#"; : print"#CLR#"; : print"#OFF#"; : lcd_light_off = off
print"#ON_CONFIG#"; : put &b1000 : print"#OFF#";
#try_again
gosub initialize_srf08
if i2c_nack then goto try_again
'*******************************************'
'***************** PROGRAM *****************'
#start
gosub get_srf08_range
if i2c_nack then goto start
print"#ON_LCD#";
print"#L101#";
print"Light = ";light;" ";
print"#L201#";
print"Range = ";range;"cm";" ";
print"#OFF#";
goto start
'*******************************************'
'*************** SUBROUTINES ***************'
#get_srf08_range
#fire_srf08
gosub start_i2c
i2c_byte = &he0 : gosub write_byte_i2c
i2c_byte = 0 : gosub write_byte_i2c
i2c_byte = &h51 : gosub write_byte_i2c
gosub stop_i2c
if i2c_nack_count > 100 then goto no_ack_from_srf08
if i2c_nack then goto fire_srf08
#read_light_and_range
#srf08_wait_and_setup
gosub start_i2c
i2c_byte = &he0 : gosub write_byte_i2c
i2c_byte = 1 : gosub write_byte_i2c
gosub stop_i2c
#pass_srf08_setup
if i2c_nack_count > 100 then goto no_ack_from_srf08
if i2c_nack then goto srf08_wait_and_setup
#read_srf08_data
gosub start_i2c
i2c_byte = &he1 : gosub write_byte_i2c
gosub read_byte_i2c : light = i2c_byte
gosub read_byte_i2c : range_high_byte = i2c_byte
gosub read_last_byte_i2c : range_low_byte = i2c_byte
gosub stop_i2c
if i2c_nack then goto pass_srf08_setup
return

#start_i2c
sda = 0 : scl = 0
return

#stop_i2c
sda = 0 : deact scl : deact sda
return

#write_byte_i2c
for loop = 1 to 8
sda = i2c_out_bit
deact scl
#write_byte_i2c_clock_stretch
if not scl then goto write_byte_i2c_clock_stretch
scl = 0
i2c_byte = i2c_byte shl 1
next
deact sda
deact scl
#write_byte_i2c_ack_clock_stretch
if not scl then goto write_byte_i2c_ack_clock_stretch
i2c_nack = sda
scl = 0
if i2c_nack then goto i2c_error
i2c_nack_count = 0
return
#i2c_error
i2c_nack_count = i2c_nack_count + 1
goto stop_i2c

#read_byte_i2c
i2c_last = 0
#get_i2c_byte
deact sda
for loop = 1 to 8
deact scl
#read_byte_i2c_clock_stretch
if not scl then goto read_byte_i2c_clock_stretch
i2c_in_bit = sda
scl = 0
if loop < 8 then i2c_byte = i2c_byte shl 1
next
if i2c_last then deact sda else sda = 0
deact scl
#read_byte_i2c_ack_clock_stretch
if not scl then goto read_byte_i2c_ack_clock_stretch
scl = 0
return

#read_last_byte_i2c
i2c_last = 1
goto get_i2c_byte
'*******************************************'
'******* INITIALIZATION SUBROUTINES ********'
#initialize_srf08
gosub start_i2c
i2c_byte = &b11100000 : gosub write_byte_i2c
i2c_byte = &b00000001 : gosub write_byte_i2c
i2c_byte = srf08_gain : gosub write_byte_i2c
i2c_byte = srf08_range : gosub write_byte_i2c
#pass_initialize_srf08
gosub stop_i2c
if i2c_nack_count > 16 then goto no_ack_from_srf08
if i2c_nack then goto initialize_srf08
return
'*******************************************'
'****************** DATA *******************'

'*******************************************'
'************* ERROR MESSAGES **************'
#no_ack_from_srf08
beep 1,1,1:beep 10,1,1:beep 1,1,1:beep 10,1,1
print"#ON_LCD#";
print"#CLR#";
print"E-I2C ERROR:";
print"#L201#";
print"SRF08 not found";
pause 300
print"#CLR#";
print"#OFF#";
return
'*******************************************'


wie kann ich low-byte und high-byte zusammenfassen und als einen wert an die serielle shcnittstelle zurückgeben.

ist es möglich einen 2ten SRF10 an dieselbe c-control anzuschliessen

gordo
17.01.2006, 14:02
hab jetzt folgende einstellung:

define srf08_gain 8 'SRF08 GAIN / DEFAULT = 31'
define srf08_range 255 'SRF08 RANGE / DEFAULT = 255'

und bekomme, wenn ich die hand davor halte, relativ vernünftie werte, jedoch eigentlich andauern Nullen?!!? stimmt die baudrate nicht?!

Windt H.J.
17.01.2006, 19:49
Hello,
The SRF08 program will NOT work with the SRF10!
That is why my example is called"SRF08 RANGE VIA EMULATED I2C BUS v1.3 for CCIUM2.01 with CCIAB2.0" and NOT "SRF10 RANGE......."
The SRF08 and SRF10 have different registers for reading in the range data
I am working on a program for the SRF10 and I’ll let you know when it is finished.


ist es möglich einen 2ten SRF10 an dieselbe c-control anzuschliessen

You can use 2 or more SRF08/10 on one I2C bus.
The I2C addresses are changeable but you will need to write a program for this.
Greetings,
H.J. Windt

gordo
18.01.2006, 10:49
when shit hits the fan...... i´m preparing an audio-installation where distances should be measured up to 10meters .. with the srf08 programm, the srf10 works, but measures only 2meters. and it´s really unstable. if there´s anybody in vienna who has a srf08, please contact me!

Windt H.J.
18.01.2006, 12:33
Hello,
I have created a few beta examples for the SRF10.
One version is for the C-Control I v1.1 and the other for the C-Control I v2.0
I changed the SRF08 example to hopefully work with the SRF10. [-o<
I am not able to test them at this time so let me know how they work. \:D/
Greetings,
H.J. Windt

P.S. One important thing to know about the SRF08 and SRF10:
If the range between an object and SRFxx is greater than the SRFxx can measure then the SRFxx will return with the range = 0.

gordo
18.01.2006, 12:53
thanks for the quick help!!!

i tried it with range 255 und gain 16 and i´m receiving only 40,41 on the serial port (replacing the print to lcd commands to "print range") because i dont have the application board. within 1meter distance i´m getting exact results!

i´m only using ccontrol m unit2.0. for reading data , i´m using hyperterminal with 9600baud, 8databits, no parity, 1stopbit

Windt H.J.
18.01.2006, 13:09
Hello,
One thing to remember is that the SRFxx’s have a wide range of “View”.
You will probably have to play around with the gain settings and or angle the SRF10 to get the results you want.
Also have a look at -->> http://www.robot-electronics.co.uk/htm/sonar_faq.htm
and -->> http://robot-electronics.co.uk/
Greetings,
H.J. Windt

gordo
18.01.2006, 13:35
hmmm. let me think. the sensor is fired into an empty hall. it is 1metre above the ground! no reflections in distance! i think there is some problem with interpreting the data?! maybe i´m getting only the data of the low_register?! ..hmm. i´m not an expert!

Windt H.J.
18.01.2006, 13:54
Hmmm.
This is interesting.
It could be that the srf10 is detecting the walls, floors, ceiling and or the edges of open or shut doorways, this because of the wide range of "View".
If it is possible, try firing the srf10 outside and see what happens.
Also try adding a pause in between the ranging cycles; it could be that the terminal program can’t handle the amount of data being sent.
I’ll also run thru my examples tonight to see if I made any mistakes.
Greetings,
H.J. Windt

Windt H.J.
23.01.2006, 21:24
Hello,
Has anybody had any success using the SRF10 and C-Control I v x.x?
It has become very quiet here. :-s
Greetings,
H.J. Windt

Frank
24.02.2006, 16:33
Ich habe auch nochmal ein SRF10 Bascom Programm für die RN-Control in RN-Wissen reingestellt:
https://www.roboternetz.de/wissen/index.php/Ultraschall_SRF10_an_RN-Control

Läßt sich sicherlich leicht auf andere AVR Boards übertragen