Shop OBEX P1 Docs P2 Docs Learn Events
Question on FREQOUT — Parallax Forums

Question on FREQOUT

Don JDon J Posts: 12
edited 2006-11-14 05:35 in BASIC Stamp
Hello,
Looking for information on how to shorten this?
I'm writing a program for an Amateur Repeater and this is the ID portion.
It is taking up major space.
I have a BS2 and am still pretty new to this.
Don't need anyone to write the code, just need to be pointed in the
general direction to find the answer or possibly an explanation on
how to shorten this.

Thanks for the help!
Don J


CWID:
PAUSE 50
GOSUB DAH
GOSUB DIT
GOSUB DAH
GOSUB SPACE
GOSUB DIT
GOSUB DIT
GOSUB SPACE
GOSUB DAH
GOSUB DAH
GOSUB DAH
GOSUB DAH
GOSUB DAH
GOSUB SPACE
GOSUB DIT
GOSUB SPACE
GOSUB DAH
GOSUB DAH
GOSUB DAH
GOSUB SPACE
GOSUB DAH
GOSUB DIT
GOSUB DIT
GOSUB DAH
GOSUB DIT
GOSUB SPACE
GOSUB DIT
GOSUB DAH
GOSUB DIT
RETURN

DAH:
FREQOUT 7, 216, 1100
FREQOUT 7, 72, 0
RETURN


DIT:
FREQOUT 7, 72, 1100
FREQOUT 7, 72, 0
RETURN


SPACE:
FREQOUT 7, 144, 0
RETURN

Comments

  • latigerlillylatigerlilly Posts: 114
    edited 2006-11-13 08:09
    For counter = 1 to 5
    gosub dah
    next

    gosub rep1
    gosub rep2

    rep1:
    Gosub dit
    gosub dah
    gosub dit
    return

    rep2:
    Gosub space
    gosub dit
    return
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-11-13 10:51
    Folks -

    Nice try, but there is a REAL problem waiting in that code. See below:

    FOR COUNTER = 1 TO 5
    GOSUB DAH
    NEXT

    GOSUB REP1
    GOSUB REP2
    <
    Once you drop through here, the program will start to go off the rails!
    REP1:
    GOSUB DIT
    GOSUB DAH
    GOSUB DIT
    RETURN

    REP2:
    GOSUB SPACE
    GOSUB DIT
    RETURN

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-11-13 14:09
    Yup, that's a hole both in the original AND the simplified version.

    So, if you want to do it ONCE, put an "END" there.

    If you want to do it continuously, put:
    MAIN:
    FOR COUNTER = 1 TO 5
    GOSUB DAY
    NEXT
    GOSUB REP1
    GOSUB REP2
    PAUSE 500 ' Pause 1/2 second to 'separate' the messages
    GOTO MAIN

    Then it will repeat forever, with 1/2 second between messages.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-11-13 17:25
    Consider a general purpose routine that encodes the dit-dah patterns in bytes that can be stored as CONstants or in a DATA lookup table and played back. Something like this:

    seven  CON  10111000    ' five elements   dah dah dit dit dit
    letter_n CON 01000010    ' two elements dah dit
    



    where the 3 msb are the number of elements to send, and the 5 lsb are the pattern. It is possible to include six element punctuation in this scheme by treatment of 110 and 111 as both calling out 6 elements.

    You need one subroutine that is called with a variable containing the pattern to play back, or a pointer to that pattern. It takes a little to set it up, but I think you will find the end result much more versatile and easier to follow.

    There is an example of this in the Applied Sensors text, to sound out sensor readings in Morse code. There are other examples around too, maybe in the archives of this forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Don JDon J Posts: 12
    edited 2006-11-13 19:34
    Thanks everyone for your input!
    Tracy, I've read about the DATA lookup table, but don't
    seem to understand it quite yet.
    That is the route I'm looking for and will investigate it further.

    I do have the CWID working now and have compacted it somewhat,
    but it still looks somewhat "bulky".

    I have the "What's a Microcontroller" and "Stamp 2 Communications and Control projects" books
    and have picked up a lot of info from there.
    There is a repeater controller project in the communications book and so far I have learned
    alot just reading through the code on that project, but my primary goal
    is to write my own program.

    Thanks,
    Don J
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2006-11-14 04:24
    Oh Jeez let me take a stab at it.


    result·VAR BYTE
    idx VAR BYTE

    'Main loop goes here

    'subroutines
    CWID:
    PAUSE 50
    FOR idx= 0 to 27
    ·· LOOKUP idx, [noparse][[/noparse] 0, 1, 0, 2, 1, 1, 2, 0, 0, 0, 0, 0, 2, 1, 2, 0, 0, 0, 2, 0, 1, 1, 0, 1, 2, 1, 0, 1], result
    ·· ON result GOSUB DAH, DIT, SPACE
    NEXT
    RETURN

    DAH:
    FREQOUT 7, 216, 1100
    FREQOUT 7, 72, 0
    RETURN

    DIT:
    FREQOUT 7, 72, 1100
    FREQOUT 7, 72, 0
    RETURN

    SPACE:
    FREQOUT 7, 144, 0
    RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-11-14 05:35
    A data lookup table is not too hard. For example, the Intrnl Morse code patterns for the letters A to Z:

    mrs_A  DATA %01000001    ' three msb for the number of elements, 5 lsb for the pattern, 1=dah 0=dit
    mrs_B DATA %10001000
    mrs_C DATA  %1001010
    mrs_D DATA %01100100
    mrs_E DATA %00100000
    mrs_F DATA %10000010
      and so on to
    mrs_Z DATA %10001100
    



    Suppose you have a string you want to send:
    cars DATA "CALLING ALL CARS",0 ' null terminates string

    A program to send that string would include statements like this:
       pointer = cars
       DO
         READ pointer,char   ' retrieve a character from the string
         SELECT char     ' decide based on the character
         CASE 0
             EXIT   ' done with string, null
        CASE 32  ' space
            ' send a Morse word space
         CASE char>64 AND char <91  ' A to Z inclusive
             READ char - "A" + mrs_A, pattern   ' retrieve the pattern for the letter postion in the table
             GOSUB playMorse   ' send the pattern + letter space
          ENDSELECT
         pointer = pointer + 1  ' point to next char in string
      LOOP
    



    You see, there are really two tables, one with the string you want to send with the pointer to entries at cars, cars+1, cars+2 etc. until it finishes when it hits the null entry. Then if the entry happens to be a letter from A to Z, it looks up the Morse pattern in the table that starts with mrs_A, and passes the byte pattern it finds there to the subroutine that plays it in code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.