measuring da distance!

Markd77

Joined Sep 7, 2009
2,806
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,
Sounds about right.
A possible improvement would be to lookup the 3 segments to send (and store them in variables) after the conversion instead of in the ISR. That way it is easy to put something to display for over and under in those variables and the interrupt will just display them. You could put something like "ovr" and "und"
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Looks like it's getting there. It is missing the part to set the transistors for each display.
Oh yes I forgot thanks!

Make sure that in your initialisation you set all user variables to the correct initial value, because they have unknown values at power up.
Absolutly, i thinking of creating a routine that clear all registers that need to be initialized with ZERO and assign required values for other register in the normal initialization.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Sounds about right.
A possible improvement would be to lookup the 3 segments to send (and store them in variables) after the conversion instead of in the ISR. That way it is easy to put something to display for over and under in those variables and the interrupt will just display them. You could put something like "ovr" and "und"
I get the idea but still a bit confused...wondering how the irs is going to display it ....also are 'ovr' and 'und' labels??

regards,
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Ah ohk I get it... but i think like you said that's for improvement...i just wana display anything that i would interpret as out of range (overange) and I'm not considering underrange right now...

underrange will be implemented in the improvement after the whole thang works...

thanks!!
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Please check the change that i plan to do for overflow display...below is just changes for units displat BUT if it makes sense i'll edit the rest...lemme know if im correct or if not please show me how to do it

regards,



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

bin16_BCD5

btfsc outofrange
goto endbin16_BCD5
.......
conversion code goes here
..........
goto get_out

endbin16_BCD5

movlw 10
movwf Ones

movlw 10
movwf Tens

movlw 10
movwf Hund

get_out
return

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

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
retlw b'1000000' ; -

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

dsp_units

; display units digit
clrf PORTC ; blank the display
movf Ones,w ; copy units value for display
xorlw 10 ;
btfsc STATUS, Z ;
movlw 10 ;
call segdata ; get segment data
movwf PORTC ; displays units into LED display
bsf en_units ; enable units display
goto isr_end ; get out


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

Markd77

Joined Sep 7, 2009
2,806
Please have a look at new 'distance' routine

lemme know if correct

regards,
It's getting there, there are a few things I won't spot until I do a simulation, which I will do when there is a more complete program.
At the moment the listen routine won't check for the timer interrupt flag unless the the input pin gets set, so you should check for both before the goto start.
 

Markd77

Joined Sep 7, 2009
2,806
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???
Yes, that's another way of doing it, you could even add more characters to the table later to display the message.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
So if I understood you well, you mean post #86 is correct???

im trying finish up all the small editing...

thanks for all the above...
 

Markd77

Joined Sep 7, 2009
2,806
Yes, post 86 is good, apart from this bit which should be removed:
xorlw 10 ;
btfsc STATUS, Z ;
movlw 10 ;
You are checking if W is 10, and if it is, setting it to 10, but if W isn't 10 it's value will be changed.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
i don't think its value will change coz if W isn't 10 its value will not change because 'btfsc STATUS, Z ' = 0 ==>> will skip 'movlw' , also the fact that there has been no overflow, the value of Hun:Tens:Ones are correct (the BCD one)

check in post #86 how i edited routine bin16_BCD5 to take care of that!

well maybe i'm wrong!!

thanks!
 

Markd77

Joined Sep 7, 2009
2,806
i don't think its value will change coz if W isn't 10 its value will not change because 'btfsc STATUS, Z ' = 0 ==>> will skip 'movlw' , also the fact that there has been no overflow, the value of Hun:Tens:Ones are correct (the BCD one)

check in post #86 how i edited routine bin16_BCD5 to take care of that!

well maybe i'm wrong!!

thanks!
The damage has already been done by xorlw 10, but if you remove the whole section then everything will remain the same (including if W was 10).
Actually unless you put "radix dec" at the top of the code, I think the default is hex, so 10 is 0x10 which is 16 in decimal.
I usually use, for example, movlw d'10' to force it to use decimal.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
To avoid complication, I will not put:

xorlw 10
btfsc STATUS, Z ;
movlw 10 ;

But now with that extra line: "retlw b'1000000' ; - " added to segdata

and with:

movlw 10
movwf Ones
movlw 10
movwf Tens
movlw 10
movwf Hund

added in bin16_BCD5, the 3 dashes (---) will still be displayed on timer1 overflow???

sorry if you already answered that i just wana make sure I get you well as i'm doing the final editing...

thanks!
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
This is the burst routine ima use:

---------------------------------------------------------
burst
movlw 5 ;
movwf cycles ;
incf cycles, F ; add one so Zero bit can be used instead of Carry bit
loopcycles
decf cycles, F ;
btfsc STATUS, Z ;
goto endcycles ;
bsf pulse ;
call delay4cy ; 4 cycles
call delay4cy ;
call delay4cy ;
bcf pulse ;
call delay4cy ;
goto $+1 ; 2 cycles
goto loopcycles ;
endcycles
delay4cy
return
-----------------------------------------------------------------

im just wondering if there will be no conflit with the:

noconversion
return

in the bin16_BCD5???

thanks!
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Also i think 243 is the exact value to load in order to get a delay of exactly 250 microsecond, right?

250us_delay

movlw 243 ;
movwf delay1 ;

again

decfsz delay1 ;
goto again ;

return
 

Markd77

Joined Sep 7, 2009
2,806
im just wondering if there will be no conflit with the:

noconversion
return

in the bin16_BCD5???

thanks!
I'm not really sure what you mean, it will probably make more sense when the program is more whole.

Just noticed that you are doing bsf en_units, but you also need to do bcf en_hundreds, or whatever the last one to be turned on was.
 

Markd77

Joined Sep 7, 2009
2,806
Also i think 243 is the exact value to load in order to get a delay of exactly 250 microsecond, right?
It's going to be closer to
movlw d'80'
at 4MHz. The loop takes 3 cycles.

Unless you have put "radix dec" at the top of the code, you need to put d and the single quotes around anything you want to be decimal.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Please find attached the complete program (UDM1_1:UDM1_2) for simulation!!

my 'distance' routine might still have lil problem and I might have forgotten something BUT this is good enough for simulation to spot some mistakes,,,

Regards,
 

Attachments

Top