Lynxmotion Tech Support

www.lynxmotion.com
Join the Accelerator Program
It is currently Wed Jun 19, 2013 5:12 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Fri Aug 18, 2006 12:18 am 
Offline
Robot Guru

Joined: Tue Feb 28, 2006 11:27 am
Posts: 2172
Mike, If I read it right you are using the command variable as a semaphore between the interrupt handler and the main loop. When a command is received by the irpd it puts the value in the command variable. Once you see in the main loop that the command variable has been updated you act on it and then reset it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:19 am 
Offline
Lynxmotion Founder
User avatar

Joined: Mon Oct 31, 2005 10:46 am
Posts: 9325
Location: my quiet place
SN96 wrote:
Note: I went back and made some quick changes to the code. Sorry...

>>>Edit
This wait is killing me, Jim.... Are you done yet?.... :shock:

Sorry, I made the changes and although it does work, it's still having the same problems. I think it's in the interupt code. Or how I'm trying to wrap basic around it. :(

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:25 am 
Offline
Robot Guru
User avatar

Joined: Mon Oct 31, 2005 3:03 pm
Posts: 3598
Location: Houston, Texas
Robot Dude wrote:
SN96 wrote:
Note: I went back and made some quick changes to the code. Sorry...

>>>Edit
This wait is killing me, Jim.... Are you done yet?.... :shock:

Sorry, I made the changes and although it does work, it's still having the same problems. I think it's in the interupt code. Or how I'm trying to wrap basic around it. :(


I was kidding about the wait comment. :lol:

I figured there was something more to the problem then what meets the eye. I gave it my best shot though. :lol:

So some how with the interupt, varables are getting jumbled up I guess. Acidtech is the best person to provide an answer.

_________________
Mike

The robotics nut.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:30 am 
Offline
Robot Guru

Joined: Tue Feb 28, 2006 11:27 am
Posts: 2172
is there a way to block the interrupt while you are accessing the command variable? or force the code to always load the variable from memory every time it is accessed? there is a problem with optimized and compiled languages where a frequently used variable might be held in a register for a few operations rather than pulled from memory every time it is needed. If an interrupt is changing the contents of that variable at the same time though the main loop won't see the change and could possible overwrite it. In C/C++ there is a storage class called volatile that is specifically to address this problem. I don't know if the basic stuff you are using has that same type of issue, but if it does there may be a similar fix to the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:34 am 
Offline
Lynxmotion Founder
User avatar

Joined: Mon Oct 31, 2005 10:46 am
Posts: 9325
Location: my quiet place
SN96 wrote:
I figured there was something more to the problem then what meets the eye. I gave it my best shot though. :lol:

So some how with the interupt, varables are getting jumbled up I guess. Acidtech is the best person to provide an answer.


I forgot to mention that a reset brings it back to life for a little while, so I think it's the interupt code that is causing it to act up.

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


Last edited by Robot Dude on Fri Aug 18, 2006 12:36 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:34 am 
Offline
Robot Guru
User avatar

Joined: Mon Oct 31, 2005 3:03 pm
Posts: 3598
Location: Houston, Texas
You know Eddie, I think you might be on to something! :lol:

In both Pbasic and Mbasic, you can write variables to the eeprom. This might be a good thing to try. This could help "protect" the variable from being affected from the interrupt.

_________________
Mike

The robotics nut.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:37 am 
Offline
Robot Guru
User avatar

Joined: Mon Oct 31, 2005 3:03 pm
Posts: 3598
Location: Houston, Texas
Robot Dude wrote:
SN96 wrote:
I figured there was something more to the problem then what meets the eye. I gave it my best shot though. :lol:

So some how with the interupt, varables are getting jumbled up I guess. Acidtech is the best person to provide an answer.


I forgot to mention that a reset brings it back to life, so I think it's the interupt code that is causing it to act up.


What about what Eddie said about writing the variables to eeprom, could this possibly help?

_________________
Mike

The robotics nut.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:37 am 
Offline
Lynxmotion Founder
User avatar

Joined: Mon Oct 31, 2005 10:46 am
Posts: 9325
Location: my quiet place
SN96 wrote:
You know Eddie, I think you might be on to something! :lol:

In both Pbasic and Mbasic, you can write variables to the eeprom. This might be a good thing to try. This could help "protect" the variable from being affected from the interrupt.


I am currently experimenting with the enable and disable commands. They allow you to enable and disable the interupt. Nothing good to say yet, but I am still working.

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:46 am 
Offline
Lynxmotion Founder
User avatar

Joined: Mon Oct 31, 2005 10:46 am
Posts: 9325
Location: my quiet place
I tried disabling the interupt when the decisions are being made.

Code:
main
disable WKPINT_3
   if(command<>0xFF)then
'      serout S_OUT,i115200,["Address = ",hex address,13,"Command = ",hex command,13]

   if (command = 0) then
      servop = 4000
   endif
   if (command = 1) then
      servop = 3000
   endif
   if (command = 2) then
      servop = 2000
   endif
      Command=0xFF
   endif
enable WKPINT_3   

pulsout 15,servop
pause 20

   goto main

But it's still loosing interest in behaving after a while.

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 12:49 am 
Offline
Robot Guru

