Shop OBEX P1 Docs P2 Docs Learn Events
servo/programing problem — Parallax Forums

servo/programing problem

dylantsdylants Posts: 13
edited 2011-05-09 11:03 in General Discussion
I need to run a servo with an external low of 1.3V and shut it down at 1.5V; any ideas?

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-05-04 06:37
    Use an analog to digital converter to read an external voltage level into a STAMP or Propeller micro. There are tons of A/Ds. I looked on my bench for a reference number and found a MAX 1113.
    http://www.datasheetcatalog.org/datasheet/maxim/MAX1112-MAX1113.pdf
  • dylantsdylants Posts: 13
    edited 2011-05-04 09:25
    the signal is dc, I dont think a analog to dc converter will help. I only want the circuit on when there is a low of 1.3 and off at 1.5. I have tried to use an opamp to a comparator to a FET switch; It still wont turn off at the 1.5V.

    Now I am trying to program the input shut off at a high; the program turning the servo just starts over instead of stopping when it reads the high signal.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-04 10:28
    You need some way to detect when the control voltage is around the thresholds (1.3V and 1.5V). You can do this with an analog to digital converter. You can also do this with a pair of comparators, one with a threshold of 1.3V and one with a threshold of 1.5V.

    A single comparator won't work for this since it responds to a single voltage threshold and you want a lower and upper threshold to define a voltage window.

    If you want help with your program, you'll have to provide it ... as an attachment to a reply. Use the "Go Advanced" button and you'll find an attachment manager that can upload your source file.
  • kwinnkwinn Posts: 8,697
    edited 2011-05-04 10:38
    dylants wrote: »
    I need to run a servo with an external low of 1.3V and shut it down at 1.5V; any ideas?

    What you want is called a window comparator. It consists of 2 comparators, one for each voltage, and an R/S flip flop that the comparator outputs turn on and off. A 555 timer might also be able to do this. Look at the LM339 and 7474 dual D flip flop.
  • dylantsdylants Posts: 13
    edited 2011-05-04 10:40
    Thans for responding mike, attached is my program to turn my servo. I only want the servo to turn at the low freq, how can I program the BOE to do that?

    PS thankyou so much! I stayed up all night trying to figure this out.
  • dylantsdylants Posts: 13
    edited 2011-05-04 11:04
    I have an lm339, could you show me a circuit design that would work? Also I need to either use a transistor or programing to kill power to pin 14 as long as there is a high signal. I'm not really sure what transistor to use or how to make a program to do that.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-04 11:09
    First of all, you need to learn Stamp Basic. The "What's a Microcontroller?" tutorial is a good starting point. You should find it in PDF form in the Stamp Editor's help files.

    Your program starts with a GOSUB, followed by the subroutine itself. You never get in trouble with that because the subroutine never exits, so the lack of a matching RETURN doesn't affect anything.

    I see where your program puts the servo through a pattern of movements, one after another, then moves the servo through its range, first in one direction, then the other. Nowhere is there any test of an input. Your program does exactly what it's written to do. How did you plan to control the movement with the voltage input? We've made some suggestions. What do you want to do?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-04 11:13
    Why do you need to kill power to pin 14? Why do you need the transistor?

    Do a web search on "window comparator". One hit I found was this.
  • dylantsdylants Posts: 13
    edited 2011-05-04 11:24
    I need to kill power to pin 14 to stop the loop during a high input until there is a low input form an external circuit.
  • kwinnkwinn Posts: 8,697
    edited 2011-05-04 11:57
    Here is a diagram of a basic window comparator. The outputs could go to the input pins of a micro or to additional circuitry. The output level (high/low) can be reversed by reversing the signals on the +/- pins.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-04 11:58
    I really don't understand what you're trying to do. First of all, what do you mean by "pin 14"? Assuming you're using a BS2, there's I/O pin 14 which is physically pin #19 of the module. Physical pin #14 is I/O pin 9. Neither one is a power connection. If you mean for this to be an I/O pin, it could be connected directly to the LM339's output(s). You don't need a transistor between them. You need to read the sections of the "What's a Microcontroller?" tutorial on testing I/O pin states and on program decision making (IF / THEN statement). You might also read the parts of the "Basic Stamp Syntax and Reference Manual" on "BASIC Stamp Architecture - Memory Organization" since the I/O pins are mapped into memory locations.
  • dylantsdylants Posts: 13
    edited 2011-05-04 12:41
    Mike Green wrote: »
    I really don't understand what you're trying to do. First of all, what do you mean by "pin 14"? Assuming you're using a BS2, there's I/O pin 14 which is physically pin #19 of the module. Physical pin #14 is I/O pin 9. Neither one is a power connection. If you mean for this to be an I/O pin, it could be connected directly to the LM339's output(s). You don't need a transistor between them. You need to read the sections of the "What's a Microcontroller?" tutorial on testing I/O pin states and on program decision making (IF / THEN statement). You might also read the parts of the "Basic Stamp Syntax and Reference Manual" on "BASIC Stamp Architecture - Memory Organization" since the I/O pins are mapped into memory locations.

    I'm reading it right now. What I am trying to do is stop the loop from pulsing out while say for example pin 3 input is high. and return to pulsing when pin 3 input is low. I have been experimenting with "if then" statement to no avail.
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-05-04 12:46
    dylants wrote: »
    the signal is dc, I dont think a analog to dc converter will help. I only want the circuit on when there is a low of 1.3 and off at 1.5. I have tried to use an opamp to a comparator to a FET switch; It still wont turn off at the 1.5V.

    Now I am trying to program the input shut off at a high; the program turning the servo just starts over instead of stopping when it reads the high signal.

    As Mike G mentioned, an analog to digital converter ( A/D ) will work just fine and get rid of all the related window comparator components. An A/D converter inputs a voltage, 0-5V for example, and outputs a digital number corresponding to the voltage.... so FOR EXAMPLE, 0V might be a digital zero, while 5V might be a digital 65535.... your 1.3 and 1.5V would be somewhere in the middle.... maybe digital 500 and 600 respectively.... So you read the output of the A/D with your stamp, and toggle the servo as you see fit based on the A/D's output.

    You might be able to get satisfactory results with the RCTIME command and related circuit as well. Look in the Stamp manual for RCTIME. It's essentially a crude A/D.... sort of.
  • dylantsdylants Posts: 13
    edited 2011-05-04 13:00
    Spiral_72 wrote: »
    As Mike G mentioned, an analog to digital converter ( A/D ) will work just fine and get rid of all the related window comparator components. An A/D converter inputs a voltage, 0-5V for example, and outputs a digital number corresponding to the voltage.... so FOR EXAMPLE, 0V might be a digital zero, while 5V might be a digital 65535.... your 1.3 and 1.5V would be somewhere in the middle.... maybe digital 500 and 600 respectively.... So you read the output of the A/D with your stamp, and toggle the servo as you see fit based on the A/D's output.

    You might be able to get satisfactory results with the RCTIME command and related circuit as well. Look in the Stamp manual for RCTIME. It's essentially a crude A/D.... sort of.
    Wow, that looks good, I will try that.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-04 13:13
    I'm going to simplify things for the purpose of discussion. Your program looks sort of like this:
    ' Stuff that moves the servo around
    DO
       ' Stuff that moves the servo around
    LOOP
    
    There are all sorts of ways to make the loop quit when something happens. It depends on when you want things to stop. One way would be to
    ' stuff
    DO UNTIL <condition>
       'Stuff
    LOOP
    
    The <condition> is some kind of test that becomes true when the program should stop. It could be something as simple as "IN9 = 1".

    If you need finer control, you'd need to put IF / THEN statements all through your code, something like "IF <condition> THEN STOP". This would cause the program to stop. If you want something different to happen, you might want to do "IF <condition> THEN GOTO someLabel" where "someLabel" is defined elsewhere in your program.
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-05-04 13:44
    dylants wrote: »
    Wow, that looks good, I will try that.

    I dunno which you were referring to, but keep in mind, for RCTIME you may need an opamp, or use a different voltage level (If that's possible)... Refernce the manual regarding the 1.4V threshold.
  • dylantsdylants Posts: 13
    edited 2011-05-04 13:53
    Mike Green wrote: »
    ]
    The <condition> is some kind of test that becomes true when the program should stop. It could be something as simple as "IN9 = 1".

    If you need finer control, you'd need to put IF / THEN statements all through your code, something like "IF <condition> THEN STOP". This would cause the program to stop. .
    Hmm how do you make it start the loop again once the <condition> goes back to the previous state?

    Basically what I want the circuit to do is run the first part of the program once.
    then if input = 0 run the loop and if input = 1, stop loop until input = 0 again and then resume loop from where it left off until input reaches 1..... repeating forever.
  • Mike GMike G Posts: 2,702
    edited 2011-05-04 14:04
    Hmm how do you make it start the loop again once the <condition> goes back to the previous state?
    Well, you create a separate method (SUB) who's whole job is to move a servo given some parameters. Then you put values in the parameters and call the method. You should have run across an example in the suggested reading materials.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-04 14:45
    What you want is a subroutine that tests for a condition (like input = 0). This subroutine returns if the condition is true. If false, it waits until the condition becomes true again, then returns. You call this subroutine just before doing the PULSOUT in each of the FOR / NEXT loops in your DO / LOOP. Something like this:
    DO
       'FOR ...
          GOSUB testRoutine
          'PULSOUT ...
          'PAUSE ...
       'NEXT
    LOOP
    testRoutine:
       'Wait here if input is not zero
       IF input = 1 THEN GOTO testRoutine
       'Go back to main loop
       RETURN
    
  • dylantsdylants Posts: 13
    edited 2011-05-04 19:51
    awesome thank you both, Ill build this and program it and let u know how it goes thx allot:smile::thumb:!
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-05-05 20:52
    dylants,

    Do you need the hysteresis between 1.3V and 1.5V or would a single above or below a threshold of say 1.4V work?
  • dylantsdylants Posts: 13
    edited 2011-05-09 10:50
    Okay, thank you all for your help. I was able to get this circuit to work. I used a opamp and programming to get there. 1/2 of the opamp I used for a closed loop gain of about 3 and the other 1/2 as a comparator. I used pots to change the gain and ref voltage. when I get the high signal it shuts off the servo as planned.
  • dylantsdylants Posts: 13
    edited 2011-05-09 10:57
    Now how do I change this thread to solved???
  • PublisonPublison Posts: 12,366
    edited 2011-05-09 11:03
    I believe you can go to your first post and edit it there.
Sign In or Register to comment.