Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ultra sonic distance meter with pic16f84

Status
Not open for further replies.
Try to use the original code again, and only add the "__CONFIG" line
don't add the "LIST" and "INCLUDE" lines.

Then check how your lcd is connected, on the scematic you posted lcd pin 1 is on the right!, not on the left. If you missed that you connected the lcd backwards.

then, to make absolutely sure your oscillator is running, it may be wise to test a simple blink-a-led program...
 
Ok,thanks,like I said before I get false distances on my LCD with the first hex file (trisa,trisb lines deleted) so connection of LCD could not be wrong.

but I will test your offered hex file.

Thank you
 
unfortunately the circuit does not work I have my LCD light on but it shows wrong distances.
I think maybe transmitter or receiver are not working properly.
I see a 10 Vp-p pulse between RA0 and Ra1 outputs of the pic16f84 witch is going straight to the transmitter sensor. I should have a low to high going pulse on RA0 and a high to low going pulse on RA1 pin but I don't see none of them separately on scope. But I see a pulse between that two pins on the scope.:!:

my transmitter and receiver circuits are here:

**broken link removed**
 
I heve seen my interrupt going through three stages of amplification and reaching the interrupt pin (RB7) of pic16f84, but LCD shows wrong distances.

I have this doubt that maybe my switchin transistor witch should send the interrupt is not proper ,although I have seen it's (switching) when I push the send signal button in this circuit:(The Receiver circuit)
**broken link removed**

I have both BC107 and C547 (high frequency)transistors tested.

so what's the problem? I have been confused.
 
elnaz said:
I heve seen my interrupt going through three stages of amplification and reaching the interrupt pin (RB7) of pic16f84, but LCD shows wrong distances.

I have this doubt that maybe my switchin transistor witch should send the interrupt is not proper ,although I have seen it's (switching) when I push the send signal button in this circuit:(The Receiver circuit)
**broken link removed**

I have both BC107 and C547 (high frequency)transistors tested.

so what's the problem? I have been confused.

I suspect your problems are more likely to be the receiver hardware, rather than a problem with the PIC.

If you have a double beam scope try using one beam on the receive line to the PIC (RB7) and the other on the output to the transmitter. Make sure you get a varying time between these two signals, based on how far it is to the nearest reflective object.

The receiver itself seems very crude, it would be far better having tuned amplifers rather than broadband ones - which will be far more prone to instability and external interference.
 
I've already done with scope and yes the level of receiving signal changes appropirate to distance between object and receiver.I forgot to say that I have very narrow spikes as interrupts ( high to low spike) on RB7 (interrupt pin) but is it sufficient to have just negative going spikes?
Does pic take this as an interrupt? or maybe it needs a level?!
 
It needs a certain level to be seen as a logic 1...
You should find all the info in the datasheet..

I find it rather strange that your using RB7 as external interrupt.
RB7 can only interrupt on portchange
RB0 should be a better choice, especially because it is a schmitt trigger input when configured as interrupt pin
 
It has certain amount of logic 1 (transistor off) but level zero to be taken as interrupt is only a spike (switching transistor on).

here in :**broken link removed**
 
It seems to me that pic does not send 40KHz signal, hoewer it must send it according to program.
I've changed my sensors to be sure about sensors be working.

So why pic does not send this signal?????
 
elnaz said:
It seems to me that pic does not send 40KHz signal, hoewer it must send it according to program.
I've changed my sensors to be sure about sensors be working.

So why pic does not send this signal?????

You've got a scope, so check it!.

The 40KHz output is in a bridge arrangement, to double the drive to the transmitter - so one pin goes high as the other goes low.
 
YES it works!!!! :)

thank you all so much

but I still have a little problem:

It's minimum measured distance doesn't change when I decrease it's default delay (the delay witch pic waits to receive signal).
here in:

RECEIVE movf MASK,W
btfsc STATUS,Z
goto DEFMASK ;if mask 0 do default delay movf MASK,W
movwf LOOPB
goto MASK1 ;perform mask delay

DEFMASK movlw D'240'
movwf ANSA1
movlw D'2'
movwf ANSA2
DEFMLP decfsz ANSA1,F
goto DEFMLP
decfsz ANSA2,F
goto DEFMLP
goto MASK0

MASK1 movlw D'2' ;masking delays
movwf ANSA2
movlw D'48'
movwf ANSA1

MASK2 movlw D'4'
movwf ANSA3
MASK3 decfsz ANSA3,F
goto MASK3

decfsz ANSA1,F
goto MASK2
decfsz ANSA2,F
goto MASK2
decfsz LOOPB,F
goto MASK1

MASK0 bcf INTCON,RBIF ;clear RB4-RB7 interrupt change flag
bcf ZERO,0
LISTEN btfsc INTCON,RBIF ;has echo been heard
 
Nigel Goodwin said:
The receiver itself seems very crude, it would be far better having tuned amplifers rather than broadband ones - which will be far more prone to instability and external interference.
Normally, Nigel, but ultrasonic transducers are extremely high-Q, so the only signal getting to the first stage would be at 40 KHz.
 
Dear Al42

yes, but the receiver is very sensitive.For example by clicking the send botton switch pic gets an interrupt and...
 
Al42 said:
Nigel Goodwin said:
The receiver itself seems very crude, it would be far better having tuned amplifers rather than broadband ones - which will be far more prone to instability and external interference.
Normally, Nigel, but ultrasonic transducers are extremely high-Q, so the only signal getting to the first stage would be at 40 KHz.

It's a nice theory, but doesn't work too well in practice - the wideband amplifier will amplify all the extraneous noise as well as the required signal. By using a tuned amplifier you can vastly reduce unwanted signals, while giving high gain at the required frequency.
 
Hi
In my measuring process when I keep send key pushed so pic keeps sending out 40KHz signals, sometimes I get very big random numbers like 23 mt 1.6 mt 54 mt...
Why does it happen?
Is it because of pic receiving the last signal's reflection?
How can I avoid it?

The code listing is here:
**broken link removed**
 
Hello,elnaz.Your problem may be for your Xtal precision.When you try to make your .hex program
it consider your crystal as xx.000000 that is six zero crystal.And if you use a crystal[xtal] with lower
that six zero instead of that your code does not work at all!

I mean you should use a crystal with six zero wrote on it,that is;[ 4.00000].

Bye,
 
Last edited:
BoBX, this is 9 year old thread. I think your help is little late. Nice thought anyway :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top