Author Topic: Help with Picaxe pulsin and pulsout command  (Read 11319 times)

0 Members and 1 Guest are viewing this topic.

Offline Minh9956Topic starter

  • Newbie
  • Posts: 9
Help with Picaxe pulsin and pulsout command
« on: June 11, 2012, 05:31:28 am »
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 :)
 

Offline PeterG

  • Frequent Contributor
  • **
  • Posts: 830
  • Country: au
Re: Help with Picaxe pulsin and pulsout command
« Reply #1 on: June 12, 2012, 11:54:43 am »
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
Testing one two three...
 

Offline Minh9956Topic starter

  • Newbie
  • Posts: 9
Re: Help with Picaxe pulsin and pulsout command
« Reply #2 on: June 12, 2012, 01:02:37 pm »
Thanks for the reply

Im 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  :)
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: Help with Picaxe pulsin and pulsout command
« Reply #3 on: June 12, 2012, 01:30:42 pm »
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.
 

Offline PeterG

  • Frequent Contributor
  • **
  • Posts: 830
  • Country: au
Re: Help with Picaxe pulsin and pulsout command
« Reply #4 on: June 12, 2012, 01:35:05 pm »
Have a read of this.

http://www.picaxe.com/docs/picaxe_manual2.pdf

It covers both the serial and pulse commands in depth.

Let us know if you get stuck.

Regards
Testing one two three...
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: Help with Picaxe pulsin and pulsout command
« Reply #5 on: June 12, 2012, 01:43:27 pm »
How long will the cable be?  Like Peter suggested, I would use serial communication (and proper driver chips), as it will be more reliable.
 

Offline PeterG

  • Frequent Contributor
  • **
  • Posts: 830
  • Country: au
Re: Help with Picaxe pulsin and pulsout command
« Reply #6 on: June 12, 2012, 02:02:00 pm »
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
Testing one two three...
 

Offline Minh9956Topic starter

  • Newbie
  • Posts: 9
Re: Help with Picaxe pulsin and pulsout command
« Reply #7 on: June 13, 2012, 07:51:59 am »
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
« Last Edit: June 13, 2012, 08:40:20 am by Minh9956 »
 

Offline PeterG

  • Frequent Contributor
  • **
  • Posts: 830
  • Country: au
Re: Help with Picaxe pulsin and pulsout command
« Reply #8 on: June 13, 2012, 08:47:45 am »
Minh9956, that looks like a great start. Well done.

Let us know how it goes when its ll hooked up together. :D

Regards
Testing one two three...
 

Offline Minh9956Topic starter

  • Newbie
  • Posts: 9
Re: Help with Picaxe pulsin and pulsout command
« Reply #9 on: June 13, 2012, 09:07:03 am »
Thanks PeterG and I will.  :D
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: Help with Picaxe pulsin and pulsout command
« Reply #10 on: June 13, 2012, 04:14:15 pm »
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: [Select]
serin 0,N2400,("!"),b1
And then send the command from the control PICAxe starting with "!".
 

Offline Minh9956Topic starter

  • Newbie
  • Posts: 9
Re: Help with Picaxe pulsin and pulsout command
« Reply #11 on: June 13, 2012, 08:50:46 pm »
I wrote b1 into b0 because I took it from a code example on http://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.
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: Help with Picaxe pulsin and pulsout command
« Reply #12 on: June 13, 2012, 09:54:50 pm »
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.
 

Offline Minh9956Topic starter

  • Newbie
  • Posts: 9
Re: Help with Picaxe pulsin and pulsout command
« Reply #13 on: June 14, 2012, 04:16:40 am »
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.  :'(
 

Offline ivan747

  • Super Contributor
  • ***
  • Posts: 2045
  • Country: us
Re: Help with Picaxe pulsin and pulsout command
« Reply #14 on: June 14, 2012, 12:22:02 pm »
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.  :'(

