Microcontroller Programming question

Thread Starter

dbaker63

Joined Mar 17, 2010
6
K I am a TOTAL programming noob and i am having a hard time with this problem from my class. ANY help would be great! Here is the problem:
"Write a program with the following devices:
An active-High LED on P0 (LED1)
An active-High PB on P8 (PB1)
Servo on P13
Program the controller to loop continuously and perform the following:
- At run, the LED will be off and the servo will be fully CW.
- When the PB is pressed, the LED will blink 10 times at a rate of once per second.
- A count down will be shown on the screen.
- After the 10 blinks, the servo will move fully CCW
- When the button is released the servo will move back to CW immediately and the LED will be off.

Here is what i have so far:


' {$STAMP BS2}
' {$PBASIC 2.5}
duration VAR Word

duration = 750
DO
IF (IN8 = 1) THEN
DEBUG "10" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
DEBUG "9" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
DEBUG "8" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
DEBUG "7" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
DEBUG "6" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
DEBUG "5" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
DEBUG "4" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
DEBUG "3" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
DEBUG "2" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
DEBUG "1" ,CR
HIGH 0
PAUSE 500
LOW 0
PAUSE 1000
IF IN8 = 1 THEN
IF duration > 500 THEN
duration = duration - 25
ENDIF
ENDIF
PULSOUT 13, duration
PAUSE 1000

ELSE
PAUSE 1000
PULSOUT 13, 500
ENDIF


LOOP

Um the LED works fine, but i can get the servo to drive correctly. Its either always energized or it wont drive all the way to ccw or cw. Thanks for your help in advance!
 

retched

Joined Dec 5, 2009
5,208
Hey, bro, it's ok to just post in 1 thread.

So we will stay here in Homework Help so people don't start conversing in 3 different threads about the same thing.
 

hgmjr

Joined Jan 28, 2005
9,027
I have removed the duplicates as retched has indicated. It is best if a thread is only posted once since all members can see all threads regardless of the sub-forum in which it is posted.

hgmjr
 

retched

Joined Dec 5, 2009
5,208
Are you using the BasicSTAMP Compiler?

Do you have to "LOOP DO" in your compiler or is it automatic?

You want the count down to 1 then a step to the motor then repeat the countdown then 1 more step?
 

Thread Starter

dbaker63

Joined Mar 17, 2010
6
Sorry about that guys ive been workin on this for awhile i am going nuts, yes i am using BASIC Stamp kit. Right now the push button activates the countdown and led blink and will drive the servo ccw and then cw. but as soon as i run the program the servo is wiggin out. then when i push the button it starts the blink etc. ideally once it runs then it stops until the button is depressed again, but the servo is constantly driving back and forth. I know its a problem with my code and not the servo...but not sure what i am doing wrong.
 

retched

Joined Dec 5, 2009
5,208
It sounds like you have a floating pin.
Try assigning pin 13 LOW in the beginning.

It is floating between high and low and the servo doesn't know what to do until the end of the countdown
 

retched

Joined Dec 5, 2009
5,208
Rich (BB code):
Setup:
     CONFIGPIN SCHMITT, %0010000000000000
DO: 'continue your DO from here
Configures pin 13 with a schmitt trigger, so it needs to get %15 of high to activate..

Each number after the % is a pin starting at 16 going to 1. the last 0 means ALL pins
 

Thread Starter

dbaker63

Joined Mar 17, 2010
6
ok i took out the "else" part and now it stop wiggin out on power up. now i just have to figure how to rotate it back cw when finished.
 
Top