Shop OBEX P1 Docs P2 Docs Learn Events
2400hz? — Parallax Forums

2400hz?

PaulPaul Posts: 263
edited 2009-06-05 21:11 in BASIC Stamp
I would like to output a 2400.0 Hz signal on an output pin of a BS2. The best I can get is 2011.96 HZ using the simple program as follows:
OUTPUT 8
J60:
    PULSOUT 8,1
    GOTO J60


Yes, a 555 timer is cheaper but I need to switch between 300, 360 and 2400 HZ and RC circuits are temperature sensitive. A faster BS2P is too expensive. A 50-50 duty cycle is not required. I've tried FOR/NEXT and DO/LOOP but nothing seems to loop faster. Any ideas (or undocumented code? nono.gif ) Thanks, Paul

Comments

  • achilles03achilles03 Posts: 247
    edited 2005-02-02 17:05
    Does it need to be PWM? If not, and you just need a frequency, use the freqout command. It's not a perfect sine wave by any means, but it's good enough that you can hear the frequency fine.

    If it DOES need to be PWM, one option is that you can use a 555 with an adjustable resistor (digital pot). Have your BS2p sample the 555's output (see the COUNT command) and make adjustments to the digital pot until you're at the right frequency. This would also compensate for temperature. You could even get 2 digital pots in series: one for course, large steps, and another for fine tuning. I think the BS2p's oscillator is very stable over it's operating temp range, so the COUNT command should be accurate over a wide temp range also.

    Another option is that maybe you could use the freqout command to a 555 in monostable mode to trigger when a threshold is reached. (I think you can do that, right?) Maybe use double the frequency and only trigger on the Vmax portion of the wav.

    Hope that helps,
    Dave
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-02-02 17:19
    It's going to be difficult to get dead on using PBASIC. Part of what you're seeing is the instruction load/decode delay -- remember, every PBASIC instruction must be retrieved from EEPROM and decoded; this takes a bit of time.

    If you need dead-on accuracy then you may want to invest in an SX kit -- with SX/B you can compile BASIC and could, if you like, use an ISR to toggle an output in the background while your foreground program handles frequency selection.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2005-02-02 17:38
    You could also play around with other ways to "skin a cat"

    This "might" run a little faster.


    OUTPUT 8
    LOW 8
    J60: 'Caution Endless loop!!!
    TOGGLE 8
    GOTO J60


    ...or....


    OUTPUT 8
    LOW 8
    FOR Cycles=1 to NCycles ' A FOR/NEXT provides some means for escape
    TOGGLE 8
    NEXT
    LOW 8




    Another method might be a clever use of SEROUT with ASCII characters of 85 or 170

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe - Mask Designer III

    National Semiconductor Corporation
    (Communication Interface Division)
    500 Pinnacle Court, Suite 525
    Mail Stop GA1
    Norcross,GA 30071
  • PaulPaul Posts: 263
    edited 2005-02-02 17:57
    The BS2 seems to be very temperature stable. Very little drift when heating it momentarily with a heat gun.
    Dave: The digital pot controlling the 555 seems intriguing.
    Jon: I don't know anything about the SX/b so maybe now is a good time to look into it!
    Beau: Yes, I've tried the 'toggle' method but as Jon pointed out the BS2 is limited by the time it takes to read and execute the GOTO. This looks to be about 0.5 Mseconds. (a.k.a 2000Hz) And this is the same for any LOOP function.
    Thanks for the advice.

    Paul
  • achilles03achilles03 Posts: 247
    edited 2005-02-02 20:33
    I'm already doing something like that... putting together a ghetto-style radio modem using the 555 and a SPI controlled digital pot to communicate with RTTY, AMTOR, etc. I need it to be capable of compensating for temperature to work at high altitudes (very cold). I'm waiting for the digital pots to get in, but I'll let you know how it goes.

    Dave
  • achilles03achilles03 Posts: 247
    edited 2005-02-03 13:48
    Paul,

    Check out these digital pots:

    MCP41010
    MCP41100

    They're SPI interface at 10k and 100k respectively. $1.27 each at Mouser. 256 taps, or about 39/391 ohms per increment. Put them in parallel with another fixed-value resistor between pins 7 and 6/2 of your 555, and you can cut the increment much lower if you need more precise tuning.

    Dave
  • PaulPaul Posts: 263
    edited 2005-02-03 20:43
    Thanks Dave. I'll look into them. I have a DS2890 (from the Parallax Plus Pack) I can look at.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-06-05 21:11
    Maybe have the BS2 output 1200 Hz, and follow that up with a frequency doubler. The frequency doubler can be XOR gate, two inputs, with one input direct from the Stamp pin, and the other through an RC circuit with a time constant of a few microseconds.

    J60:
    PULSOUT 8,168 ' about 1200 Hz for loop, 336 us pulse per loop.
    GOTO J60

    Trouble is, there is no exit. The FOR:NEXT construct is slow, with a minimum time of around 825 microseconds per iteration. The minimum time to interpret an IF: THEN label is around 360 microseconds, the same as it would be to evaluate a WHILE in a DO:LOOP WHILE. Too slow.

    Achilles03 had the good suggestion for PBASIC only
    FREQOUT 8,duration,2400
    which would be just fine I think if you can run the frequency output into an RC or LC lowpass filter and then through a comparator. The comparator could be as simple as the threshold of a logic gate or mosfet, maybe with a little hysteresis. That would allow an squarish wave output at your desired frequencies, and controlled durations in units of one millisecond up to 65 seconds.

    Edit: Oops. Sorry. rolleyes.gif I didn't look at the date on this thread and I don't know how it happened to be open in my browers. Old threads never die.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 6/6/2009 12:06:06 AM GMT
Sign In or Register to comment.