If you are going to send "A" then send "!" first. This lets the receiver make sure it is not receiving unintended commands. Like this:
Code: [Select]
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 confirmationSequence
         serout 0,N2400,("B")
    end

confirmationSequence:
   ;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: [Select]
main:
   [you decide its time to receive something]
   serin [pin],N2400,("!"),b0    ;[url=http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/serin]http://www.picaxe.com/BASIC-Commands/Serial-RS232-Interfacing/serin[/url]
;The ("!") makes the Picaxe automatically check for that character before storing the second character into b0. To make this longer do this:
;serin [pin],N2400,("!","?"),b0
;And dont forget to modify the transmitter's confirmation sequence:
;serout 0,N2400,("!","?")

« Last Edit: June 15, 2012, 02:01:49 am by ivan747 »
 

Offline Minh9956Topic starter

  • Newbie
  • Posts: 9
Re: Help with Picaxe pulsin and pulsout command
« Reply #15 on: June 14, 2012, 01:41:02 pm »
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.
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: Help with Picaxe pulsin and pulsout command
« Reply #16 on: June 14, 2012, 01:47:26 pm »
ASCII 13 is a "return" and ASCII 10 is a "line feed".  Together they form a "carriage return".
 

Offline ivan747

  • Super Contributor
  • ***
  • Posts: 2045
  • Country: us
Re: Help with Picaxe pulsin and pulsout command
« Reply #17 on: June 15, 2012, 02:06:52 am »
ASCII 13 is a "return" and ASCII 10 is a "line feed".  Together they form a "carriage return".

This 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.
 

Offline PeterG

  • Frequent Contributor
  • **
  • Posts: 830
  • Country: au
Re: Help with Picaxe pulsin and pulsout command
« Reply #18 on: June 15, 2012, 03:27:15 am »
Your Main loop should look something like this.

Code: [Select]
main:
  serin 0,N2400,b0 'Receive the first byte into b0
        if 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 b1

   if b1 = 67 or b1 <= 64 or b1 >= 76 then nothing
   if b1 = 68 then forwrd
   if b1 = 69 then backwrd
   if b1 = 70 then rotateleft
   if b1 = 71 then rotateright
   if b1 = 72 then forwardleft
   if b1 = 73 then forwardright
   if b1 = 74 then backwardleft
   if b1 = 75 then backwardright
   if b1 = 66 then goup
   if b1 = 65 then godown
endif
goto main

This should give you a better understanding of using 2 byte commands.

Regards
Testing one two three...
 

Offline Minh9956Topic starter

  • Newbie
  • Posts: 9
Re: Help with Picaxe pulsin and pulsout command
« Reply #19 on: June 17, 2012, 12:07:53 am »
Hi guys

So 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.
« Last Edit: June 17, 2012, 12:12:46 am by Minh9956 »
 

Offline ivan747

  • Super Contributor
  • ***
  • Posts: 2045
  • Country: us
Re: Help with Picaxe pulsin and pulsout command
« Reply #20 on: June 18, 2012, 04:29:13 pm »
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.
 

Offline Minh9956Topic starter

  • Newbie
  • Posts: 9
Re: Help with Picaxe pulsin and pulsout command
« Reply #21 on: June 19, 2012, 11:45:30 am »
Ahh yes I forgot about that, Thanks Ivan. Are all the other parts correct though?
 

Offline ivan747

  • Super Contributor
  • ***
  • Posts: 2045
  • Country: us
Re: Help with Picaxe pulsin and pulsout command
« Reply #22 on: June 19, 2012, 05:57:01 pm »
Ahh yes I forgot about that, Thanks Ivan. Are all the other parts correct though?

Mind you: you connected the potentiometers in series. They should be in parallel as you observed.
 

Offline M PEN

  • Newbie
  • Posts: 1
Re: Help with Picaxe pulsin and pulsout command
« Reply #23 on: August 02, 2012, 07:27:06 am »
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.  :'(

Hi Minh,

If you ask your Systems Engineering teacher he may have a 20M2 you can use.

Worth a try?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf