measuring da distance!

Markd77

Joined Sep 7, 2009
2,806
In an ideal world the receiver would detect the start of the first pulse reflected, so starting the timer at the start of the first pulse is correct. In the real world you may find there is some small difference between actual and measured distance, but if it's a problem you can just make a small adjustment when everything is finished.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
but if it's a problem you can just make a small adjustment when everything is finished.
yes! when everything is finished...it is not important for now..you are right! im thinking now of how to implement the out of range (overrange) and im referring to one of post explaination...
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
i been struggling a bit implementing the out of range into the distance routine...attached is what i came up with...

is it correct???

and a part from that am I missing something???

regards,
 

Attachments

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
After 'call concersion' , the distance [cm] is contained in _tmr1h:_tmr1l...

Assuming, that I want a maximum range of 200 cm ==>> we only need _tmr1l register (8 bit register) ==>> _tmr1h can be ignored!

then we need to compare value in _tmr1l to a range of values (lets say 20 to 200) and if there's a match ==> display that match in seven segment display!!!

am I correct???
 

Markd77

Joined Sep 7, 2009
2,806
i been struggling a bit implementing the out of range into the distance routine...attached is what i came up with...

is it correct???

and a part from that am I missing something???

regards,
I'd disable the interrupt, the interrupt flag gets set regardless.
In the overflow section I would go to endlisten instead of listen, because the pin has gone high so it has detected a pulse, but make sure you still clear the interrupt flag.
 

Markd77

Joined Sep 7, 2009
2,806
After 'call concersion' , the distance [cm] is contained in _tmr1h:_tmr1l...

Assuming, that I want a maximum range of 200 cm ==>> we only need _tmr1l register (8 bit register) ==>> _tmr1h can be ignored!

then we need to compare value in _tmr1l to a range of values (lets say 20 to 200) and if there's a match ==> display that match in seven segment display!!!

am I correct???
First part correct, for a value to display you need to convert binary to BCD (have a look on Wikipedia if you are unsure what that is):
http://www.piclist.com/techref/microchip/math/radix/index.htm
I know for sure that the 16 bit to 5 digit by John Payson works well, you only really need 8 bit to 3 digit, but it will still work fine.
After you have the BCD (and unpacked is easiest to work with), you need to create a table that converts the unpacked BCD to the actual segments that will be lit up for those digits.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
First part correct, for a value to display you need to convert binary to BCD (have a look on Wikipedia if you are unsure what that is):
http://www.piclist.com/techref/microchip/math/radix/index.htm
I know for sure that the 16 bit to 5 digit by John Payson works well, you only really need 8 bit to 3 digit, but it will still work fine.
After you have the BCD (and unpacked is easiest to work with), you need to create a table that converts the unpacked BCD to the actual segments that will be lit up for those digits.

i been thinking of binary to BCD conversion as well...

i'll just have a look at that link just now...
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I think this binary to BCD conversion is the most resonnable thang to do!!!
All I have to do is to only consider Hund:Tens:Ones, right??

and knowing the minimum and maximum range will only be possible experimentally, right? a part from the out of range due to timer1 overflow
 

Markd77

Joined Sep 7, 2009
2,806
Yes, just hundreds, tens, and ones. Being more that 8 bit means that it can go over 256cm which could be possible. At some point the reflection will be too faint, so the pin won't get set and the timer will overflow.
Looking at it again, the listen part needs to be altered a bit. You need to check if the pin has been set and also if the timer flag has been set, with gotos to endlisten and overflow, otherwise goto listen.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Yes, just hundreds, tens, and ones. Being more that 8 bit means that it can go over 256cm which could be possible. At some point the reflection will be too faint, so the pin won't get set and the timer will overflow.
Looking at it again, the listen part needs to be altered a bit. You need to check if the pin has been set and also if the timer flag has been set, with gotos to endlisten and overflow, otherwise goto listen.

Absolutely!!! i will edit that and repost it for checkup...as i know what to do with that...i need to work on what has not been implemented yet then go back to all the rou tine that need small editing....

also in that binary to BCD conversion, NumH:NumL = _tmr1h:_tmr1l right? just have to edit names in my routine...

regards,
 

Markd77

Joined Sep 7, 2009
2,806
Absolutely!!! i will edit that and repost it for checkup...as i know what to do with that...i need to work on what has not been implemented yet then go back to all the rou tine that need small editing....

also in that binary to BCD conversion, NumH:NumL = _tmr1h:_tmr1l right? just have to edit names in my routine...

regards,
Yes, you can replace one set of names for the other.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Oh I forgot, here's segdata routine:
now i thinking if the display and multiplexing should be in a isr...and also i have to check (in the display routine I think) if button is press for next measurement...

segdata
addwf PCL,F ;

retlw b'0111111' ; 0
retlw b'0000110' ; 1
retlw b'1011011' ; 2
retlw b'1001111' ; 3
retlw b'1100110' ; 4
retlw b'1101101' ; 5
retlw b'1111101' ; 6
retlw b'0000111' ; 7
retlw b'1111111' ; 8
retlw b'1101111' ; 9

end


and the main program goes like this:

main
call getkey
call distance
call bin16_BDC5
call display

goto main

-------------------------------------------------

getkey

check
btfss swnew,7 ; new press? yes, skip, else
goto check ; loop
bcf swnew,7 ; reset "new press" flag and
return
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I decided to multiplex my sevev segment displays in timer0 interrupt service routine...coz my above display routine is NOT going to work well...im also editing my getkey routine and my main program structure...

will post the above changes...

regards
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
please check my attachement...

this is how I intend to multiplex the seven segments and deal with the push button...

Basically, before main program starts, it waits for the user to trigger it, also when there's a nex press, do the next measurement!

Am I correct??? did I miss something???

Also the main program goes like this:

main

call getkey
call distance
call bin16_BDC5

goto main

the getkey routine is the same as above post

regards,
 

Attachments

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Looking at it again, the listen part needs to be altered a bit. You need to check if the pin has been set and also if the timer flag has been set, with gotos to endlisten and overflow, otherwise goto listen.
Ok! But what about the case where the pin has not been set BUT the timer flag has been set??? does this case need to be implemented as well or it ia not necessary???

regards,
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Also, if there is overflow there is no need to call conversion...then i can just display 3 dashes (---) on the seven segment indicated out of range...am i correct???
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I also think instead of doing:

movlw 1 ;
movwf outofrange ; out of range detected

in the distance routine, i can just set a flag for the 'bin16_BDC5' so that it first check if there out of range before doing the conversion....

am I correct???

regards,
 

Markd77

Joined Sep 7, 2009
2,806
Looks like it's getting there. It is missing the part to set the transistors for each display.
Make sure that in your initialisation you set all user variables to the correct initial value, because they have unknown values at power up.
 
Top