BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 12:59 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: ARC32 Serial Input Question
PostPosted: Sat Jan 08, 2011 10:36 am 
Offline
Citizen

Joined: Tue Apr 20, 2010 4:11 pm
Posts: 15
I received my ARC32 and I must say I like it, this really is a step ahead of everthing else I have used to control servo's and the Studio software is user friendly and looks good.

I am using Studio Version 2.0.0.7 and I have read through the posts here and on Lynxmotion's forum concerning the changes to the Serial commands and I have been using this code to do some testing on a few servo's and works as expected, waits for the data then sets the servo postion and speed then toggles the status LED. I send 5000,250 + CR and I receive Pos1 = 5000, Spd1 = 250 in the terminal window.
Code:
'HW UART 1 Serial Setup
SETHSERIAL1 H9600,H8DATABITS,HNOPARITY,H1STOPBITS
Pos1      Var sWord
Spd1      Var Word
Pos1 = 0
Spd1 = 100
'Set Servos Centered
HServo [P4\0,P5\0]

Main:

HSerin 1,[sdec Pos1, dec Spd1]
HSerout 1,["Pos1 = ",sdec Pos1,", Spd1 = ",dec Spd1,13]

HServo [P4\Pos1\Spd1]

Toggle P44 'Status LED
Pause 100
GoTo Main

I then tried the HSerin with a Label and time out value and send 5000 + CR like this.
Code:
HSerin 1,nodata,5000, [sdec Pos1]
HSerout 1,["Pos1 = ",sdec Pos1,13]

HSerin 1,[dec Spd1]
HSerout 1,["Spd1 = ",dec Spd1,13]

HServo [P4\Pos1\Spd1]

nodata:

Toggle P44 'Status LED
Pause 100


I do not receive any data back so I set up the Status LED just as a visual feedback of when the data was received and tried differant time out values but the LED flash rate stays the same I thought with a larger time out value the flash rate would change as the HSerin waits longer for the data does 5000 = 5 secs?.

I also tried some testing with Serin and received some not as expected results here is some code that I was trying one section at a time.
Code:
'Sent 5000,250 + CR and receive Pos1 = 5, Spd1 = 5
Serin ComRX,ComBaud,[sdec Pos1, dec Spd1]
Serout ComTX,ComBaud,["Pos1 = ",sdec Pos1,", Spd1 = ",dec Spd1,13]

'Sent 5000 + CR and received Pos1 = 5
Serin ComRX,ComBaud,[sdec Pos1]
Serout ComTX,ComBaud,["Pos1 = ",sdec Pos1,13]

'Sent 250 + CR and received Spd1 = 2
Serin ComRX,ComBaud,[dec Spd1]
Serout ComTX,ComBaud,["Spd1 = ",dec Spd1,13]



I also tried the Serin with a Time out value and a label but received the same results as before with the HSerin time out test.
Code:
'Sent 5000 + CR No data back
Serin ComRX,ComBaud,5000,nodata,[sdec Pos1]
Serout ComTX,ComBaud,["Pos1 = ",sdec Pos1,13]

Serin ComRX,ComBaud,5000,nodata,[dec Spd1]
Serout ComTX,ComBaud,["Spd1 = ",dec Spd1,13]

HServo [P4\Pos1\Spd1]

nodata:

Toggle P44 'Status LED
Pause 100

I have been through the manuals old and new and I am over looking something simple maybe a push in the right direction would be helpful.

Thanks
John


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Sat Jan 08, 2011 10:48 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
Hi John,

I believe the new documents for hserin are wrong and we are waiting for an update. The timeout value I believe is in .5us not in ms. so your wait of 5000 is only waiting 2.5ms which is not very long! I believe the serin command is described this way

Kurt


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Sun Jan 09, 2011 3:04 am 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
The timing is in half microsecond increments. So if you have some milliseconds interval in mind, multiply that value by 1000 (one thousand times) then multiply by two. Or, simply, multiply by 2000.

So, if you want 500 milliseconds (half a second) for a timeout, multiply 500 by 2000 to arrive at a working value of 100,000.

One second is 1000 milliseconds, so your working value is 1000*1000*2 = 2,000,000.
HTH! :)

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Sun Jan 09, 2011 2:56 pm 
Offline
Citizen

Joined: Tue Apr 20, 2010 4:11 pm
Posts: 15
Thank you for the fast reply's, I have increased the time out value and HSerin is working as expected.

I found this code on Lynxmotion's forum (I changed slightly for my needs) from Acidtech and it works great...
Code:
If you have data waiting in the hserial buffer is to send a 0 timeout to the hserin command. If there is no data it will immediately jump to the label specified.
So you can do somethign like this:

HSerin 1,nodata,0,[sdec Pos1]
HSerout 1,["Pos1 = ",sdec Pos1,13]

nodata:


I thought the Serin command worked like this in the past I Bowerred this from the latest manual page 162.
Quote:
The DEC/Hex/BIN modifiers will store all incoming numeric values as their binary equivalents.
DEC/HEX/BIN modifiers will ignore all preceding non-numeral character data and the
commands will exit on the first non-numeral character received after it received numeral characters.


