Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Gyroscope & Compass Readings not changing

Status
Not open for further replies.

nsparag

Newbie level 6
Joined
Aug 14, 2015
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
136
Hello

Im interfacing IMU gy80 module with TivaC board.
Accelerometer is working fine but Gyroscope & Compass Reading are not changing.

Could you please tel me the reason behind it?
 

Hi,

we can neither check your hardware nor check your code, as long as you don´t post it.

So I´ve googled and found a lot of "how to use GY80" guidelines. Did you read them?

Please provide more information.

Klaus
 

Re: Gyroscope & Compass Readings not changing

Hello
Hers my part of code..

---------------------------------------------------------------------------------
I'm initializing the L3G4200D gyrometer registers with following mentioned values

Code:
	writeI2C0(Gyro_ADDR,CTRL_REG1,0xCF);
	writeI2C0(Gyro_ADDR,CTRL_REG2,0x00);
	writeI2C0(Gyro_ADDR,CTRL_REG3,0x08);
	writeI2C0(Gyro_ADDR,CTRL_REG4,0x30);
	writeI2C0(Gyro_ADDR,CTRL_REG5,0x00);
---------------------------------------------------------------------------------


Code:
signed int getRotation_Y(){
	signed int short raw = (signed int short) getRotation_rawY();
	signed int Rotation = (signed int)raw;
	return Rotation;
}

uint16_t getRotation_rawY(){
	uint8_t rotData1, rotData2;
	rotData1=readI2C0(Gyro_ADDR,OUT_Y_L);
	rotData2=readI2C0(Gyro_ADDR,OUT_Y_H);
	uint16_t rawY = (rotData2<<8)|rotData1;
	return (rawY);
}


Code:
UART_OutUDec((unsigned int) rotationX)
{
  if(n >= 10){
    UART_OutUDec(n/10);
    n = n%10;
  }
  UART_OutChar(n+'0'); /* n is between 0 and 9 */
}
}
---------------------------------------------------------------------------------

[
 
Last edited by a moderator:

On Gyroscope & Compass Readings not changing continuously but when the device is power OFF and again ON that time readings before power OFF and after power ON are different.
BUT untill the device is powered off the readings will remain constant.

could you please suggest the reason for this?
 

Hi,

You give only snippets of your code, so we can´t see what else is happening.

Maybe you are reading to fast - fromone measurement to the other - and the gyro neet time vor a new conversion. But that´s only guessing.
Did you read the guidelines and/or other tutorials with code..

Did you read datasheet carefully?
You configure INT2 for DataReady, we can not see how you use it.
You configure it to the least sensitve range. Are you moving the gyro? Else there will be no change.

Klaus
 
Re: Gyroscope &amp; Compass Readings not changing

Hi,

Ya Im trying to read at 800Hz...but now changed to 100Hz...but still the same problem & Im configuring INT2 but I havent understood it properly. I read datasheet also but still in doubts.

Im thinking "when gyro will read data ie when data is available in output resistors, INT2 will be set"
so is it correct?

if 'yes' then when INT2 will be cleared ?


Code:
#include <stdint.h>
#include <stdbool.h>
#include "driverlib/sysctl.h"
#include "Nokia5110.h"
#include "L3G4200D_Gyroscope.h"
#include "inc/tm4c123gh6pm.h"
#include "UART.h"
#include "PLL.h"

int main (void)
{
	signed int rotationX, rotationY, rotationZ;
	
	// Set the clocking to run directly from the external crystal/oscillator.
	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_OSC_INT | SYSCTL_XTAL_16MHZ);
	UART_Init();
	PLL_Init();
	UART_OutString("Testing\r\n");
	init_L3G4200D_Gyroscope();

//	PortF_Init();

	SetPowerMode(0x01);
	
	int i,k,j=0;
	while(1){
		rotationX = getRotation_X();
		if (rotationX>=0) {
				UART_OutString("\r\nX Rot: ");
				UART_OutUDec((unsigned int) rotationX);
		} else {
				UART_OutString("\r\nX Rot*: -");
				UART_OutUDec((unsigned int) (rotationX*-1));
		}
          }

	return 0;
}


L3G4200D_Gyroscope.c
Code:
#include <stdint.h>
#include "Tiva_i2c.h"
#include "L3G4200D_Gyroscope.h"


