All About Circuits Forum  

Go Back   All About Circuits Forum > Electronics Forums > Homework Help

Notices

Homework Help Stuck on a textbook question or coursework? Cramming for a test and need help understanding something? Post your questions and attempts here and let others help.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 03-18-2010, 02:27 AM
dbaker63 dbaker63 is offline
New Member
 
Join Date: Mar 2010
Posts: 6
Default Microcontroller Programming question

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!
Reply With Quote
  #2  
Old 03-18-2010, 02:37 AM
retched's Avatar
retched retched is offline
Senior Member
 
Join Date: Dec 2009
Location: Baltimore, MD
Posts: 3,619
Blog Entries: 14
Default

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.
__________________
-rm-
Reply With Quote
  #3  
Old 03-18-2010, 02:46 AM
hgmjr's Avatar
hgmjr hgmjr is online now
Super Moderator
 
Join Date: Jan 2005
Location: Tennessee, USA (GMT-5)
Posts: 7,146
Blog Entries: 11
Default

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
Reply With Quote
  #4  
Old 03-18-2010, 02:54 AM
retched's Avatar
retched retched is offline
Senior Member
 
Join Date: Dec 2009
Location: Baltimore, MD
Posts: 3,619
Blog Entries: 14
Default

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?
__________________
-rm-
Reply With Quote
  #5  
Old 03-18-2010, 03:44 AM
dbaker63 dbaker63 is offline
New Member
 
Join Date: Mar 2010
Posts: 6
Default

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.
Reply With Quote
  #6  
Old 03-18-2010, 03:55 AM
retched's Avatar
retched retched is offline
Senior Member
 
Join Date: Dec 2009
Location: Baltimore, MD
Posts: 3,619
Blog Entries: 14
Default

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
__________________
-rm-
Reply With Quote
  #7  
Old 03-18-2010, 03:57 AM
dbaker63 dbaker63 is offline
New Member
 
Join Date: Mar 2010
Posts: 6
Default

how do i do that?
Reply With Quote
  #8  
Old 03-18-2010, 04:05 AM
retched's Avatar
retched retched is offline
Senior Member
 
Join Date: Dec 2009
Location: Baltimore, MD
Posts: 3,619
Blog Entries: 14
Default

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
__________________
-rm-
Reply With Quote
  #9  
Old 03-18-2010, 04:06 AM
retched's Avatar
retched retched is offline
Senior Member
 
Join Date: Dec 2009
Location: Baltimore, MD
Posts: 3,619
Blog Entries: 14
Default

Do you have BS2px?
__________________
-rm-
Reply With Quote
  #10  
Old 03-18-2010, 04:23 AM
dbaker63 dbaker63 is offline
New Member
 
Join Date: Mar 2010
Posts: 6
Default

no its just bs2, it wont do the configpin command
Reply With Quote
Reply   Post New Thread

Bookmarks

Tags
, ,

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
8051 architecture programming question Eric90 Embedded Systems and Microcontrollers 5 03-18-2010 07:44 AM
Microcontroller programming in C herc Embedded Systems and Microcontrollers 5 08-27-2009 05:58 AM
Embedded C programming in 8051 and PIC microcontroller triplehdineshbabu Embedded Systems and Microcontrollers 1 02-16-2009 09:56 AM
Programming PIC32 Microcontroller Inputs DancinNancy Embedded Systems and Microcontrollers 6 01-28-2009 06:03 PM
Need Help Programming PIC32 microcontroller DancinNancy Programmer's Corner 0 01-28-2009 04:01 AM


All times are GMT. The time now is 10:16 PM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License. Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.