Help with Picaxe pulsin and pulsout command - Page 1
Forum section: electronics / general

author: Minh9956
author_rank: Newbie
timestamp: June 11, 2012, 05:31:28 am
content: Hi my name is Minh and I am new to this forum so please bear with me.For school I am building an submersible vehicle for system engineering and right now I'm having trouble with how I need to control it. My first design was to control the motors with switches on land and the batteries would also be on land like in this website:http://www.homebuiltrovs.com/howtoswitch.html. but i opted opted out because the umbilical cable that i'll be using will be a CAT5 cable so the voltage drop would be too much.My second design is to have the batteries onboard the ROV and control it with 2 picaxe microcontrollers "talking" to each other. one would be on the Rov it self and one would be in the control box onland. the first picaxe would read a pair of potentiometer (in my case the ones in my joystick) and turns certain outputs on. These output then connect to the second microcontroller on the rov which transcribe its to turn the motor respectively. For example if pin0 is high and all the other pins are low then the second microcontroller will read this and send signals for the motors to go forward (H-Bridge).You can view my current programme here:https://docs.google.com/document/d/1sHfm9mcgWfio004RjNY-twFZxNM3itzUzy32WLvyOCk/edit, dont worry about the gripper mode for now.The problem is that it uses 4 output pins and four wires. A CAT5 cable only has 8 wires and 2 of them will already used for the onboard camera. I have looked into the pulsin and pulsout command and thought that i might be able to send a pulse of a certain frequency out of only 1 output and the second picaxe will be able to read the frequency of the pulse and do a certain thing.The problem is i dont know how to write the program for pulsin and pulsout so if anyone knows can you please help me. Thanks

author: PeterG
author_rank: Frequent Contributor
timestamp: June 12, 2012, 11:54:43 am
content: Hi Minh9956,The first thing that comes to mind is "Why use a Picaxe chip?"The second is, have you considered using serial to communicate between the two chips?Regards

author: Minh9956
author_rank: Newbie
timestamp: June 12, 2012, 01:02:37 pm
content: Thanks for the replyIm using a picaxe chip because it is what were using at school at the moment and I don't have an arduino or any other board and i don't know how to program them either.As for the serial I have not looked into that yet so I'll be doing some googling on that right now. Thanks Peter

author: MikeK
author_rank: Super Contributor
timestamp: June 12, 2012, 01:30:42 pm
content: There is certainly nothing wrong with using a PICAxe. It is capable of doing many things. And is much cheaper than Arduino and Stamps. This forum, however, may be limited in knowledge about it.Have you tried the PICAxe forums? They have many active members there.

author: PeterG
author_rank: Frequent Contributor
timestamp: June 12, 2012, 01:35:05 pm
content: Have a read of this.http://www.picaxe.com/docs/picaxe_manual2.pdfIt covers both the serial and pulse commands in depth.Let us know if you get stuck.Regards

author: MikeK
author_rank: Super Contributor
timestamp: June 12, 2012, 01:43:27 pm
content: How long will the cable be? Like Peter suggested, I would use serial communication (and proper driver chips), as it will be more reliable.

author: PeterG
author_rank: Frequent Contributor
timestamp: June 12, 2012, 02:02:00 pm
content: For a school project he can probably get by without the MAX232 driver chips and use a slow baud rate,2400 or less, given he will only be sending simple commands down the line. This should work if the link is shielded and less then 5 meters.Regards

author: Minh9956
author_rank: Newbie
timestamp: June 13, 2012, 07:51:59 am
content: ok so i've read up on serials and here's my program right now. please correct me if im wrong.and also the cable will be 30 metres long

author: PeterG
author_rank: Frequent Contributor
timestamp: June 13, 2012, 08:47:45 am
content: Minh9956, that looks like a great start. Well done.Let us know how it goes when its ll hooked up together.Regards

author: Minh9956
author_rank: Newbie
timestamp: June 13, 2012, 09:07:03 am
content: Thanks PeterG and I will.

author: MikeK
author_rank: Super Contributor
timestamp: June 13, 2012, 04:14:15 pm
content: In the receiver program...What are you using b0 for? It's not used anywhere else in your program. Also, I would do a two-sequence command, with the first byte being some fixed value. This prevents the serin() command from getting stuck on garbage data. It's basically saying, "wait for the beginning of a command":Code:serin 0,N2400,("!"),b1And then send the command from the control PICAxe starting with "!".

author: Minh9956
author_rank: Newbie
timestamp: June 13, 2012, 08:50:46 pm
content: I wrote b1 into b0 because I took it from a code example onhttp://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/serin/. I guess I dont need it.And I don't know what you mean by a two sequence command.

author: MikeK
author_rank: Super Contributor
timestamp: June 13, 2012, 09:54:50 pm
content: Instead of sending one byte for each command, send two. Where the first byte is the same value each time, I just chose the "!" character. It's a way of ensuring that you don't get any bad commands.The reason I suggest it is that the length of your cable might cause problems. If your ROV receives unintended commands it could damage it if it hits something. When you send over a "Hi, do this command", it guarantees that if your ROV can hear the "Hi" part it'll hear the "do this command" part.

