|
|
View previous topic :: View next topic |
Author |
Message |
rajm
Joined: 06 Nov 2012 Posts: 29
|
|
Posted: Fri May 03, 2013 3:58 am |
|
|
i cant understand about 1st header line (ie)
#include "C:\Users\semerci\Desktop\dddd\lcdddd.h". also tell me whether i can use #include<lcd.c> instead of flex lcd. in the imu.c there is no device address, it contains only register address..
im using PIC18f4550
regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Fri May 03, 2013 5:27 am |
|
|
Anyone else totally lost in this thread?
RAJM..
I suggest the following
Start over and keep code simple
1) download PCM programmers' I2C scanner diagnostic' program from the code library.
Install and run . It will tell you if your hardware is OK and that the PIC can 'see' the gyro module.There's no point trying anything until 'scanner' sees the module!
2) code only for 1 of the module functions(say gyroscope).Get it working properly.
3) once that's done, proceed to a 2nd function, again, get it working, confirming #1 still works.
4) now do the 3rd function,which should be a lot easier as the others all work fine!
I use the 4550 and flex_lcd without any problems.You do NOT need any interrupts so get rid any ISR code.The flex_lcd is easier to modify and use.
Query. Is the module designed for 5 volts as that PIC is a 5V product.
hth
jay |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
Posted: Fri May 03, 2013 6:07 am |
|
|
#include "C:\Users\semerci\Desktop\dddd\lcdddd.h".
it does not matter. instead of "include <PIC16F877A>". Add
I do not have PIC18F4550.
I'm sorry.
copy pasted the code is missing.
add them. imu.c
gyro_ADD_W = 11010110
gyro_ADD_R = 11010111
acce_ADD_W =00110010
acce_ADD_R =00110011
magn_ADD_W =00111100
magn_ADD_R =00111101
You can also use 2x lcd.
printf function 2x16 (etc.) .According to straighten lcd.c.
returns the code value. If you type returns the same value. If you can try your hand with 16F877. I tried it and it worked for me is just a 16F877. but the data is between 0 to 32000. the desired value for the mathematical operation is required.I add the code to the site I can arrange it |
|
|
rajm
Joined: 06 Nov 2012 Posts: 29
|
|
Posted: Fri May 03, 2013 11:06 pm |
|
|
hi
Code is giving error for me, even though i change header file as #include<18f4550.h>, every error by clicking them it shows error in the same header line. I can't understand for what you using tur and b and b+1 in I2c write function.
regards |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
Posted: Sat May 04, 2013 2:17 am |
|
|
tur = gyro_add_w ===> 0b11010110
Can you add your code |
|
|
rajm
Joined: 06 Nov 2012 Posts: 29
|
|
Posted: Sat May 04, 2013 3:43 am |
|
|
hi
i compiled without error, but i don't know what value should come in lcd. I'm getting 3 values of four digit no, but its getting flickering. I'm not able to see changes in values when i change sensor.
Kindly change my first code which i posted for gyro sensor, in that I'm getting only -1 as fixed without changing even i change my sensor.
regards |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
Posted: Sat May 04, 2013 7:55 am |
|
|
your code
add forum |
|
|
rajm
Joined: 06 Nov 2012 Posts: 29
|
|
Posted: Sun May 05, 2013 10:12 pm |
|
|
hi
I have used same code as you posted by deleting some printf statement.
Code: |
#include <18f4550.h>
#fuses NOWDT,HS
//#fuses HS,MCLR,NOWDT,NOPROTECT,NOLVP,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=4000000)
#use i2c(Master,sda=PIN_B0,scl=PIN_B1)
#define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_C0
#define LCD_RW_PIN PIN_C1
#define DATA_PORT PORTD
#include<lcd.c>
// #include <imu.C>
#define L3G_DEVICE_AUTO 0
#define L3G4200D_DEVICE 1
#define L3GD20_DEVICE 2
// SA0 states
#define L3G_SA0_LOW 0
#define L3G_SA0_HIGH 1
#define L3G_SA0_AUTO 2
// register addresses
#define gyro_ADD_W 0b11010110
#define gyro_ADD_R 0b11010111
#define L3G_WHO_AM_I 0x0F
#define L3G_CTRL_REG1 0x20
#define L3G_CTRL_REG2 0x21
#define L3G_CTRL_REG3 0x22
#define L3G_CTRL_REG4 0x23
#define L3G_CTRL_REG5 0x24
#define L3G_REFERENCE 0x25
#define L3G_OUT_TEMP 0x26
#define L3G_STATUS_REG 0x27
#define L3G_OUT_X_L 0x28
#define L3G_OUT_X_H 0x29
#define L3G_OUT_Y_L 0x2A
#define L3G_OUT_Y_H 0x2B
#define L3G_OUT_Z_L 0x2C
#define L3G_OUT_Z_H 0x2D
#define L3G_FIFO_CTRL_REG 0x2E
#define L3G_FIFO_SRC_REG 0x2F
#define L3G_INT1_CFG 0x30
#define L3G_INT1_SRC 0x31
#define L3G_INT1_THS_XH 0x32
#define L3G_INT1_THS_XL 0x33
#define L3G_INT1_THS_YH 0x34
#define L3G_INT1_THS_YL 0x35
#define L3G_INT1_THS_ZH 0x36
#define L3G_INT1_THS_ZL 0x37
#define L3G_INT1_DURATION 0x38
#define LSM303DLH_DEVICE 0
#define LSM303DLM_DEVICE 1
#define LSM303DLHC_DEVICE 2
#define LSM303_DEVICE_AUTO 3
// SA0_A states
#define LSM303_SA0_A_LOW 0
#define LSM303_SA0_A_HIGH 1
#define LSM303_SA0_A_AUTO 2
// register addresses
#define acce_ADD_W 0b00110010
#define acce_ADD_R 0b00110011
#define LSM303_CTRL_REG1_A 0x20
#define LSM303_CTRL_REG2_A 0x21
#define LSM303_CTRL_REG3_A 0x22
#define LSM303_CTRL_REG4_A 0x23
#define LSM303_CTRL_REG5_A 0x24
#define LSM303_CTRL_REG6_A 0x25
#define LSM303_REFERENCE_A 0x26
#define LSM303_STATUS_REG_A 0x27
#define LSM303_OUT_X_L_A 0x28
#define LSM303_OUT_X_H_A 0x29
#define LSM303_OUT_Y_L_A 0x2A
#define LSM303_OUT_Y_H_A 0x2B
#define LSM303_OUT_Z_L_A 0x2C
#define LSM303_OUT_Z_H_A 0x2D
#define LSM303_FIFO_CTRL_REG_A 0x2E
#define LSM303_FIFO_SRC_REG_A 0x2F
#define LSM303_INT1_CFG_A 0x30
#define LSM303_INT1_SRC_A 0x31
#define LSM303_INT1_THS_A 0x32
#define LSM303_INT1_DURATION_A 0x33
#define LSM303_INT2_CFG_A 0x34
#define LSM303_INT2_SRC_A 0x35
#define LSM303_INT2_THS_A 0x36
#define LSM303_INT2_DURATION_A 0x37
#define LSM303_CLICK_CFG_A 0x38
#define LSM303_CLICK_SRC_A 0x39
#define LSM303_CLICK_THS_A 0x3A
#define LSM303_TIME_LIMIT_A 0x3B
#define LSM303_TIME_LATENCY_A 0x3C
#define LSM303_TIME_WINDOW_A 0x3D
#define magn_ADD_W 0b00111100
#define magn_ADD_R 0b00111101
#define LSM303_CRA_REG_M 0x00
#define LSM303_CRB_REG_M 0x01
#define LSM303_MR_REG_M 0x02
#define LSM303_OUT_X_H_M 0x03
#define LSM303_OUT_X_L_M 0x04
#define LSM303_OUT_Y_H_M 0x05
#define LSM303_OUT_Y_L_M 0x06
#define LSM303_OUT_Z_H_M 0x07
#define LSM303_OUT_Z_L_M 0x08
#define LSM303_SR_REG_M 0x09
#define LSM303_IRA_REG_M 0x0A
#define LSM303_IRB_REG_M 0x0B
#define LSM303_IRC_REG_M 0x0C
#define LSM303_TEMP_OUT_H_M 0x31
#define LSM303_TEMP_OUT_L_M 0x32
int8 num=0, sensH=0,sensL=0;
signed long sens=0;
void writeRegister(int8 reg,int8 value,int addr)
{
i2c_start();
i2c_write(addr);
i2c_write(reg);
i2c_write(value);
i2c_stop();
}
void init_gyro()
{
writeRegister(L3G_CTRL_REG1,0b11101111,gyro_ADD_W);
writeRegister(L3G_CTRL_REG2,0b00000000,gyro_ADD_W);
writeRegister(L3G_CTRL_REG4,0b0010000,gyro_ADD_W);
}
void init_acce()
{
writeRegister(LSM303_CTRL_REG1_A,0x47,acce_ADD_W);
writeRegister(LSM303_CTRL_REG4_A,0b00101000,acce_ADD_W);
}
void init_magn()
{
writeRegister(LSM303_SR_REG_M, 0b00000001,magn_ADD_W);
writeRegister(LSM303_IRA_REG_M,0b01001000,magn_ADD_W);
writeRegister(LSM303_IRB_REG_M,0b00110100,magn_ADD_W);
writeRegister(LSM303_IRC_REG_M,0b00110011,magn_ADD_W);
writeRegister(LSM303_CRA_REG_M,0b10010000,magn_ADD_W);
writeRegister(LSM303_CRB_REG_M,0b10000000,magn_ADD_W);
writeRegister(LSM303_MR_REG_M, 0b00000000,magn_ADD_W);
}
int a;
void display(int adresR,int adresW) //adresR=device Read adres,adresW =device write adres
{
int i;
int b=0;
char c;
a=1;
for ( i=40;i<46;i+=2) //40=0x28 xHbit, 42=0x2b yHbit, 44=0x2d zHbit
{
b=i; //b=hbit, b+1=lbit. acce,gyro xHbit=0x28 xLbit=029
if (adresR==magn_ADD_R)
{
num=2;
b=i-37; //magnetometer xLbit=3 xHbit=4,yLbit=5 yHbit=6,zHbit=7,zHbit=8
c="m";
}
i2c_start();
i2c_write(adresW);
i2c_write(b);
i2c_start();
i2c_write(adresR);
sensH=i2c_read(),i2c_read(0);
i2c_stop(); //sensH=device x or y or z hbit
i2c_start();
i2c_write(adresW);
i2c_write(b+1);
i2c_start();
i2c_write(adresR);
sensL=i2c_read(),i2c_read(0);
i2c_stop(); //sensL=device x or y or z Lbit
sens=make16(sensH,sensL); //sens =long variable
if (adresR==acce_ADD_R)
{
num=3; //lcd line
sens=sens>>4; //Accelerometer: one 12-bit reading (left-justified) per axis
c="a";
}
if (adresR==gyro_ADD_R)
{
c="g";
num=4;
}
Lcd_gotoxy(num+8, 1);
printf(lcd_putc,"\%c",c);
Lcd_gotoxy(1, 1);
printf(lcd_putc,"satirlar="); //lcd 2x16 for num=1 or 2
Lcd_gotoxy(a, num); printf(lcd_putc,"\%Ld",sens);
a=a+6; //lcd row
}
}
void main()
{
set_tris_c(0xFE);
set_tris_D(0x00);
lcd_init();
printf(lcd_putc, "\f");
lcd_gotoxy(1, 1);
printf(lcd_putc, "minimu9 v2");
init_gyro();
init_acce();
init_magn();
lcd_init();
while(1)
{
display(gyro_ADD_R,gyro_ADD_W); // gyro
display(acce_ADD_R,acce_ADD_W); // accelometer
init_magn(); //to update
display(magn_ADD_R,magn_ADD_W); //compas
delay_ms(100);
printf(lcd_putc"\f");
}
}
|
Kindly help me, all the value getting changed and it not steady, its always flickering. Also help me to understand for loop.
regards |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
Posted: Mon May 06, 2013 2:35 am |
|
|
for ( i=40;i<46;i+=2)
b=i ====> 40===> 0x28 ===> (acceXlow LSM303_OUT_X_L_A 0x28)or(gyroXlow L3G_OUT_X_L 0x28)
b+1 ====> 41===> 0x29 ===> (acceXlow LSM303_OUT_X_L_A 0x29 )or(gyroXlow L3G_OUT_X_L 0x29 )
variable c = m(magnetometer) or a(accelometer) or g(gyroscope)
variable a = lcd coloumn
variable num = lcd line (my lcd has 4 line)(your lcd has 2 line) num = max 2 or Lcd_gotoxy(a, 1); Lcd_gotoxy([coloumn, line);
you can delete(
num=2; and num=3; and num=4;
Lcd_gotoxy(num+8, 1);
printf(lcd_putc,"\%c",c);
Lcd_gotoxy(1, 1);
printf(lcd_putc,"satirlar=");)
add
Lcd_gotoxy(a, 1); printf(lcd_putc,"\%Ld",sens);
cast gyro
display(gyro_ADD_R,gyro_ADD_W);
/* display(acce_ADD_R,acce_ADD_W);
init_magn();
display(magn_ADD_R,magn_ADD_W);
*/
I'm sorry if I'm rude wrote.
I do not know English. I am writing the message using Google Translate.
Last edited by vrs on Mon May 06, 2013 3:59 am; edited 1 time in total |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
Posted: Mon May 06, 2013 3:02 am |
|
|
//cast gyro
sensH=0,sensL=0;
signed long sens=0;
void writeRegister(int8 reg,int8 value,int addr)
{
i2c_start();
i2c_write(addr);
i2c_write(reg);
i2c_write(value);
i2c_stop();
}
void init_gyro()
{
writeRegister(L3G_CTRL_REG1,0b11101111,gyro_ADD_W);
writeRegister(L3G_CTRL_REG2,0b00000000,gyro_ADD_W);
writeRegister(L3G_CTRL_REG4,0b0010000,gyro_ADD_W);
}
int a;
void display(int adresR,int adresW)
{
int i;
a=0;
for ( i=40;i<46;i+=2)
{
i2c_start(); //high adres read
i2c_write(adresW);
i2c_write(i);
i2c_start();
i2c_write(adresR);
sensH=i2c_read(),i2c_read(0);
i2c_stop();
i2c_start(); //low adres read
i2c_write(adresW);
i2c_write(i+1);
i2c_start();
i2c_write(adresR);
sensL=i2c_read(),i2c_read(0);
i2c_stop();
sens=make16(sensH,sensL); //high + low adress
if (sens>=0)
{Lcd_gotoxy(a+1, 2); printf(lcd_putc,"\%Ld",sens);}
else{Lcd_gotoxy(a, 2); printf(lcd_putc,"\%Ld",sens);}
a=a+6; //lcd coloumn
}
}
void main()
{
set_tris_c(0xFE);
set_tris_D(0x00);
lcd_init();
printf(lcd_putc, "\f");
lcd_gotoxy(1, 1);
printf(lcd_putc, "minimu9 v2");
init_gyro();
while(1)
{
display(gyro_ADD_R,gyro_ADD_W); // gyro
delay_ms(100);
printf(lcd_putc"\f");
lcd_gotoxy(1, 1);
printf(lcd_putc, " X Y Z");
}
} |
|
|
rajm
Joined: 06 Nov 2012 Posts: 29
|
|
Posted: Mon May 06, 2013 4:17 am |
|
|
hi
I have tried another code which you posted in the thread minIMu9v2 problem for all three sensor, it shows value with light flickering and i can able to see the changes in the value as i change the sensor. Kindly say what is the difference between two code. the code in the link http://www.ccsinfo.com/forum/viewtopic.php?t=50012&highlight=minimu9
displays result for three axis as separate for 3 sensor, but in the latest code it shows only 3 values with 4 digit.
Kindly suggest which code to use.
regards |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
Posted: Mon May 06, 2013 9:20 am |
|
|
hi
last code for just gyro. and for 2 line lcd.
is as follows screenshot.
Code: |
line 1 X Y Z
line 2 32000_32000_32000
|
|
|
|
rajm
Joined: 06 Nov 2012 Posts: 29
|
|
Posted: Tue May 07, 2013 9:50 pm |
|
|
hi
The gyro code which you posted shows result with lot of flickering and changes without changing the sensor. What to do for this?
regards |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|