Shop OBEX P1 Docs P2 Docs Learn Events
FREQOUT question — Parallax Forums

FREQOUT question

dragoneyedragoneye Posts: 2
edited 2008-06-25 10:54 in BASIC Stamp
Hello ,
I'd appreciate help on syntax.
I'm trying to write a program to allow for different frequencies to be output from a pin depending on which input pin is "energized"
This is what I wrote;
' {$STAMP BS2}
' {$PBASIC 2.5}
DO
DEBUG HOME
DEBUG ? IN1
DEBUG ? IN2
DEBUG ? IN3
DEBUG ? IN4
DEBUG ? IN5
DEBUG ? IN6
DEBUG ? IN7
IF (IN1=1) THEN
FREQOUT 8,1000,1
ELSEIF (IN2=1)THEN
FREQOUT 8,1000,2
ELSEIF (IN3=1)THEN
FREQOUT 8,1000,4
ELSEIF(IN4=1)THEN
FREQOUT 8,1000,9
ELSEIF(IN5=1)THEN
FREQOUT 8,1000,18
ELSEIF(IN6=1)THEN
FREQOUT 8,1000,36
ELSEIF(IN7=1)THEN
FREQOUT 8,1000,73
ELSEIF(IN8=1)THEN
FREQOUT 8,1000,146
ENDIF
LOOP
DEBUG "Tone done."

It seems to "get stuck" at one frequency regardless of which I/O pin is at "1". Also there is an annoying "gap" each time it cycles.
My goal is to have a mulitple position switch that determines which I/O pin is powered at any given time and to have an LED light flashing at the frequency determined by the so chosen pin continuously until power is switched to another or turned off.
Thanks for any help.
Rich

Comments

  • AmaralAmaral Posts: 176
    edited 2008-06-25 02:55
    Try to run just the debug part and check if the input is stucked !
    after that , add the freqout part !

    just a sugestion

    Amaral
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-06-25 03:33
    Have you remembered to attach pulldown resistors to all your pins? A 10K resistor from each affected pin to ground will ensure that the pin reads as a zero when it's not being "powered". Otherwise, it will float, and there's no telling what it might read.

    As to the gap, that's just something you'll have to live with. Each statement in PBASIC comes with some overhead, which will cause silent intervals between the FREQOUTs.

    -Phil
  • dragoneyedragoneye Posts: 2
    edited 2008-06-25 10:54
    Thanks for the suggestions .I will try them out.
Sign In or Register to comment.