author: Minh9956
author_rank: Newbie
timestamp: June 14, 2012, 04:16:40 am
content: oh ok, so do you mean like instead of sending out just 'serout 0,N2400,("A") endif', I send out 'serout 0,N2400,("Alfa") endif '?I tried that but the picaxe im using (14M) only has 256 bytes of memory so I went over by 98 bytes.

author: ivan747
author_rank: Super Contributor
timestamp: June 14, 2012, 12:22:02 pm
content: Quote from: Minh9956 on June 14, 2012, 04:16:40 amIf you are going to send "A" then send "!" first. This lets the receiver make sure it is not receiving unintended commands. Like this:Code:main:[do some stuff here][read pots or something][you decide you have to send A]gosub confirmationSequence ;example here: http://www.picaxe.com/BASIC-Commands/Program-Flow-Control/return/serout 0,N2400,("A")[you decide you have to send B]gosub confirmationSequenceserout 0,N2400,("B")endconfirmationSequence:;Here you add whatever conficmation sequence you want. Its like a secret handshake.serout 0,N2400,("!")return ;Dont forget this;You can also add a terination sequence, just like the confirmation sequence, but for ending the transmission. I think it is overkill.On the receiver side:Code:main:[you decide its time to receive something]serin ,N2400,("!"),b0 ;[url=http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/serin]http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/serin;The ("!") makes the Picaxe automatically check for that character before storing the second character into b0. To make this longer do this:;serin ,N2400,("!","?"),b0;And dont forget to modify the transmitter's confirmation sequence:;serout 0,N2400,("!","?")

author: Minh9956
author_rank: Newbie
timestamp: June 14, 2012, 01:41:02 pm
content: Ahhhh cool I sort of get it now. So the ("!") is like saying to the picaxe 'start recording now' kinda of thing. Thanks Ivan.I just have one question, when I press simulate I have to type in "!",13,10. What does the 13 and the 10 stand for?Thanks again.

author: MikeK
author_rank: Super Contributor
timestamp: June 14, 2012, 01:47:26 pm
content: ASCII 13 is a "return" and ASCII 10 is a "line feed". Together they form a "carriage return".

author: ivan747
author_rank: Super Contributor
timestamp: June 15, 2012, 02:06:52 am
content: Quote from: MikeK on June 14, 2012, 01:47:26 pmThis is equivalent to pressing the enter key on the keyboard. The first one (13) means "go down one line" the second one (10) means "now put the cursor back in the beginning of the screen".ASCII used to be used for teletypes, you had to manually tell the teletype to move to the next line but also to move the carriage back to the beginning because they were two separate operations. RS-232 (serial) was created for these kind of machines.

author: PeterG
author_rank: Frequent Contributor
timestamp: June 15, 2012, 03:27:15 am
content: Your Main loop should look something like this.Code:main:serin 0,N2400,b0 'Receive the first byte into b0if b0 = "!" then 'If b0 = "!" then do the following checks, if not then skip the checks.serin 0,N2400,b1 ; receive serial value 'Only need to receive the second byte when a valid first byte is received.'write b0,b1 ; write value into b1if b1 = 67 or b1 <= 64 or b1 >= 76 then nothingif b1 = 68 then forwrdif b1 = 69 then backwrdif b1 = 70 then rotateleftif b1 = 71 then rotaterightif b1 = 72 then forwardleftif b1 = 73 then forwardrightif b1 = 74 then backwardleftif b1 = 75 then backwardrightif b1 = 66 then goupif b1 = 65 then godownendifgoto mainThis should give you a better understanding of using 2 byte commands.Regards

author: Minh9956
author_rank: Newbie
timestamp: June 17, 2012, 12:07:53 am
content: Hi guysSo I've wrote the code like you said but I haven't been able to program it because I don't have a USB program cable. I'll tell you how it goes once I get the code on the picaxe. For now here's my schematic of the two picaxe. Feel free to leave a comment.The pots should be parallel by the way, I just couldn't be bothered drawing it.

author: ivan747
author_rank: Super Contributor
timestamp: June 18, 2012, 04:29:13 pm
content: The switches need pull-down resistors. Like this:Else you are going to have problems. The pins on your PICAXE can act as tiny "antennas" and pick noise from the environment. THat can make the PICAXE think you pressed a switch when you didn't. The resistor weakly connects the PICAXE to a known voltage (0V) and that "absorbs" the noise. The switch can be pressed because instead of connecting the PICAXE directly to 0V, you are using a resistor. You should use 10k resistors in this case.

author: Minh9956
author_rank: Newbie
timestamp: June 19, 2012, 11:45:30 am
content: Ahh yes I forgot about that, Thanks Ivan. Are all the other parts correct though?

author: ivan747
author_rank: Super Contributor
timestamp: June 19, 2012, 05:57:01 pm
content: Quote from: Minh9956 on June 19, 2012, 11:45:30 amMind you: you connected the potentiometers in series. They should be in parallel as you observed.

author: M PEN
author_rank: Newbie
timestamp: August 02, 2012, 07:27:06 am
content: Quote from: Minh9956 on June 14, 2012, 04:16:40 amHi Minh,If you ask your Systems Engineering teacher he may have a 20M2 you can use.Worth a try?