Shop OBEX P1 Docs P2 Docs Learn Events
POT example with BS2 — Parallax Forums

POT example with BS2

carguycarguy Posts: 3
edited 2006-09-22 01:18 in BASIC Stamp
I am looking for an example on how to read the value of a pot with BS2. The POT function only exists under BS1 according to the Help.·I tried to run the POT.bas example under the BS1 folder, but I could not make that work. I got a message stating no BS1 module connected to my computer. I have the BASIC Stamp Homework board.

My goal is to use one (or multiple) pots to affect the output of a square wave. If the pot had a scale of 0 to 100, then I was hoping to do something like:

POT 0, 100, level

time = 100 - level

HIGH 14
PAUSE time
LOW 14



Just looking for some examples or input. Thanks.

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-09-19 04:38
    You need to use RCTime, with a pot + capacitor in parallel to ground from an I/O, such as P2
    You can size the capacitor to get the range of values you prefer.

    value var word

    DO
    HIGH 2
    Pause 10
    RCTime 2,1,Value
    debug ? value
    Loop

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
    AppBee - XBee ZigBee / IEEE 802.15.4 Adapters & Devices
  • carguycarguy Posts: 3
    edited 2006-09-21 14:56
    Ok, so I built a couple of circuits and tried a couple of things. Perhaps this is not what I need.

    I want to build a circuit in which I can turn a knob/dial to increase/decrease the rate at which a square wave is generated somewhere else in the circuit. For example, assume the knob/dial has a scale of 1,000 to 10,000. I was hoping to do something like
    Scale = knob/dial value

    IF Scale < 5,000

    · Square_Wave =· 50% Duty Cycle

    ELSE

    · Square_Wave =·80% Duty·Cycle

    ENDIF

    In this example, I want Scale to represent RPM. So,

    Convert RPM to Cycles Per Minute (need two revolutions for 1 cycle in a four stroke engine)

    CPM = RPM / 2

    Calculate Cycles per Second

    CPS = CPM / 60

    Calculate time for one cycle in mS

    Cycle = 1000 / CPS······· '·1 second·/ CPS * 1000


    What kind of input device can I use to allow changing the Scale; thus, altering the square wave output. I am also a little confused on how to make the code work, but that maybe related to figuring out what hardware to incorporate and interrupt its value.

    Thanks.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-09-21 15:28
    One thing to keep in mind is that the Stamp can do only one thing at a time. It can read the setting of a variable resistor using the RCTIME statement or it can generate a pulse train at a particular frequency, but not both at the same time. It is possible to overlap two things with careful attention to timing if they happen slowly (on the order of 10's of ms or slower)

    Step 1 is to become comfortable with reading the value of a variable resistor using the RCTIME statement. Read the section in the PBasic Manual on the RCTIME statement and try the examples to see how it behaves. Plot out the values you get from the RCTIME compared to the rotation of the variable resistor and decide how you want to assign cycle time or frequency values to the RCTIME values (best to create an equation that fits the relationship).

    Step 2 is to generate pulse trains using the PULSOUT or HIGH/LOW and PAUSE statements. The PAUSE statement has a resolution of only 1ms, so sometimes you can use two PULSOUT statements, one to the pin you want to use, the other to an unused pin (just to provide a time delay) for the "off time".

    Step 3 is to combine these so the position of the resistor gets read from time to time (maybe once a second or so) and used to set the time delays for the pulse train. This would cause an interruption in the pulse train which may or may not be acceptable. If this interruption is not acceptable, you would need to use some kind of external circuitry to generate this with the Stamp controlling the external generator.
  • carguycarguy Posts: 3
    edited 2006-09-22 00:21
    Mike Green said...
    One thing to keep in mind is that the Stamp can do only one thing at a time. It can read the setting of a variable resistor using the RCTIME statement or it can generate a pulse train at a particular frequency, but not both at the same time. It is possible to overlap two things with careful attention to timing if they happen slowly (on the order of 10's of ms or slower)

    Step 1 is to become comfortable with reading the value of a variable resistor using the RCTIME statement. Read the section in the PBasic Manual on the RCTIME statement and try the examples to see how it behaves. Plot out the values you get from the RCTIME compared to the rotation of the variable resistor and decide how you want to assign cycle time or frequency values to the RCTIME values (best to create an equation that fits the relationship).

    Step 2 is to generate pulse trains using the PULSOUT or HIGH/LOW and PAUSE statements. The PAUSE statement has a resolution of only 1ms, so sometimes you can use two PULSOUT statements, one to the pin you want to use, the other to an unused pin (just to provide a time delay) for the "off time".

    Step 3 is to combine these so the position of the resistor gets read from time to time (maybe once a second or so) and used to set the time delays for the pulse train. This would cause an interruption in the pulse train which may or may not be acceptable. If this interruption is not acceptable, you would need to use some kind of external circuitry to generate this with the Stamp controlling the external generator.
    Thanks for the feedback. I did play around for quite a while last night. I think I am fairly ok with Step 1. Regarding Step 2 and 3, I never could get the wave to look the way it should. Even when removing all the pause statements, there seemed to me to be too long of an interval between waves. Instead of a 50% duty cycle, it was more like 33%. The code looked something like this:

    HIGH 7 'Discharge the cap 
    
    PAUSE 10
    RCTIME 7, 1, Result 'Measure RC charge time. 
    
    RPM = Result * 100 
    CPM = RPM / 2 
    CPS = CPM / 60 
    Cycle = (1000 / CPS) 
    DC = Cycle / 2 
    HIGH 14 
    PAUSE DC 
    LOW 14
    

    I tried different capacitors and different lengths of PAUSE. Perhaps I just never got the right combination. I would have thought with the code above, the waves however long would have been relatively compressed together (close together), but that did not seem to be the case. I could have done something wrong though. Any advice?

    My ultimate goal is to build a little black box with multiple variables that a user can change which alter a square wave output. The box would have an easy place to connect a scope to view the affects on the square wave. The wave represents injector pulse width. The variable inputs would be:

    RPM 1,000 - 10,000
    Intake Air Temperatue 0 - 50* C
    Manifold Pressure 20 - 300 kPa

    It would be nice to be able to display the values of each variable as well as provide smooth transition/resolution throughout the given scale. Any thoughts on getting to this ultimate goal or how much something like this would cost to build. It doesn't sound like the BS2 will do this.

    Thanks.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-09-22 01:18
    It sounds like you want to use something like the SX or Propeller which can do several things simultaneously. The SX is the cheapest ($10 for a prototype board + SX Key). The SX/B compiler lets you write stuff in basic and the SX can digitize several analog signals at the same time and use those for timing a square wave. I'm soft on the Propeller since it can do lots of stuff all at the same time. A big advantage is that it can also generate its own video for displaying your variable inputs and any intermediate calculations you want. You could use a mouse for the input parameters although I don't think anyone has made a slider control yet that uses the mouse. It shouldn't be hard. That way you wouldn't need the pots at all. If you already have a spare PS/2 keyboard and mouse and a tv with a video input, you could get started for $130-$150 depending on whether you want a paper manual.
Sign In or Register to comment.