Help needed with a display

Hope you all had a Happy Christmas and I wish you all a happy new year.

My problem:

I have a SRF005 that shows the display on a AXE133Y display, all works well, but;

If the distance is a single digit the number is steady.

If the distance is double digits, 10cms or over the display shows the distance but toggles between it and 0.

If I turn the delay in start1 up to 400ms the display works with out going to 0.

I want to use this as a reversing sensor in my garage, so I would like a quick response and a steady delay.

The program I have made from the PDF's and looking in the manual.

The 0 flashes up in the debug as well.

Code:
start0:

#picaxe 18m2 ; distance measured by Ultrasonic and displayed on OLED in cms
symbol SIG = C.1   ; Define pin for Trigger & Echo 
symbol range = w1  ; 16 bit word variable for range
symbol LCD = b.7   ; output pin 
symbol baud = n2400

	Pause 500
	
	serout LCD, baud,(254,1) ; clear display 
	pause 30
	
	serout LCD,baud,(254,128) ;line 1 position 1
	pause 30
	
	serout LCD,baud,("Measured in cms "); top banner
	pause 30

Main:
		
		serout LCD,baud,(254,198,#range,"    "); distance line 2 in 6 places, the "" keep 4 digit display
		pause 30
 
		
goto main



Start1:

		pulsout SIG,2      ; produce 20uS trigger pulse (must be minimum of 10uS)
	
		pulsin SIG,1,range ; measures the range in 10uS steps
				 	; now convert range to cm (divide by 5.8) or inches (divide by 14.8)
				 	; as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead

		let range = range * 10 / 58 ; multiply by 10 then divide by 58

		debug range 	; display range via debug command 

		pause 50 		; short delay
	
		
	
goto start1
Thanks for your help
 

nick12ab

Senior Member
In what way does it toggle between 0 and the value? Does it briefly flash 0 or is it 0 one read then the value the next read, then 0 again?

The problem could be because you're unnecessarily using multitasking. If that serout command executes after the pulsin command but before the following let command then the value displayed will not be the one created by the calculation in that let command.

Since you're getting 0 and not some strange value, that suggests that the problem is when the serout command happens between the pulsout and pulsin commands causing the PICAXE to miss the pulse from the sensor.

Here is a version not using multitasking:
Code:
#picaxe 18m2 ; distance measured by Ultrasonic and displayed on OLED in cms
symbol SIG = C.1   ; Define pin for Trigger & Echo 
symbol range = w1  ; 16 bit word variable for range
symbol LCD = b.7   ; output pin 
symbol baud = n2400

	Pause 500
	
	serout LCD, baud,(254,1) ; clear display 
	pause 30
	
	serout LCD,baud,(254,128) ;line 1 position 1
	pause 30
	
	serout LCD,baud,("Measured in cms "); top banner
	pause 30

Main:
	pulsout SIG,2      ; produce 20uS trigger pulse (must be minimum of 10uS)
	pulsin SIG,1,range ; measures the range in 10uS steps
			 	; now convert range to cm (divide by 5.8) or inches (divide by 14.8)
			 	; as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead
	let range = range * 10 / 58 ; multiply by 10 then divide by 58

	debug range 	; display range via debug command 

	pause 50 		; short delay
		
	serout LCD,baud,(254,198,#range,"    "); distance line 2 in 6 places, the "" keep 4 digit display
	goto main
That code should fix the problem.

Is there any reason to use pulsin and pulsout anyway? Why not just use the ultra command.
 
All fixed thank you.

I used the pulsin and out as that was in the data sheet. Looked at ultra and that is the answer.

I used the multi tasking to speed the operation up as initially I had the banner and clear commands in the program and they slowed down operation.

Its easy when you know, but take it from me you don't know how much you do know.

Again thanks for your help.
 
Top