BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 1:05 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Atom Pro getting stuck/freezing?
PostPosted: Wed Jul 21, 2010 2:31 pm 
Offline
Citizen

Joined: Thu Jul 08, 2010 6:33 pm
Posts: 8
Hey!

I have the following code to measure distances from 3 SRF04 sensors, but it seems that once in a while the output from the terminal gets stuck? Is it just the terminal, or is my microcontroller actually freezing? Pressing reset works sometimes, and others it just advances one more time through. It seems to be random.

Any suggestions?

Thanks!

Code:
convfac con 74 ' use inches

SONAR_INIT con p16
SONAR_ECHO con p17

sonar_dist var word
output SONAR_INIT
input SONAR_ECHO

; ### Main Function ###
main
   goto getDistance
goto main
 
; ### Get Distances ###
getDistance:

   SONAR_INIT con p16
   SONAR_ECHO con p17

   low SONAR_INIT
   pulsout SONAR_INIT, 20      '10us pulse to init reading   
   RCTIME SONAR_ECHO, 1, sonar_dist ; use instead of pulsin since buggy
   RCTIME SONAR_ECHO, 0, sonar_dist

   debug [dec sonar_dist, 13]

   sonar_dist = sonar_dist / convfac
   serout s_out, i9600, ["Distance1: ", sdec sonar_dist, 13, 10]      ;display result in terminal
   
   ;if sonar_dist < 15 then brake
   ;if sonar_dist > 15 then accelerate
;###############   
   SONAR_INIT con p18;
   SONAR_ECHO con p19;
   
   low SONAR_INIT
   pulsout SONAR_INIT, 20      '10us pulse to init reading   
   RCTIME SONAR_ECHO, 1, sonar_dist ; use instead of pulsin since buggy
   RCTIME SONAR_ECHO, 0, sonar_dist

   debug [dec sonar_dist, 13]

   sonar_dist = sonar_dist / convfac
   serout s_out, i9600, ["Distance2: ", sdec sonar_dist, 13, 10]      ;display result in terminal
;#############

   SONAR_INIT con p20;
   SONAR_ECHO con p21;
   
   low SONAR_INIT
   pulsout SONAR_INIT, 20      '10us pulse to init reading   
   RCTIME SONAR_ECHO, 1, sonar_dist ; use instead of pulsin since buggy
   RCTIME SONAR_ECHO, 0, sonar_dist

   debug [dec sonar_dist, 13]

   sonar_dist = sonar_dist / convfac
   serout s_out, i9600, ["Distance3: ", sdec sonar_dist, 13, 10]      ;display result in terminal
   
   
return



Top
 Profile  
 
 Post subject: Re: Atom Pro getting stuck/freezing?
PostPosted: Wed Jul 21, 2010 4:39 pm 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
I answered this on the Lynxmotion thread.

change: goto getDistance
to: gosub getDistance

Also maybe change all debug statements to serout s_out statements...

Kurt


Top
 Profile  
 
 Post subject: Re: Atom Pro getting stuck/freezing?
PostPosted: Thu Jul 22, 2010 9:36 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Just so any new people understand, a goto can NOT be returned from. If you try to return from a GOTO your program will do unexpected things. in this case it froze which is probably the best possible outcome. In other situations you may jump into a completely different part of your program causing code to run you really don't want to, especially if you have heavy machinery attached to/controlled by the module.

Only GOSUB works with a RETURN. The GOSUB command pushes a return address on the stack which is then available to the RETURN so it know what address to return to.

As for switching to serouts instead of debug commands, thats because serouts will be much faster (because you won't be using DEBUG mode). You should use DEBUG mode when you need to check variables and or code flow. You can easily step through your program and see what it's doing. In this case when it gets to the return you would see it was NOT returning to where you expected which would be a big warning flag you did something wrong. However if all you are doing with DEBUG mode is outputing values to the DEBUG output window you are usually better off just using serout commands to a terminal window and using regular PROGRAM mode. This way your program will run at full speed.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO