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.

ultrasonic range finder problem

Status
Not open for further replies.

cheenu02

Junior Member level 3
Joined
Jun 16, 2011
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,500
Hi,
I am doing ultrasonic range finder project using pic18f4552.while reading the values through serial port I am getting some error values like this
272
272
272
272
10
272
10
272
272
10
I dont know why this 10 comes.My ultrasonic module is Ts601.I attached the data sheet of Ts1601.Please help me
 

Attachments

  • Range_Finder.pdf
    256.2 KB · Views: 65

Which platform you receive? Show on hyperterminal or VB?
 

while reading the values through serial port I am getting some error values like this
Your report is incomprehensible. According to the datasheet, the said ultrasonic module hasn't a serial output.
 

hi,
This is my program.I am using PICC(CCSC) compiler

Code:
#include<18f452.h>
#fuses HS,NOWDT,NOLVP,NOPROTECT
#use delay(clock=12000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

#define rs PIN_C0
#define rw PIN_C1
#define en PIN_C2

void signal()
{
	output_low(PIN_B0);
	delay_us(2);
	output_high(PIN_B0);
	delay_us(5);
	output_low(PIN_B0);
}

void lcd_command(int16 command)
{
   output_d(command);
   delay_ms(50);
   output_low(rs);
   output_low(rw);
   output_high(en);
   delay_cycles(1);
   output_low(en);
}

void lcd_data(int16 data)
{
   output_d(data);
   delay_ms(50);
   output_high(rs);
   output_low(rw);
   output_high(en);
   delay_cycles(1);
   output_low(en);
}

void hex2dec(float value)
{
	int16 x,f1,f2,d1,d2,d3,int_val;
	float float_val;
	float_val=value+0.2;
	int_val=(int16)value+1;

	lcd_command(0x80);
   	lcd_data('v');
   	lcd_data('=');
	
	/*****************************************
		 Integer value calculation
	*****************************************/
   	x=int_val/10;          //102       
   	//d4=value%10;         //3
   	d3=int_val%10;    //2
   	d2=x%10;        //0
   	d1=x/10;        //1 

	lcd_command(0x82);
   	lcd_data(d1+48);
   	lcd_data(d2+48);
	lcd_data(d3+48);

	lcd_command(0x85);	
	lcd_data('.');
	
	/*****************************************
		Float value calculation
	*****************************************/
	f1=(int16)(float_val*10)%10;
	f2=(int16)(float_val*100)%10;
   
   	lcd_command(0x86);
	lcd_data(f1+48);
	lcd_data(f2+48);

	lcd_command(0x88);
	lcd_data('c');
   	lcd_data('m');
   	//lcd_data(d3+48);
   	//lcd_data(d4+48);
}
int16 range()
{
	int16 count=0;
	int1 state;

	set_tris_b(0x00);		//make PIB_B0 output
    signal();				//Trigger Ultrasonic*/
		
	set_tris_b(0xff);		//make PIN_B0 input

	while(state==0)
	{
		delay_cycles(2);
		state=input_state(PIN_B0);
	}
	while(state==1)
	{
		count++;
		delay_cycles(2);
		state=input_state(PIN_B0);
		delay_cycles(2);
	}
	//if(count>10)
	{
		printf("count=%ld\r\n",count);
		return(count);
	}
}
void main()
{
	float distance, value;
	lcd_command(0x38);
	lcd_command(0x0c);
	lcd_command(0x01);
	lcd_command(0x06);
	while(1)
	{
		value=range();
		distance=(value/19.2); 
		if(distance>2.5)
			hex2dec(distance);
	}
}
 
Last edited by a moderator:

Variable state isn't initialized in your code, in so far the result is unpredictable.

Apart from this obvious problem, there may be a problem of additional spikes not shown in datasheet waveform. You should preferably check the real waveform with an oscilloscope. Possibly you need to supplement addidtional timing conditions when a pulse edge will be accepted.

In the present code, you don't need a state variable. You can simply perform a while(1) loop and break it conditionally.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top