Hallo, ich habe jetzt ein funktionierendes Programm:
Code:
$regfile = "m32def.dat"
$crystal = 16000000
$baud = 9600
$hwstack = 200
$swstack = 200
$framesize = 400
Config Portd.7 = Output
Config Sda = Portc.1
Config Scl = Portc.0
Config Twi = 100000
Declare Sub Read_gyro
Declare Sub Read_acc
Dim Tmp_gyrox(2) As Byte
Dim Tmp_gyroy(2) As Byte
Dim Tmp_gyroz(2) As Byte
Dim Tmp_accx(2) As Byte
Dim Tmp_accy(2) As Byte
Dim Tmp_accz(2) As Byte
Dim Gyrox As Integer
Dim Gyroy As Integer
Dim Gyroz As Integer
Dim Accx As Integer
Dim Accy As Integer
Dim Accz As Integer
Sound Portd.7 , 400 , 450
Sound Portd.7 , 400 , 250
Sound Portd.7 , 400 , 450
Wait 2
Print "Hallo"
Waitms 20
I2cinit
'--- (25) Sample Rate Divider = 1 ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 25 'Register 25 Sample Rate Divider (1..8 kHz)
I2cwbyte &B00000000 'Divider set to 1 (soll)
I2cstop 'stop condition
'--- (26) DLPF = 42/44 Hz ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 26 'Register 26 DLPF_CFG (digital lowpass filter) Configuration
I2cwbyte &B00000011 'Bits 0..2 = 011 (3) - ACC:44Hz, 4.9ms; Gyro:42Hz, 4.8ms
I2cstop 'stop condition
'--- (27) Gyro Full Range = +-2000°/s ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 27 'Register 27 Gyro Configuration
I2cwbyte &B00011000 'Bits 3+4 = 11 - Full Scale Range: +/-2000°/s
I2cstop 'stop condition
'--- (28) ACC Full Range = +-2g ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 28 'Register 28 ACC Configuration
I2cwbyte &B00000000 'Bits 3+4 = 00 - Full Scale Range: +/-2g / No High Pass Filter
I2cstop 'stop condition
'--- (107) Power Management 1 ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 107 'Register 107 Power Management 1
I2cwbyte &B00001011 'No Reset / No Sleep / No Cycle / Temp_Sens: Dis / Clock Source: Z-Gyro
I2cstop
Do
Call Read_gyro
Gyrox = Tmp_gyrox(1) + Tmp_gyrox(2)
Gyroy = Tmp_gyroy(1) + Tmp_gyroy(2)
Gyroz = Tmp_gyroz(1) + Tmp_gyroz(2)
Print "Gyrox :" ; Gyrox
Waitms 20
Print "Gyroy :" ; Gyroy
Waitms 20
Print "Gyroz :" ; Gyroz
Print
Waitms 100
Call Read_acc
Accx = Tmp_accx(1) + Tmp_accx(2)
Accy = Tmp_accy(1) + Tmp_accy(2)
Accz = Tmp_accz(1) + Tmp_accz(2)
Print "Accx :" ; Accx
Waitms 20
Print "Accy :" ; Accy
Waitms 20
Print "Accz :" ; Accz
Print
Print
Print
Wait 1
Loop
End
Sub Read_gyro()
I2cstart
I2cwbyte &HD0
I2cwbyte 67
I2crepstart
I2cwbyte &HD1
I2crbyte Tmp_gyrox(2) , Ack
I2crbyte Tmp_gyrox(1) , Ack
I2crbyte Tmp_gyroy(2) , Ack
I2crbyte Tmp_gyroy(1) , Ack
I2crbyte Tmp_gyroz(2) , Ack
I2crbyte Tmp_gyroz(1) , Nack
I2cstop
End Sub
Sub Read_acc()
I2cstart
I2cwbyte &HD0
I2cwbyte 59
I2crepstart
I2cwbyte &HD1
I2crbyte Tmp_accx(2) , Ack
I2crbyte Tmp_accx(1) , Ack
I2crbyte Tmp_accy(2) , Ack
I2crbyte Tmp_accy(1) , Ack
I2crbyte Tmp_accz(2) , Ack
I2crbyte Tmp_accz(1) , Nack
I2cstop
End Sub
Doch bekomme ich nur sinnlose Werte. Wie kann ich denn richtige Ergebnisse bekommen ? Soll ich mehrere Messungen machen und diese dann mitteln oder was ?
Kennt jemand ein Programm, dass die Daten graphisch darstellen kann ??
Lesezeichen