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.

measuring angle with Accelerometer using pic16f887

Status
Not open for further replies.

prathap reddy

Newbie level 4
Newbie level 4
Joined
Jul 2, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,343
the following program based on using pic16f887 and adxl330 type accelerometer to measure the tilt angle and displayed on LCD.but i am unable to get output. can any one help?

sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
signed int x_acc,y_acc,z_acc;
signed int ZeroGx,OneGx,ZeroGy,OneGy;
signed int Counts_PerG_x,Counts_PerG_y;
float Gx,Gy,angle;
Read_Acceleration()
{
x_acc=Adc_Read(0);
y_acc=Adc_Read(1);
z_acc=Adc_Read(2);
}
Init_ADC()
{
ANSEL=0x07;
ANSELH=0;
TRISA=0x07;
ADCON0=0x81;
ADCON1=0x80;
}
void main()
{
Init_ADC();
Lcd_init();
ZeroGx=384;
OneGx=465;
ZeroGy=380;
OneGx=460;
Counts_PerG_x= OneGx -ZeroGx;
Counts_PerG_y= OneGy –ZeroGy;
for(;;)
{
Read_Acceleration();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"INCLINOMETER");
Gx=(float)(x_acc-ZeroGx)/ Counts_PerG_x;
Gy=(float)(y_acc-ZeroGy)/ Counts_PerG_y;
angle=atan2(Gy,Gx);
angle=angle*180.0/3.14;
FloatToStr(angle,txt+6);
Lcd_Out(2,1,txt);
Delay_Ms(500);
}
}
 

thank u for ur reply... compilation is successful but it gives DEMO LIMIT error.
 

quite easy.. I dont know what software you're using (mikroe C ???) but it seems that it is a demo version
and that you have made a program too big to be compiled under the demo version
buy the software and the error will disappear !
 
thank you very much...
now i have one more doubt.........
i did two modules individually..
1)ADC module
2) Accelerometer module(what i mentioned earlier)
now i want to combine these two modules and send result angle and digital info to main program. what are the modifications i need to do?...
the following code is my adc module.......
i am using mikro c only........
unsigned int temp_res;

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

char txt1[] = "ADC Example";
char txt[7];
void main() {
/////////// comment for 877/////////////////////////////////////
ansel=4; // Configure AN2 pin as analog
anselh=0;
c1on_bit=0;
c2on_bit=0;
////////////////////////////////////////////////////////////////
TRISA = 0xFF; // PORTA is input
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,txt1);
adc_init();
do {

temp_res = ADC_read(2); // Get 10-bit results of AD conversion
IntToStr(temp_res, txt); //int to string conversion
Lcd_Out(2,1,txt);
} while(1);
}

---------- Post added at 10:49 ---------- Previous post was at 10:18 ----------

my project is sign language to text translation for indian sign language by using 10 flex sensors, two accelerometers, pic 16f887
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top