Microcontroller Programming question

Discussion in 'Homework Help' started by dbaker63, Mar 17, 2010.

  1. dbaker63

    Thread Starter New Member

    Mar 17, 2010
    6
    0
    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!
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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.
     
  3. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  4. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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?
     
  5. dbaker63

    Thread Starter New Member

    Mar 17, 2010
    6
    0
    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.
     
  6. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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
     
  7. dbaker63

    Thread Starter New Member

    Mar 17, 2010
    6
    0
    how do i do that?
     
  8. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Code ( (Unknown Language)):
    1.  
    2. Setup:
    3.      CONFIGPIN SCHMITT, %0010000000000000
    4. DO: 'continue your DO from here
    5.  
    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
     
  9. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Do you have BS2px?
     
  10. dbaker63

    Thread Starter New Member

    Mar 17, 2010
    6
    0
    no its just bs2, it wont do the configpin command
     
  11. dbaker63

    Thread Starter New Member

    Mar 17, 2010
    6
    0
    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.
     
Loading...