Joined: Fri Jun 16, 2006 3:51 pm
Posts: 1003
Location: New York, USA
Have you tried mine? Instead of having it send the servo pulse to the servo, make it print it to the terminal. I think its a better method of debugging. You might also want to stick a print into the label which checks for the command.

_________________
What do you mean "NO SPOON!"????


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 1:24 am 
Offline
Lynxmotion Founder
User avatar

Joined: Mon Oct 31, 2005 10:46 am
Posts: 9325
Location: my quiet place
robodude666 wrote:
Have you tried mine? Instead of having it send the servo pulse to the servo, make it print it to the terminal. I think its a better method of debugging. You might also want to stick a print into the label which checks for the command.

Well I didn't think this was worth trying as it worked fine before I added the pulsout commands. However I did go back and put the terminal serial command back in. Low and behold it is getting corrupt. After working for a while it starts sending garbage to the screen...

At first it works...
Code:
Address = 1
Command = 1
Address = 1
Command = 1


Then after a while it sends this...
Code:
{Ønd = 0
Addresÿî = 0
Comý{Ønd = 0
{Ønd = 0
Addre^þ0
Com
/Ï{ö^þ0
Addre^þ0
Com
/Ï{ö^þ0
Addresÿî = 0
Comý{Ønd = 0
Addresÿî = 0
Comss{Ønd = 0
Addresÿî = 0
Comî = 0


Clicking dissconnect and then reconnect seems to fix it. But it's just temporary...

This is with no pulsout commands. Thanks for making me go back to the beginning. :D

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


Last edited by Robot Dude on Fri Aug 18, 2006 1:27 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 1:27 am 
Offline
Robot Guru
User avatar

Joined: Mon Oct 31, 2005 3:03 pm
Posts: 3598
Location: Houston, Texas
Robot Dude wrote:
So it has to be the interupt code. This is with no pulsout commands. Thanks for making me go back to the beginning. :D


LOL, but it's not all bad though, it's interesting to "see" what was going on... :lol:

_________________
Mike

The robotics nut.


Last edited by SN96 on Fri Aug 18, 2006 1:28 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 1:27 am 
Offline
Robot Guru

Joined: Fri Jun 16, 2006 3:51 pm
Posts: 1003
Location: New York, USA
Yup, thought so. Nothing wrong with your servop stuff, had to be the commands/address it was getting.

_________________
What do you mean "NO SPOON!"????


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 1:52 pm 
Offline
Roboteer
User avatar

Joined: Thu Dec 01, 2005 7:37 pm
Posts: 628
Location: Temecula CA
It's gona be a little longer before I can get back to this code. But until then...

The problem causing the data to become invalid is being caused because the IRPD is missing a pulse. When it does there is no recovering with the current code because it has no way of knowing it missed a pulse. What needs to be done is setup a TimerA interrupt that keeps track of the current pulse width. By keeping track of the time, if the pulse gets longer than a valid pulse(ie greater than 195) the sequence needs to be reset(setting lasttime = -1 will reset the sequence for the next valid pulse train from the remote).

So here's the code(not tested and probably has bugs/typos):

Code:
ONINTERRUPT WKPINT_3,handle_irpd
ONINTERRUPT TIMERA_OVF,handle_timera
PMR5.bit3 = 1
TMA=4   ;increments on clock/256
ENABLE WKPINT_3
ENABLE TIMERA_OVF

lasttime var long
currenttime var long
datacount var byte
irpd_data var word
command var byte
address var byte
ServoP var word

currenttime=0
lasttime = -1   ;indicate next data should be a startpulse
low 15

main

pulsout 15,servop
pause 20

   if(command<>0xFF)then
;      serout S_OUT,i115200,["Address = ",hex address,13,"Command = ",hex command,13]

      if (command = 0) then
         servop = 4000
      endif
      if (command = 1) then
         servop = 3000
      endif
      if (command = 2) then
         servop = 2000
      endif

      Command=0xFF
   endif
   goto main

;Modified handle_irpd routine
handle_irpd
   if(lasttime<0)then
      datacount=0
      lasttime=currenttime+TCA
   else
      datacount=datacount+1
      lasttime=(currenttime+TCA)-lasttime
      irpd_data=irpd_data>>1       
      if(lasttime>175 AND lasttime<195)then
         irpd_data=0
      elseif(lasttime>100 and lasttime<120)
         irpd_data.bit10=1
      elseif(lasttime>65 and lasttime<85)
         irpd_data.bit10=0
      else
         ;invalid pulse received
         lasttime=-1   
         resume   ;resume imediately   
      endif
      if(datacount=12)then
         lasttime=-1
         command = irpd_data&0x7F
         address = irpd_data>>7
      else
         lasttime = currenttime+TCA
      endif
   endif   
   resume

handle_timera
   currenttime=currenttime+256
   resume


That should work to handle bad pulses. I may have the wrong name for the TIMERA_OVF interrupt but the rest looks right.

Nathan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 4:16 pm 
Offline
Lynxmotion Founder
User avatar

Joined: Mon Oct 31, 2005 10:46 am
Posts: 9325
Location: my quiet place
I moved this to the Bipeds section.

http://www.lynxmotion.net/viewtopic.php?t=1242

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group