FullDuplexSerial and Servo32 Incompatible?
sharpie
Posts: 150
So, I'm still a newbie to this and not entirely sure of the dynamics here... But I cannot seem to get a servo to move at the same time I am accepting data.· Everything I do it seems either one or the other...· It's got to be me..· Right now I just have a serial stream coming in at 57600, and trying to move a servo with a loop at the same time...
Here's a simple test I tried (one of about a hundred combinations..)
Tried it with and without tv_terminal in there too...· Anybody able to provide some insight into this for me?
Here's a simple test I tried (one of about a hundred combinations..)
con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 Out = %1 var long stack1[noparse][[/noparse]50] long stack2[noparse][[/noparse]50] obj tx : "FullDuplexSerial" txt : "tv_terminal" svo : "Servo32" pub Main txt.start(12) tx.start(0, 1, 0, 57_600) svo.Set(3,1500) svo.start cognew(recvData,@stack1) cognew(moveServo,@stack2) pub recvData repeat txt.out(tx.rx) txt.str(string(13,10)) pub moveServo | temp repeat repeat temp from 1000 to 2000 waitcnt (cnt+125_000) svo.Set(3,temp) repeat temp from 2000 to 1000 waitcnt (cnt+125_000) svo.Set(3,temp)
Tried it with and without tv_terminal in there too...· Anybody able to provide some insight into this for me?
Comments
I would move the "svo.start" to before the first "svo.Set(". I'm not sure it really matters in this case, but that's what's assumed. No pulses are produced on a pin until the first "svo.Set(".
Your serial stream is pretty fast (200us/char roughly). You're asking a lot of the tv_terminal object to act on 3 characters (xx,13,10) at that rate. It's based on a graphics object and I don't think it can run that fast. You could try "tv_text" instead which is character cell based and faster.
I ran your code, and scoped pin A3 and the servo pulse is doing what it is supposed to. I tend to agree with Mike in that your serial stream is pretty fast,
but I'm not sure that the graphics object should be effected by this.
As far as the order of "svo.start" vs "svo.Set"... it really does not matter. The original thinking was that you needed to preset the value before you initiated
the "svo.start"... logically it makes no difference, since the pin will not output anything anyway unless/until "svo.set" has been called.
I don't have a way at the moment to test 57.6Kbaud, but substituting the line that reads...
...with...
...I see the letter "A" (ASCII 65) displayed on the TV screen at the same time I see the proper servo pulsewidth on pin A3.
This indicates to me that the "tv_terminal" and "Servo32" objects are working properly. I would try to lower the baud rate
and see if your results are different.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
You're initializing tx and svo in one cog, but using them in different cogs. If the tx.start and svo.start record their settings in VARs, these settings won't be reachable when svo.SET and tx.rx are called from the other cogs. It will be as if they were never started. I would put the calls to start in the cogs that use the objects' routines.
-Phil
Phil is right.....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I don't believe this is necessarily true. The VARS reside in the object, not the cog. It doesn't matter which cog is running the SPIN code that references the VARS except for the usual caveats that two cogs shouldn't try to use the same information without some planning for the interaction. In this case, the initialization of the other objects was over with before the new cogs were started and none of the running cogs were using the same object at the same time.
The way you did it is cleaner and clearer though.
Mike
As long as an object's routines are called using the same object declaration as the call to start, the same instance of the object's VARs gets used, regardless of whether the calls were made from different cogs. Apparently, it's only when an object is declared more than once, either within the same object or across object boundaries, that separate instances of the VARs get created. (At least I think that's right.)
Thanks much for the insight!
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
In the code example I provided above, the servo runs fine, the serial data coming in has more errors than not. If I comment out the servo stuff, the serial works great. I have tried sending a serial stream with a value that is passed to the servo for position, I have not got this to work. Ultimately, what I would like to do is have two propellers talking to each other... One telling the other one what to do so to speak.. One that has sensors, user interactions, etc.. and processes that data and tells the other propeller to move the servos connected to it in corresponance to the data it's sending.. So there is a constant stream of information flowing between the two as the second prop is responding with acks, and feeback etc... I'd also like to send these commands in sentences, but I haven't mastered the fdxserial stuff and handling variables, strings, etc. well enough yet to get that done...
With the controlling prop, I am sending a simple "+" to increase the servo position, and "-" to decrease...· Using the following code, I attempt to move the servo based on the received information...· the controlling prop sends a constant stream of +'s and -'s at 57.6k.· I get limited success with this, very sporadic movement.· When I output to the tv so I can see what it's getting...· I can see the serial object is stumbling just as it had with the previous attempt.· I'd reaaaallllly rather not drop the baud rate, and I have actually tried as low as 38.4k...·
I would like to have more than just servo data going back and forth..· This doesn't seem that it should be that challenging for the propeller..
I've had great success with another project using a different micro accepting serial data through a mini webserver over ethernet..· But I don't want to use that configuration on this project, the propeller is so much better.
Don't forget, every time you invoke tx.rx it gets another character from the input. That may be the reason you're missing inputs. Better to do something like this:
This will get one character for each loop interation, and compare that character to "+" and "-". Note that I've also included your limiter in the increment and decrement using <# and #>
Also, you've got a 12.5ms delay in there (assuming an 80MHz clock). That's enough for 72 characters at 57,600 baud, if they're coming full bore. Without some sort of handshaking, they'll end up in a black hole.
-Phil
The results I get from what I had done above was waaay more successful than what I'd tried before.. However, I am still getting serious delays in servo movement.. Although, at least I can see it move in the direction I expected. I am currently adding rts/cts lines between the two processors as well, in a hope to get some handshaking going.
This is without the introduction of any servo object or anything.. Looks to me as if it runs perfectly..·My next step is to add a loop where the servo goes back and forth to see if my hunch is right and the serial object will start stumbling.· If this happens, can someone give me some insight as to why it will?·
Post Edited (sharpie) : 7/23/2006 8:47:53 AM GMT
Just one thought! Being more of a Hardware, rather than software, Guy.
Also I noticed that you have covered the software end of it. knowing that the problem only seams to occur when the servo is hooked up, It might not be software related.
It has been My experience that when ever you get weird results while interfacing Inductive Loads with digital electronics that you might want to consider Noise coming in though your power supply or directly though / into your pulse out pin. Ether of these can be receiving inductive surges. Even If there is no noise coming in through ether of these two methods.· there can still be Electro magnetic interference. coming out of the servo going right into the Propeller IC at radio wave lengths / frequencies.
Maybe your timing is so high as to be affected by low strength stray EMI.
You might want to add some Low uf Caps / Shielding and/or ferrite beads to your Servo control and power Leads.·
·
Hope It helps,
IAI Captain
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
IAI (Indigenous Alien Intelligence),
The New View on Machine Intelligence.
Because There is nothing Artificial about it!
Thanks for the input!!
Better grounding, couple of caps.. Well, two good things came of it... It forced me to go ahead with the serial handshaking, which turned out to help ALOT, and I got it all to work together.
Like you said Beau, it is still a learning process for all of us....
Thanks to everyone for the helpful words.
I'm just glad to know that I helped solve the problem.
·
·Like I said, I'm a hardware guy. When it comes to software,·you are·a lot further along than myself, So I keep on going and I will Keep on learning from each new post.
·
(I know that this may not be the place)
· But It does seem at least on the surface, that a bunch of Prop Issue could be solved if everyone would first realize that the Propeller is hardware first And therefore must follow the rules of Digital I/O.
·· ··(I.E.·A lot of the threads are Questions about Interfacing Mem.·All mem follow the same Hardware I/O Rules(non I2C & SPI). there Are (A0-A12 (Address Lines and most of the time D0-D7 (Data Lines) then there are the control lines). If one were to just read any of the spec sheets that are out there on Mem,(Ram, SRam, SDRam, Rom, EPRom, EEProm, ect.. It's all the same I/O Connections). The Hard part is not selecting the right port to use on the Prop. who cares it's all the same, but the data manipulation is a different Question all together. what to do once you get the hardware hooked up correctly?) (The Software)!
·
· So, I guess my point was, look, If you think in terms of hardware I/O first and then build the software around the hardware project chances are you will always have less problems with any given project because at least you’ve lessened the chance of it being hardware by an order of magnitude.
·
Sorry to let it all out on you Sharpie.
·
Hope that this helps.
·
Cap size: 0.01uf or smaller if you are·getting high freq noise. 10uf - 100uf cap if low freq noise on the Power supply lines. (give a try to a range of values.)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
IAI (Indigenous Alien Intelligence),
The New View on Machine Intelligence.
Because There is nothing Artificial about it!
Anyway, thanks again..
U R Welcome.
Just glad 2 help
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
IAI (Indigenous Alien Intelligence),
The New View on Machine Intelligence.
Because There is nothing Artificial about it!