Shop OBEX P1 Docs P2 Docs Learn Events
Toggling or Remains at 3.3V — Parallax Forums

Toggling or Remains at 3.3V

TommmTommm Posts: 4
edited 2010-03-11 03:41 in BASIC Stamp
Is there A way to program the BS2, so it will sample A signal Pin to determine if the pin is toggling or remain at 3.3v? For example, once the I/O changes state (low/high); you can wait for 4 seconds and sample the I/O pin again; if it's HIGH. Then Run this program
(High 14 pause 100 Low 14 pause 100). If its toggling run this program (High 15 pause 1000 low 15 pause 1000).


Tommm

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-03-06 22:06
    You've got the right idea. An I/O pin at 3.3V will appear to be high. An I/O pin close to 0V (typically anything less than 2.5V) will appear to be low. If the toggling is slow enough (100's of times a second), you can easily sample it and distinguish steady state from toggling the way you described.
  • TommmTommm Posts: 4
    edited 2010-03-07 18:03
    How would I go about making A program to sample the pin? If I was to use A 555timer to make A (100's of times a second), would the BS2 read, if the I/O pin was High at (100's of times a second) go run this Program (High 14 pause 100 Low 14 pause 100). If it was toggling for 1sec. at (100's of times a second) Run this Program (High 15 pause 1000 low 15 pause 1000).


    Tommm
  • Mike GreenMike Green Posts: 23,101
    edited 2010-03-07 19:02
    You need to go through the "What's a Microcontroller?" tutorial and the "BASIC Stamp Syntax and Reference Manual" to learn basic concepts. Do you know that the I/O pins are sensed and are always available as the bits in a 16-bit variable called INS? There are special names for parts of this variable that are described in the Reference Manual. For example, I/O pin 5 is referenced as a 1-bit variable IN5.

    www.parallax.com/tabid/535/Default.aspx
    www.parallax.com/tabid/440/Default.aspx
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-03-07 20:05
    You could use the COUNT command to advantage. If the pin is toggling, the count will be greater than zero, otherwise zero.

    signal pin 0
    result VAR Word
    DO:LOOP UNTIL signal   ' wait for high
    PAUSE 4000   ' wait 4 seconds
    COUNT signal,100,result    ' check if toggling
    ' counts for 0.1 second and returns a value of about 10 if the input is toggling, zero if not, and an intermediate value if by chance the toggling starts or stops in the middle of the 0.1 second interval.
    IF result THEN
      ...
    ELSE 
      ...
    ENDIF
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • TommmTommm Posts: 4
    edited 2010-03-11 03:41
    Thank you people for helping me.
Sign In or Register to comment.