void init_L3G4200D_Gyroscope(){
	initI2C0();
		writeI2C0(Gyro_ADDR,CTRL_REG1,0x0F);
		writeI2C0(Gyro_ADDR,CTRL_REG2,0x00);
		writeI2C0(Gyro_ADDR,CTRL_REG3,0x08);
		writeI2C0(Gyro_ADDR,CTRL_REG4,0x80);
		writeI2C0(Gyro_ADDR,CTRL_REG5,0x00);
}

void SetPowerMode(unsigned char powerMode) {
	uint8_t i2c_data = readI2C0(Gyro_ADDR,0x2d);
	if (powerMode==1){
		i2c_data = i2c_data | (powerMode<<3);
	} else if (powerMode==0){
		i2c_data &= ~(1<<3);
	}
	i2c_data = i2c_data | (powerMode<<3);
	writeI2C0(Gyro_ADDR,0x2d,i2c_data);
}


uint16_t getRotation_rawX(){
	uint16_t rotData1, rotData2;
	rotData1=readI2C0(Gyro_ADDR,OUT_X_L);
	rotData2=readI2C0(Gyro_ADDR,OUT_X_H);
		UART_OutString("\r\nX rotData1: ");
		UART_OutUDec(rotData1);
		UART_OutString("\r\nX rotData2: ");
		UART_OutUDec(rotData2);
	uint16_t	rawX = (rotData2<<8)|rotData1;
	UART_OutString("\r\nX rawX: ");
	UART_OutUDec(rawX);
	return (rawX);
}

signed int getRotation_X(){
	signed int short raw = (signed int short) getRotation_rawX();
	signed int Rotation = (signed int)raw;
	return Rotation;
}

Tiva_i2c.c"
Code:
#include <stdint.h>
#include <stdbool.h>
#include "Tiva_i2c.h"
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"

	#define GPIO_PB2_I2C0SCL        0x00010803
	#define GPIO_PB3_I2C0SDA        0x00010C03

void initI2C0(void)
{
	//This function is for eewiki and is to be updated to handle any port

	//enable I2C module
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

	//reset I2C module
	SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);

	//enable GPIO peripheral that contains I2C
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);


	// Configure the pin muxing for I2C0 functions on port B2 and B3.
	GPIOPinConfigure(GPIO_PB2_I2C0SCL);
	GPIOPinConfigure(GPIO_PB3_I2C0SDA);

	// Select the I2C function for these pins.
	GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
	GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

	// Enable and initialize the I2C0 master module.  Use the system clock for
	// the I2C0 module.  The last parameter sets the I2C data transfer rate.
	// If false the data rate is set to 100kbps and if true the data rate will
	// be set to 400kbps.
	I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);

	//clear I2C FIFOs
	HWREG(I2C0_BASE + I2C_O_FIFOCTL) = 80008000;
}

uint8_t readI2C0(uint16_t device_address, uint16_t device_register)
{
	//specify that we want to communicate to device address with an intended write to bus
	I2CMasterSlaveAddrSet(I2C0_BASE, device_address, false);

	//the register to be read
	I2CMasterDataPut(I2C0_BASE, device_register);

	//send control byte and register address byte to slave device
	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

	//wait for MCU to complete send transaction
	while(I2CMasterBusy(I2C0_BASE));

	//read from the specified slave device
	I2CMasterSlaveAddrSet(I2C0_BASE, device_address, true);

	//send control byte and read from the register from the MCU
	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

	//wait while checking for MCU to complete the transaction
	while(I2CMasterBusy(I2C0_BASE));

	//Get the data from the MCU register and return to caller
	return( I2CMasterDataGet(I2C0_BASE));
}

void writeI2C0(uint16_t device_address, uint16_t device_register, uint8_t device_data)
{
	//specify that we want to communicate to device address with an intended write to bus
	I2CMasterSlaveAddrSet(I2C0_BASE, device_address, false);

	//register to be read
	I2CMasterDataPut(I2C0_BASE, device_register);

	//send control byte and register address byte to slave device
	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

	//wait for MCU to finish transaction
	while(I2CMasterBusy(I2C0_BASE));

	I2CMasterSlaveAddrSet(I2C0_BASE, device_address, true);

	//specify data to be written to the above mentioned device_register
	I2CMasterDataPut(I2C0_BASE, device_data);

	//wait while checking for MCU to complete the transaction
	I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);

	//wait for MCU & device to complete transaction
	while(I2CMasterBusy(I2C0_BASE));
}

