| View previous topic :: View next topic |
| Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 07, 2013 10:57 am |
|
|
| Post your current test program. |
|
 |
hamid9543
Joined: 31 Jan 2013 Posts: 63
|
|
Posted: Mon Jul 08, 2013 3:13 am |
|
|
thanx PCM programer
| Code: |
#Include <18f452.h>
#fuses HS,NOWDT
#use delay(clock=20000000)
//Define LCD ******************
#define LCD_RS_PIN PIN_b1
#define LCD_RW_PIN PIN_b2
#define LCD_ENABLE_PIN PIN_b3
#define LCD_DATA4 PIN_b4
#define LCD_DATA5 PIN_b5
#define LCD_DATA6 PIN_c6
#define LCD_DATA7 PIN_c7
#include <LCD.c>
#use i2c(Master,Fast,sda=PIN_c4,scl=PIN_c3)
// Define Reg L3G4200d*************
#define gyro_ADD_R 0xD3
#define gyro_ADD_W 0xD2
#define X_LSB 0x28
#define X_MSB 0x29
#define Y_LSB 0x2A
#define Y_MSB 0x2B
#define Z_LSB 0x2C
#define Z_MSB 0x2D
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24
#define FIFO_CTRL_REG 0x2E
#define OUT_TEMP 0x26
long value=0;
int8 M=0,L=0;
void writeRegister(int8 reg,int8 config)
{
i2c_start();
i2c_write(gyro_ADD_W);
i2c_write(reg);
i2c_write(config);
i2c_stop();
return;
}
void init_gyro()
{
writeRegister(CTRL_REG1,0b00001111);
writeRegister(CTRL_REG2,0b00101001);
writeRegister(CTRL_REG3,0b00001000);
writeRegister(CTRL_REG4,0b00100000); // 0x00-250dps, 0x10-500dps, 0x20-2000dps
//writeRegister(CTRL_REG5,0b00000000);
//writeRegister(FIFO_CTRL_REG,0b00000000);
return ;
}
void main()
{
printf(lcd_putc"\f");
init_gyro();
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc,"setup L3G4200D");
delay_ms(1000);
while(true)
{
i2c_start();
i2c_write(0xD2);
i2c_write(0x28);
i2c_start();
i2c_write(0xD3);
L=i2c_read();
M=i2c_read(0);
value=make16(M,L);
i2c_stop();
printf(lcd_putc"\f");
lcd_gotoxy(1,2);
printf(lcd_putc,"x=%Lu ",value);
delay_ms(1000);
}
}
|
|
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 08, 2013 5:11 pm |
|
|
The output values are signed. You have them as unsigned. That's part of
the reason why you get seemingly very large values like 63222.
You need to edit your code to use a signed long variable, and also to
display a signed long result. See the changes shown below:
| Quote: |
signed long value=0;
int8 M=0,L=0;
printf(lcd_putc"\f");
lcd_gotoxy(1,2);
printf(lcd_putc,"x=%ld ",value);
delay_ms(1000);
} |
|
|
 |
hamid9543
Joined: 31 Jan 2013 Posts: 63
|
| wonderful!! |
Posted: Mon Jul 08, 2013 9:43 pm |
|
|
hi
When I change the code below result is true!!!!!!!!!!!!!!!!!!!!!!!
| Code: |
signed long value=0;
int8 M=0,L=0;
while(true)
{
i2c_start();
i2c_write(0xD2);
i2c_write[b](0x2ِِD);[/b]
i2c_start();
i2c_write(0xD3);
L=i2c_read();
M=i2c_read(0);
value=make16(M,L);
i2c_stop();
printf(lcd_putc"\f");
lcd_gotoxy(1,2);
printf(lcd_putc,"x=%ld ",value);
delay_ms(500);
} |
If the correct code to use
.
.
.
i2c_write(0x2ِِC);
.
.
.
Standing still is the sensor but the output varies continuously
.
1)Is it because certain?
2)How to change the sensor output when the sensor is working properly |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 08, 2013 10:09 pm |
|
|
Did you build this L3G4200D board yourself, or did you buy a board ?
If you built it, post a link to your schematic. If you bought the board,
post a link to the website for it. |
|
 |
hamid9543
Joined: 31 Jan 2013 Posts: 63
|
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20161
|
|
Posted: Tue Jul 09, 2013 6:45 am |
|
|
What sort of power supply smoothing have you got on your processor board?.
I remember that board having problems on Arduino based systems, if the supply smoothing on the processor board was not very good. It uses a switching regulator to generate the 3.3v, and can introduce spikes back into the processor supply. People were having to put a low ESR electrolytic paralleled with a couple of ceramic capacitors at the connection to the processor board.
Best Wishes |
|
 |
hamid9543
Joined: 31 Jan 2013 Posts: 63
|
|
Posted: Tue Jul 09, 2013 7:47 am |
|
|
| Quote: | | People were having to put a low ESR electrolytic paralleled with a couple of ceramic capacitors at the connection to the processor board. |
no result.....
Please read before post.
When i read 0x29 or read 0x2D sensor working properly. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 09, 2013 12:57 pm |
|
|
You are fooling yourself. When you say "working properly", you mean
it has a very stable output.
Here is part of the register map, as shown on page 27 of the L3G4200D
data sheet:
| Code: |
Register Address Default value
OUT_Z_H 0x2D Z-axis msb
FIFO_CTRL_REG 0x2E 0x00
|
Your code always reads 2 bytes and it uses the first byte as the LSB
and the 2nd byte as the MSB. So when use register 0x2D as the
register address to read, your code will read 0x2D and then 0x2E.
But register 0x2E is not part of the Z-axis data. It's another completely
different register. It's the Fifo Control Register. It has a default value of 0x00.
So it's very likely that the MSB of the Z-axis value doesn't change very
much. In your test, the MSB becomes the "LSB" and the 0x00 from the
Fifo register becomes the "MSB". It's all fake. It's not real. You are
not reading both bytes of the Z-axis register.
Also, I don't have one of these L3G4200D to test. So all I can do is look
at the data sheet or other documentation. I can't tell you for sure what
the resting state output should be. However, you can search Google for
other people's projects. Do a search for this:
| Quote: | | l3g4200d stationary output |
Here's one of the search results:
http://ardadv.blogspot.com/2012/05/using-l3g4200d-with-arduino.html
Scroll down on that page and look at this graph of X, Y, Z axis response
vs. time. It has red, green, and blue lines. It's bouncing all over the
place. You need to filter the output. Either use built-in filters that are
in the chip or do some filtering in software. And remember, I don't have
one of these L3G4200D chips, so don't insist that I answer all questions on it. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20161
|
|
Posted: Tue Jul 09, 2013 2:57 pm |
|
|
On the Arduino, using these, the units are usually recommended to be mounted using 'moon gel', and a Kalman filter is applied to the data. The raw data _is_ noisy....
Best Wishes |
|
 |
|