Hi,
I am at the begining of my project, actually I spent 1 week trying to make the LCD work properly so that tels me that I have a long way to go.
I am using a 16F627A (just because that's what I have on hand) if a better chip is suggested I can change it.
I have found a number of designs on the Web and read quite a few treads on forums, not that I want to reinvent the wheel but I would rather make my own design although I am taking some parts of interesting code here and there.
I do have a few questions to get me going. Based on the attached file, this is pretty much the simplest flowchart I could come up with and next to it is my understaning of what needs to happen as far as signal however I am no sure about the following details:
I presume that between T1 and T2 there has to be a burst of 40k times per second but I don't know how long it should last.
Ditto for the listening time between T3 and T4 and I guess the length of time it is listening is partly related to the range I can detect as long as I have enough transmitting and receiving power.
Please correct me if I am wrong but I figure I only want to start listening at T3 because I don't want the receiver to pickup vibrations from the transmiter since they are both on the same PCB.
What I have seen so far can take care of a ranges from a few centimeters to a few meters but I would like my range to be 6 cm to 6 meters so I understand I have to add some amplification at the receiver using op-amps and probably I have to increase power to the transmitter but how do I increase the Tx power? by raising the voltage?
and one last question (for now) when I detect an echo, do I calculate the time from T1 or T2?
I don't really need more than +/-20 cm of precision at 6 meters but I do need a minimum of 2 or 3 cm at 6 cm.
Here is where I am at with the code which basically I can see 40Khz on the scope and I know the LCD works. Like I said, I have a long way to go...
Code:
@ __config _XT_OSC & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
DEFINE OSC 4
TRISB = 0 ' Make PORTB all outputs
TRISA = %10 ' A0 = send burst, A1 = listen to echo
CMCON = 7 ' Disable comparator
FLAGS = 0
T1CON = %00000001 ' enable Timer1 prescaler 1:1
disTance var byte
ECHO var PORTA.1
Cycles var byte
LCD_DB4 VAR PORTB.0 ' Set port for 4 bits bus
LCD_DB5 VAR PORTB.1
LCD_DB6 VAR PORTB.2
LCD_DB7 VAR PORTB.3
LCD_RS VAR PORTB.5 ' Set RS bit port
LCD_E VAR PORTB.4 ' Set Enable bit port
LCD_Lines CON 2 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines)
LCD_DATAUS CON 50 ' Data delay time in us
LCD_COMMANDUS CON 2000 ' Command delay time in us
INCLUDE "LCD_AnyPin.pbp" ' Must go after LCD initialization
Pause 500: LCDOUT $FE,1: pause 250 ' clear screen and relax
LCDOUT $FE,$80,"Distance Finder"
goto start
asm
_Pulse
bsf PORTA,0 ; change to whatever port pin you have available
goto $+1 ; 2uS per GOTO $+1
goto $+1
goto $+1
goto $+1
goto $+1
bcf PORTA,0
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
decfsz _Cycles,f
goto _Pulse ; 25uS total for 40kHz carrier
RETLW 0 ; return to CALLing routine
ENDASM
Start:
' start timer ...
' send burst ...
Cycles = 8 ' number of carrier cycles to generate
CALL Pulse
PAUSEUS 24
' Listen for echo ...
' timed out...
' count number of time outs ...
' update display
gosub display_upd
GOTO start
Display_UPD:
LCDOUT $FE,$C0,"Distance = ",dec disTance," "
return
end
Bookmarks