Shop Learn
Piezo in P-Basic — Parallax Forums

Piezo in P-Basic

flyers2000flyers2000 Posts: 1
edited 2021-09-19 12:21 in BASIC Stamp

New at this. I understand the FREQOUT command.
FREQOUT 4, 2000, 3000
Is there a way to turn on the Piezo at a certain frequency and leave it on until a off command is executed?
Thanks

Comments

  • JonnyMacJonnyMac Posts: 7,741
    edited 2021-09-19 21:52

    No. The BASIC Stamp can only do one thing at a time. Since its processor does not use hardware to create the FREQOUT signal (it's done in firmware), there is no way to turn it on and leave it on. This where the Propeller shines; with 8 cores, one can do lots of things at the same time with no fuss.

  • ". . . with 8 cores" and 16 counters that can output tones autonomously! :)

    -Phil

  • I may have put off learning the Propeller for too long. Now that I've retired, there's a whole sea of Propeller stuff to learn about, and now the Propeller 2 has landed! So I can avoid learning a new language (Spin or Spin2), can't somebody please just port PBASIC to the Propeller? :wink:

  • msrobotsmsrobots Posts: 3,468

    FlexProp from @ersmith has a wonderful Basic able to compile for P1 and P2.

    Give that a whirl...

    Mike

  • GenetixGenetix Posts: 1,547

    JBKerner,

    I started with the BS2 and found Spin too intimidating at first but I found it to be about 80% the same.

    I learned Spin from the Propeller Education Kit Textbook, but it doesn't explain much on using CONstants.
    https://www.parallax.com/package/propeller-education-kit-fundamentals-text-and-code/

    I created myself a file for converting PBASIC statements to Spin that you may find handy.
    There is no Spin equivalent for a BS2-specific command like FREQOUT, but making sound on the Propeller is easy since it has counters.
    Page 143 of the Propeller Education Kit (PEK) text explains how to make Tones on the Propeller using a Counter.

  • @JBKerner Ditto what Mike said. If you liked PBASIC, you’re going to love FlexBASIC. Best of all you can intermix BASIC, C, PASM and Spin and it all compiles down to assembly. Wickedly fast too.

  • @JRoark said:
    @JBKerner Ditto what Mike said. If you liked PBASIC, you’re going to love FlexBASIC. Best of all you can intermix BASIC, C, PASM and Spin and it all compiles down to assembly. Wickedly fast too.

    @JRoark said:
    @JBKerner Ditto what Mike said. If you liked PBASIC, you’re going to love FlexBASIC. Best of all you can intermix BASIC, C, PASM and Spin and it all compiles down to assembly. Wickedly fast too.

    Why the heck would I want to mix C in with anything, unless I wanted to ruin it! :wink: My first exposure to that gawdawful language was circa 1983 (before ANSI decided they had nothing better to do), and judging by a few Arduino programs I've studied, it hasn't improved a whole lot! It's almost as bad as PASCAL or COBOL! I have two goto languages (no pun intended): BASIC or assembly (or machine-language, if I want to beat my head against a wall!)

    Thanks JRoark, I'll look into FlexBASIC.

  • @Genetix said:
    JBKerner,

    I started with the BS2 and found Spin too intimidating at first but I found it to be about 80% the same.

    I learned Spin from the Propeller Education Kit Textbook, but it doesn't explain much on using CONstants.
    https://www.parallax.com/package/propeller-education-kit-fundamentals-text-and-code/

    I created myself a file for converting PBASIC statements to Spin that you may find handy.
    There is no Spin equivalent for a BS2-specific command like FREQOUT, but making sound on the Propeller is easy since it has counters.
    Page 143 of the Propeller Education Kit (PEK) text explains how to make Tones on the Propeller using a Counter.

    Thanks! I might try SPIN again.

  • @msrobots said:
    FlexProp from @ersmith has a wonderful Basic able to compile for P1 and P2.

    Give that a whirl...

    Mike

    Thanks Mike! I'll look at FlexProp.

  • @JRoark said:
    Here ya go: https://github.com/totalspectrum/flexprop

    Awesome! I'll investigate this further, when I have more time. Thanks JRoark!

  • @JRoark said:
    Here ya go: https://github.com/totalspectrum/flexprop

    I downloaded the .zip file, and I've been reading over the manual before installing. It seems very VBA-like, which I appreciate! Neither the manual, nor the ProBASIC Syntax Guide define the sizes of variable types. Can I assume that a Byte is 8-bit (pretty universal), a Word is 16-bits, and a Long is 32-bits? No Bit-sized variables? Now that I think about it, you can't define a variable as a bit in VBA, either. I typically use bit-varaibles in PicBASIC PRO and the Basic Stamp as flags, to signal that something has been done previously. I don't see a problem, really, with using a byte, instead; it's still going to be a zero or a one, it's just a tad more memory. The Basic Stamp teaches you to be frugal with memory!

  • ersmithersmith Posts: 5,060

    @JBKerner said:

    @JRoark said:
    Here ya go: https://github.com/totalspectrum/flexprop

    I downloaded the .zip file, and I've been reading over the manual before installing. It seems very VBA-like, which I appreciate! Neither the manual, nor the ProBASIC Syntax Guide define the sizes of variable types.

    There's a section titled "Data Types" in basic.pdf (it starts on page 16 of the manual). Is that missing in the version you downloaded?

    The summary is "ubyte, ushort, uinteger" for 8, 16, 32 bit unsigned integers, an "byte, short, integer" for 8, 16, 32 bit signed integers. On the propeller anything shorter than 32 bits is best addressed as unsigned, so "ubyte" and "ushort" are the preferred forms. There are also floating point, pointer and string types, and a generic 32 bit type "any" that can hold anything at all.

    No, there aren't any bit sized variables. I could probably add those to classes (re-using the mechanism for bit fields in C structures). And of course you can use CONST definitions and explicitly set/test bits within another variable.

  • GenetixGenetix Posts: 1,547

    JBKerner,

    I should have mentioned the Propeller Manual which is the go to Bible for Spin and if you dare Assembly.
    https://www.parallax.com/package/p8x32a-propeller-datasheet/
    https://www.parallax.com/package/propeller-manual/

    I learned Spin using the old 1.3.2 version of Propeller Tool, which is the 1st file in the list
    https://web.archive.org/web/20200805080701/https://www.parallax.com/downloads/propeller-tool-software-windows-spin-assembly

  • JonnyMacJonnyMac Posts: 7,741
    edited 2021-10-09 19:56

    There is no Spin equivalent for a BS2-specific command like FREQOUT, but making sound on the Propeller is easy since it has counters.

    The Spin1 interpreter is very small so Spin1 doesn't have a lot of the niceties we enjoyed in the BASIC Stamp (the P2 instructions/interpreter are different and many of those things come back). I have a standard template that includes an object called jm_io.spin that I use in most projects. Many of these methods will seem familiar. I've attached an archive of my P1 template in case you find it useful.

    If you decide you want to use this template and compile with FlexProp, set the terminal type in the application to T_ANSI. This is what's included in the template:

    The jm_time_80.spin object handles things like PAUSE; another Stamp feature we're quit used do. Most projects run at 80MHz and this object is set for that. You can copy, rename, and modify for different clock frequencies (I have one for 100MHz that gets used in a couple of products).

Sign In or Register to comment.