-
'===CHIP SETTINGS===
-
$regfile = "m128def.dat"
-
$framesize = 320
-
$swstack = 160
-
$hwstack = 160
-
$crystal = 16000000
-
$baud1 = 38400
-
-
Config Scl = Portd.0
-
Config Sda = Portd.1
-
-
Open "COM2:" For Binary As #1
-
Const Mpuaddw = &B11010000 'AD0 auf Masse
-
Const Mpuaddr = &B11010001
-
'--MPU6000--
-
Dim Test As Byte
-
Dim Gyrox As Integer
-
Dim Gyroy As Integer
-
Dim Gyroz As Integer
-
Dim Tmp_gyrox(2) As Byte At Gyrox Overlay 'nick
-
Dim Tmp_gyroy(2) As Byte At Gyroy Overlay 'roll
-
Dim Tmp_gyroz(2) As Byte At Gyroz Overlay 'yaw
-
Dim Xacc_pre As Integer
-
Dim Yacc_pre As Integer
-
Dim Zacc_pre As Integer
-
Dim Tmp_accx(2) As Byte At Xacc_pre Overlay
-
Dim Tmp_accy(2) As Byte At Yacc_pre Overlay
-
Dim Tmp_accz(2) As Byte At Zacc_pre Overlay
-
Dim Meas_nick As Single
-
Dim Meas_roll As Single
-
Dim Yaw_gyro As Single
-
Dim Xacc As Single
-
Dim Yacc As Single
-
Dim Zacc As Single
-
-
Declare Sub Read_mpu
-
Declare Sub Init_mpu
-
-
I2cinit
-
-
-
-
Waitms 100
-
Init_mpu
-
Print #1 , "OK";
-
-
-
-
-
Do
-
Read_mpu
-
-
Waitms 250
-
-
Print #1 , "$" ; Meas_nick;
-
Loop
-
-
End
-
-
Sub Init_mpu
-
I2cstart 'start condition
-
I2cwbyte Mpuaddw 'write adress of MPU-6050
-
I2cwbyte 117 'Register 117 "Who am I"
-
I2crepstart 'repeated start
-
I2cwbyte Mpuaddr 'read adress of MPU-6050
-
I2crbyte Test , Nack 'read byte WHO_AM_I (Reg 117)
-
I2cstop 'stop condition
-
I2cstart 'start condition
-
I2cwbyte Mpuaddw 'write adress of MPU-6050
-
I2cwbyte 25 'Register 25 Sample Rate Divider (1..8 kHz)
-
'mal spielen...
-
'&B00000001 wäre 500 Hz
-
I2cwbyte &B00000000 'Divider set to 1 (soll)
-
I2cstop 'stop condition
-
'Low pass filter
-
'0=256Hz &B00000000
-
'1 = 188hz &B00000001
-
'2 = 98hz &B00000010
-
'3 = 42hz &B00000011
-
'4 = 20hz &B00000100
-
'5 = 10hz &B00000101
-
'6 = 5hz &B00000110
-
I2cstart 'start condition
-
I2cwbyte Mpuaddw 'write adress of MPU-6050
-
I2cwbyte 26 'Register 26 DLPF_CFG (digital lowpass filter) Configuration
-
I2cwbyte &B00000011 'Bits 0..2 = 000 - ACC:260Hz, 0.0ms; Gyro:256Hz, 0.98ms ( &B00000000 )
-
I2cstop 'stop condition
-
'42hz scheint gut
-
'gyro full range
-
'250°/s &B00000000
-
'500°/s &B00001000
-
'1000°/s &B00010000
-
'2000°/s &B00011000
-
-
I2cstart 'start condition
-
I2cwbyte Mpuaddw 'write adress of MPU-6050
-
I2cwbyte 27 'Register 27 Gyro Configuration
-
I2cwbyte &B00011000 'Bits 3+4 = 00 - Full Scale Range: +/-250°/s
-
I2cstop 'stop condition
-
'ACC full range
-
'+-2g &B00000000
-
'+-4g &B00001000
-
I2cstart 'start condition
-
I2cwbyte Mpuaddw 'write adress of MPU-6050
-
I2cwbyte 28 'Register 28 ACC Configuration
-
'set to +-8g?
-
'&B00000000 = 2g
-
'&B00001000 = 4g
-
'&B00010000 = 8g
-
'&B00011000 = 16g
-
I2cwbyte &B00000000 'Bits 3+4 = 00 - Full Scale Range: +/-2g / No High Pass Filter
-
I2cstop 'stop condition
-
I2cstart 'start condition
-
I2cwbyte Mpuaddw 'write adress of MPU-6050
-
I2cwbyte 107 'Register 107 Power Management 1
-
'temp enabled: &B00000011
-
'temp disabled: &B00001011
-
I2cwbyte &B00000011 'No Reset / No Sleep / No Cycle / Temp_Sens: Dis / Clock Source: Z-Gyro
-
I2cstop
-
End Sub
-
-
Sub Read_mpu
-
I2cstart 'X ACC
-
I2cwbyte Mpuaddw
-
I2cwbyte 59
-
I2crepstart
-
I2cwbyte Mpuaddr
-
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
-
I2cstart 'X GYRO
-
I2cwbyte Mpuaddw
-
I2cwbyte 67
-
I2crepstart
-
I2cwbyte Mpuaddr
-
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
-
' Shift xAcc , Right , 5 , Signed '+-1024 bei 2g
-
' Shift yAcc , Right , 5 , Signed
-
' Shift zAcc , Right , 5 , Signed
-
' Shift Meas_nick , Right , 5 , Signed '+-1024 bei 250°/s
-
' Shift Meas_roll , Right , 5 , Signed
-
' Shift Yaw_gyro , Right , 5 , Signed
-
'Meas_nick = Gyrox / 76.8 '65536/1024/(300/250) MPU gyro scaling equals adxrs300 scaling
-
'Meas_roll = Gyroy / 76.8
-
'Yaw_gyro = Gyroz / 76.8
-
' Meas_nick = Gyrox / 38.4 'bei 500°/s
-
' Meas_roll = Gyroy / 38.4
-
' Yaw_gyro = Gyroz / 38.4
-
Meas_nick = Gyrox / 8.7 'bei 2000°/s
-
Meas_roll = Gyroy / 8.7
-
Yaw_gyro = Gyroz / -8.7
-
-
Xacc = Xacc_pre '65536/1024 MPU acc scaling equals ADXL322 scaling
-
Yacc = Yacc_pre
-
Zacc = Zacc_pre
-
-
-
End Sub