- - - Updated - - -

hi
At this condition I connected the INT2 pin to CRO and observed that it is always at SET value. it is not resetting at all.
 

Accelerometer Gyroscope Magnetometer Stand Still Readings

Hi

I'm using GY-80 (ADXL345, L3G4200D, HMC5883) module in my project.

I have some queries.

As the case in accelerometer when the device is kept stand still on a flat surface , it should read X : 0, Y : 0, Z : 980.

Similarly what are the values I should get for Gyroscope and Magnetometer.
Are X : 0, Y : 0, Z : 0 for Gyroscope and Magnetometer. ??

Please help me out.
 

Re: Accelerometer Gyroscope Magnetometer Stand Still Readings

Hi

in your other thread I wrote:
You configure it to the least sensitve range. Are you moving the gyro? Else there will be no change.

Klaus
 

hi

no, I'm not moving the gyro...So I should get X : 0, Y : 0, Z : 0 for Gyroscope...Right?

The HMC5883L datasheet says self test readings should lie between 243 & 575 at the mentioned conditions.
But I'm not getting readings in this range? What should I do. I'm even not moving the Magnetometer.
 

Hi,

What should I do. I'm even not moving the Magnetometer.

I want to help, but I find it difficult, because you don't give enough informations. So it's mostly guessing.

You should answer our questions.
You should give values instead of "I'm not getting readings in this range".
--> what "non selftest" ambient values do you read, what selftest values do you read?
You should move the gyro, just to test if the values are changing then.
You should more detailed tell about what you do, what you expect and what happens.
-->
I'm initializing the L3G4200D gyrometer registers with following mentioned values
. Your effort is some seconds to copy and past this code snippet. For us it takes long time to go through the datasheet to check every single bit. And even then we don't know if the setup is what you wanted.
Do you know the difference between gyro and compass?

Klaus
 

Hello..
first of all Please Excuse me ...

Please forget all the above discussion, ll start newly
I think it should be better if I clarify my all doubts of Compass. HMC5883L.

Compass is used to measure the strength of magnetic field.

I2C is configured to read at 100 Kbps

as per data sheet self test is performed
Configuration Register A = 0x71
-->no of samples averaged = 1
-->outout data rate = 1.5 Hz
Configuration Register B= 0xA0
-->Sensor Field ± 4.7 Ga
-->Gain = 390
Mode Register= 0x81
-->continuous measurement mode

again writing 0x00 to config_reg_A will stop the self test.
Code:
Self_test(){
	writeI2C0(Compass_ADDR,Config_Reg_A,0x71);
	writeI2C0(Compass_ADDR,Config_Reg_B,0xA0);
	writeI2C0(Compass_ADDR,Mode_Reg,0x00);
	delay();
                x = getMagField_rawX(); 
		y = getMagField_rawY();
		z = getMagField_rawZ();
	writeI2C0(Compass_ADDR,Config_Reg_A,0x00); 
}

after this I'm initializing compass
Code:
writeI2C0(Compass_ADDR,Config_Reg_A,0x00);
writeI2C0(Compass_ADDR,Config_Reg_B,0x20);
writeI2C0(Compass_ADDR,Mode_Reg,0x00);

Configuration Register A = 0x00
-->no of samples averaged = 1
-->outout data rate = 0.75Hz (lowest possible)
Configuration Register B= 0x20
-->Sensor Field ± 1.3 Ga Ga
-->Gain = 1090
-->digital resolution = 0.92 mG/LSB
Mode Register= 0x00
-->continuous measurement mode


The code I'm using

Code:
signed int magfieldX = getMagField_X();
		if (magfieldX>=0) {
				UART_OutString("\r\nX mField: ");
				UART_OutUDec((unsigned short) magfieldX);
		} else {
				UART_OutString("\r\nX mField: -");
				UART_OutUDec((unsigned short) (magfieldX*-1));
		}

Code:
signed int getMagField_X(){
	signed int short raw = (signed int short) getMagField_rawX();
	signed int data = (signed int)(((signed int)raw) * 0.92);	// 0.92 is Digital Resolution (mG/LSB)
 	return data;
}

