Shop OBEX P1 Docs P2 Docs Learn Events
First Post, and new to PIC''s, Please be gentle — Parallax Forums

First Post, and new to PIC''s, Please be gentle

ArchiverArchiver Posts: 46,084
edited 2003-12-20 01:00 in General Discussion
Some notes:

(1) The BS1 has a maximum serial baud rate ot 2400; your code suggests
you think you can do 9600. Sorry, you can't (BS2 family can).

(2) PAUSE is a keyword -- you can't use it as a label.

(3) All pins are inputs on reset -- you don't have to set a pin to be an
input unless it was previously made an output (by you or a function
[noparse][[/noparse]i.e., PULSOUT]).

(4) If you're going to put multiple statements on one line (not
recommended), you must separate them with a colon ([noparse]:)[/noparse].


Clean formatting goes a long way to making code easy to work with and
prevent (or find) errors. We have a document on our web site called
"The Elements of PBASIC Style" that you may find helpful. Using those
guidelines, I've reformatted your code. It compiles without errors, but
may not work -- you'll have to sort that out with your hardware.

'{$STAMP BS1}
'{$PBASIC 1.0}

SYMBOL MtrRun = PIN3
SYMBOL IgSense = PIN4

Setup:
PAUSE 2000 ' allow BiStep to initialize

Main:
GOSUB Motor_1_Out
GOSUB Wait_For_Motor
GOSUB Motor_2_Out
GOSUB Wait_For_Motor
GOSUB Sense
GOSUB Motor_2_In
GOSUB Wait_For_Motor
GOSUB Motor_1_In
GOSUB Wait_For_Motor
END


Motor_1_Out:
SEROUT 1, N2400, ("y=1")
SEROUT 1, N2400, ("1m")
RETURN


Wait_For_Motor:
IF MtrRun = 1 THEN Mtr_Is_On
PAUSE 500

Mtr_Is_On:
RETURN


Motor_2_Out:
SEROUT 1, N2400, ("x=1")
SEROUT 1, N2400, ("1m")
RETURN


Sense:
IF IgSense = 1 THEN Sense
RETURN


Motor_2_In:
SEROUT 1, N2400, ("y")
SEROUT 1, N2400, ("0m")
SEROUT 1, N2400, ("0g")
RETURN


Motor_1_In:
SEROUT 1, N2400, ("x")
SEROUT 1, N2400, ("0m")
SEROUT 1, N2400, ("0g")
RETURN



-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office




Original Message
From: yellinmm [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=pOwRAYet6kTDNbwfm1nkGItFeoRZakSyEAwr_9Gk-KeG2DJNxjB0LL0tWvnCDemMxP2h3w4G]HQ54@A...[/url
Sent: Friday, December 19, 2003 6:27 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] First Post, and new to PIC's, Please be gentle



Hello All,

I am new, so please understand that. I have this idea to use the
pic to control some Stepper motors. After some research, I found a
product called the BiStep, which can be seen here
http://www.stepperboard.com/ . Basically, the BiStep recieves serial
data, and controls the steppers, making it very easy, at least for me.

I just have a couple of questions about the PIC, and PIC Basic I am
hoping someone can answer for me.

First, when writing comments, can I use quotes around some text,
or will that confue the PIC.

Second, the BiStep outputs a TTL level HI signal when a motor is
active. I want to be able to monitor this signal. Can I just
connect it to a pin on the PIC that has been set as an INPUT, or do I
need to worry about voltages and signal levels and the like? Also, I
want to connect this to a car. I would like to PIC to sense for
ignition. Can I just use an accessory wire from the fuse box
straight into the PIC, or do something like a relay, which connects
another input pin on the pic to either the pics ground, or 5 volts
supply?

Next, I have some code (Don't worry, it will follow), but I would
like to know if there is a free program on line that I can download,
and run the PicBasic program in, to wee if it works, and what happens.

And last, here is the code. PLEASE BE GENTLE. It was my absolute
first time programing in anything since high school, and back then,
it was all in BASIC. That is how long ago that was. I use alot of
gosubs, only because to me, the actions of the motors basically goes
like this

Wait for the switch to turn on
Set the "in" location on motor 1
send motor 1 to the "out" location
wait for the motors to stop
set the "in" location on motor 2
send motor 2 to the "out" location
wait for the motor to stop
wait for the swicth to turn off
set motor 2 current location as the "out" location
send motor 2 to the in location
wait for the motor to stop turning
set motor 1 current location to the out position
send motor 1 to the in location
wait for the motor to stop turning
end program

Here is the code


`This progam will control a BiStep Stepper motor controller. It
is 'being used to create a movable LCD screen for a `carputer. The
BiStep `is controled serially with some simple text. The only
feedback `between the BiStep and the pic is a `ttl level, HI
when "busy" signal. `The BiStep does output serial communication if
needed, but I have no `use for it, so it `is not implemented. When
the BiStep and is powered, `and the PIC senses that the car key is in
at least the accessory `position, the PIC send a serial command to
move the motor till the `open poition. Once the "busy line" goes
LOW, the PIC `tell the BiStep `to move the second motor out. Then,
when the key is turned off, the `second motor returns to the in
`position, and when the busy line goes `LOW again, the first motor
goes to the in position.

Symbol Motorrunning = pin3 `Assign pin3 an easy name to use
Symbol Ignsense = pin4 `Assign pin4 an easy name
input 3

pause 2000 `pause for 2 seconds, waiting for BiStep to initialize gosub
motoroneout gosub waitformotor gosub motortwoout gosub waitformotor
gosub sense gosub motortwoin gosub waitformotor gosub motoronein gosub
waitformotor end

motoroneout:
serout 1,N9600, ("y=1") `send y=1 serially to the BiStep,
serout 1,n9600, ("1m") `send 1m serially,
return

waitformotor:
if motorrunning = o then pause `If motor turning, then pause return

pause:
pause 500 `pause for half a second
return

motortwoout:
serout 1,n9600, ("x=1") `send x=1 serially to the BiStep
serout 1,n9600, ("1m") `send 1m serially
return

Sense:
if ignsense = 1 then goto sense `Checking ignition switch return

motortwoin:
serout 1,n9600, ("y") `send y serially
serout 1,n9600, ("0m") `send 0m serially
serout 1,n9600, ("0g") `send OG serially
return

motoronein:
serout 1,n9600, ("x") `send X serially, chooses X motor
serout 1,n9600, ("0m") `send 0m serially
serout 1,n9600, ("0g") send OG serially
return



To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.


Yahoo! Groups Links

To visit your group on the web, go to:
http://groups.yahoo.com/group/basicstamps/

To unsubscribe from this group, send an email to:
basicstamps-unsubscribe@yahoogroups.com

Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/




This message has been scanned by WebShield. Please report SPAM to
abuse@p....
Sign In or Register to comment.