Using this code if I sent 250 + CR from my terminal I should receive Spd1 = 250 back correct? All I receive back is Spd1 = 2.
Code:
Spd1   Var Word

Serin ComRX,ComBaud,[dec Spd1]
Serout ComTX,ComBaud,["Spd1 = ",dec Spd1,13]


Thanks
John


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Mon Jan 10, 2011 11:17 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Are you sending 250 + CR or are you sending "250" + cr?

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Mon Jan 10, 2011 6:09 pm 
Offline
Citizen

Joined: Tue Apr 20, 2010 4:11 pm
Posts: 15
I am sending "250" + CR (ascii codes 50 53 48 13) only differance between the terminal I was using and Terminal 1 in Basic Micro Studio is my terminal sends data on carriage return were Terminal 1 sends data on keypress. I have tried this in the Basic Micro Studio Terminal 1 and Terminal 2.

For this example should I receive the same data back "250" from Serin as I do from HSerin? I Send "250" + Cr (50 53 48 13).
The HSerin returned HW Spd1 = 250
The Serin returned SP Spd1 = 2

Code:
SETHSERIAL1 H9600,H8DATABITS,HNOPARITY,H1STOPBITS
Spd1 Var Word
Main:

HSerin 1,[dec Spd1]
HSerout 1,["HW Spd1 = ",dec Spd1,13]

Toggle P44 'Status LED

Serin ComRX,ComBaud,[dec Spd1]
Serout ComTX,ComBaud,["SP Spd1 = ",dec Spd1,13]

Toggle P44 'Status LED
   
GoTo Main


Thanks
John


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Tue Jan 11, 2011 9:52 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
When you use our terminal window does it work correctly? Just getting back 2 from the your test program could indicate there is some garbage between bytes being sent. Also can you add some delay between bytes being sent from your terminal program?

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Tue Jan 11, 2011 10:58 am 
Offline
Citizen

Joined: Tue Apr 20, 2010 4:11 pm
Posts: 15
I do normally use your terminal as it is already open and ready to go, only when I need to send control characters will I switch terminals.

Using your Terminal the HSerin example works as expected, the Serin example will immediately respond with SP Spd1 = 2 at the first key press 2. I will continue testing with your terminal only to eliminate any possibility that the terminal program I am using maybe at fault.

Thanks
John


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Wed Jan 12, 2011 9:39 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
If the serin command is returning immediately after you press "2" then it must be seeing another non-numeric charcater coming right after it(eg garbage/noise). Do you have a scope? Also are you using the USB port on the ARC32?

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Wed Jan 12, 2011 11:25 am 
Offline
Master

Joined: Tue Jun 22, 2010 1:15 pm
Posts: 203
Sending "on keypress" vs CR is actually quite a bit different! Also affects how you write your buffered (if it is) I/O.

I use a variety of terminal programs. T2, DockLight, and LynxTerm all come in handy. I really have a hard time trying to set up a particular WiFi module over it's serial "back door".

Alan KM6VV

jdaniels wrote:
I am sending "250" + CR (ascii codes 50 53 48 13) only differance between the terminal I was using and Terminal 1 in Basic Micro Studio is my terminal sends data on carriage return were Terminal 1 sends data on keypress. I have tried this in the Basic Micro Studio Terminal 1 and Terminal 2.
Thanks
John

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Wed Jan 12, 2011 4:12 pm 
Offline
Citizen

Joined: Tue Apr 20, 2010 4:11 pm
Posts: 15
I tried the USB Port with the same results the Serin example will immediately respond with Spd1 = 2 at the first key press 2 using your Terminal. I do have a scope but I do not have the software to pull the captured data from it.
Code:
ComBaud Con I9600
Spd1 Var Word

Main:

Serin S_In,ComBaud,[dec Spd1]
Serout S_Out,ComBaud,["Spd1 = ",dec Spd1,13]

Toggle P44 'Status LED
   
GoTo Main


I tried this example on a couple sets of ports and captured some data with a logic analyzer.
Code:
'Serial Lines
ComTX Con P36      'TX = P36 (AUX1-P3)(TTL-White)
ComRX Con P38      'RX = P38 (AUX1-P5) (TTL-Blue)
ComBaud Con I9600   'Serial Baud Rate, Inverted
Spd1 Var Word

Main:

Serin ComRX,ComBaud,[dec Spd1]
Serout ComTX,ComBaud,["Spd1 = ",dec Spd1,13]

Toggle P44 'Status LED
   
GoTo Main


Attachment:
Serin_02.JPG
Serin_02.JPG [ 137.68 KiB | Viewed 678 times ]


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Thu Jan 13, 2011 11:05 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Please email me with a bug report. I'll run a test on it. nathan@basicmicro.com

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: ARC32 Serial Input Question
PostPosted: Thu Jan 13, 2011 2:53 pm 
Offline
Citizen

Joined: Tue Apr 20, 2010 4:11 pm
Posts: 15
Email sent.

Thanks
John


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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