Code:
uint16_t getMagField_rawX(){
	uint8_t mfData1, mfData2;
	mfData1=readI2C0(Compass_ADDR,HMC5883L_OUT_X_L);
	mfData2=readI2C0(Compass_ADDR,HMC5883L_OUT_X_H);
	uint16_t	rawX = (mfData2<<8)|mfData1;
	return (rawX);
}

---------------------------------------
I kept the compass stand still.
when I tried to read compass with self test conditions in while(1) loop I got

PHP:
x: 482
y: 445
z: 426
x: 482
y: 445
z: 426
x: 482
y: 445
z: 426
x: 482
y: 445
z: 426
x: 482
y: 445
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 447
z: 424
x: 482
y: 447
z: 424
x: 460
y: 65424
z: 98

and when I tried to read the compass in NON SELF TEST conditions I got
PHP:
X mField: 423
Y mField: -103
Z mField: 90
         trial  0
X mField: 423
Y mField: -103
Z mField: 90
         trial  1
X mField: 420
Y mField: -103
Z mField: 89
         trial  2
X mField: 421
Y mField: -104
Z mField: 86
         trial  3
X mField: 423
Y mField: -103
Z mField: 87
         trial  4
X mField: 421
Y mField: -103
Z mField: 88
         trial  5
X mField: 421
Y mField: -103
Z mField: 90
         trial  6
X mField: 421
Y mField: -105
Z mField: 88
         trial  7
X mField: 423
Y mField: -103
Z mField: 85
         trial  8
X mField: 423
Y mField: -105
Z mField: 86
         trial  9
X mField: 421
Y mField: -102
Z mField: 89
         trial  10
X mField: 418
Y mField: -106
Z mField: 88
         trial  11
X mField: 420
Y mField: -105
Z mField: 87
         trial  12
X mField: 420
Y mField: -105
Z mField: 87
         trial  13
X mField: 423
Y mField: -102
Z mField: 84
         trial  14
X mField: 424
Y mField: -103
Z mField: 87
         trial  15
X mField: 421
Y mField: -103
Z mField: 88
         trial  16
X mField: 421
Y mField: -104
Z mField: 86
         trial  17

So my doubts are
1. As mentioned in data sheet. the self test values should lie between 243 to 575.But some times the value is beyond the limits. What should I do to correct it.?
2. The NON-SELF test values are almost constant. But are these values correct ? How to find reference values. (By reference I mean as in case of accelerometer placed on X-Y plane, ideally it ll read X=0 Y=0 and Z=980(1g)).


Please let me know anything more required?
 

Correction in above post :
by mistake I wrote
Mode Register= 0x81

It should Be Mode Register= 0x00
 

Hi,

thanks for the detailed informations.

***

Configuration Register A = 0x71
-->no of samples averaged = 1
-->outout data rate = 1.5 Hz

0x71 = 0b 0111 0001 --> average of 8 samples, not 1!

***
general reading: synchronize with the sample rate of the gyro. Read DRDY status at least every 100us. Wait for a rising edge. Then read all six data registers.

***

selftsest:
* first read data without additional magnetic field, synchronized. Maybe multiple times
* then switch on additional magnetic field. Do some synced readings.
* then switch on reverse magnetic field. Do some synced readings.
* calculate the difference between tha values with and without additional field. Only the difference is of interest.

***

reading data during write of registers (RDY = 0) will give errors.
***

always read all six values:
When one or more of the output registers are read, new data cannot be placed in any of the output data registers until all six data output registers are read. This requirement also impacts DRDY and RDY, which cannot be cleared until new data is placed in all the output registers.

***

Klaus
 

Could you please elaborate

selftsest:
* first read data without additional magnetic field, synchronized. Maybe multiple times
* then switch on additional magnetic field. Do some synced readings.
* then switch on reverse magnetic field. Do some synced readings.
* calculate the difference between that values with and without additional field. Only the difference is of interest.

* what do you mean by "synchronized readings"
 
Last edited:

Hi,

There is a magnetic field of the earth. This is the ambient field you read in normal mode.

In selftest mode there is an additional field added to the earth field. In selftest you can not switch off the earth field, therefore both fields are added and thus both digital data values are added.
To see just the selftest magnetic field value you need to subtract selftest_measurement_value - normal_measurement_value.

Klaus
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top