Advice needed. FOR...NEXT loop


Closed Thread
Results 1 to 9 of 9
  1. #1
    atomski's Avatar
    atomski Guest

    Default Advice needed. FOR...NEXT loop

    Hello all,

    PROBLEM
    ********
    I'm trying to send 10 consecutive tones using FREQOUT command. Here's my code:

    Tone1 VAR Word
    ...
    Tone 10 VAR Word
    Loop:
    FREQOUT Pin, Period, Tone1
    FREQOUT Pin, Period, Tone2
    FREQOUT Pin, Period, Tone3
    FREQOUT Pin, Period, Tone4
    FREQOUT Pin, Period, Tone5
    FREQOUT Pin, Period, Tone6
    FREQOUT Pin, Period, Tone7
    FREQOUT Pin, Period, Tone8
    FREQOUT Pin, Period, Tone9
    FREQOUT Pin, Period, Tone10
    PAUSE 1000
    GOTO Loop

    QUESTION
    *********
    Can I use a FOR...NEXT loop in order to use just one FREQOUT statement instead of ten? For example:

    Loop:
    FOR i = 1 TO 10
    Tone = Tone(i)
    FREQOUT Pin, Period, Tone
    NEXT i
    i = 0
    PAUSE 1000
    GOTO Loop

    PS When I try to compile this I get an error. Can anyone give me a clue as to how I might go about solving this problem? Thank you in advance.

    --
    Sincerest regards,

    YZ7REA Vladimir M SKrbic
    4N7ATV Repeater Administrator
    YU7GHZ Radio Club President

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Tone var Byte [11]

    Note: Tone is now an Array, but since the first element of the array is Tone[0], Tone[10] is actually the eleventh element, which is why I've defined eleven elements above.

    Loop:
    FOR i = 1 TO 10
    FREQOUT Pin, Period, Tone[i]
    NEXT i

    Naturally you will have to preset the array values of Tone before you run the subroutine...

    ...or if you have lots of tunes to play try presetting them in EEPROM...

    Loop:
    For i = 1 to 10
    Read i,tone
    FREQOUT Pin, Period, Tone
    NEXT i

    Melanie

  3. #3
    atomski's Avatar
    atomski Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Mel,

    I knew I was on the right track, however I just couldn't figure it out but once again Mel comes to the rescue!

    Vlad

  4. #4
    atomski's Avatar
    atomski Guest


    Did you find this post helpful? Yes | No

    Default

    Mel, I have another question for you regarding this problem.
    I've done what you've suggested as shown below:

    Tone var Byte[11]

    Loop:
    FOR i = 1 TO 10
    FREQOUT Pin, Period, Tone[i]
    NEXT i

    However I have 10 4-digit dec numbers that the PC program
    is sending out via rs-232 as ASCII characters in hex format
    as shown below:
    for 1234 it sends $04, $D2
    or
    for 5678 it sends $16, $2E

    So, my numbers are WORD sized. Can my Tone array hold
    10 word sized velues?

    How can I get them by using HSERIN command? Perhaps
    like this:

    HSERIN [STR Tone\11]

    Also, how can I store these 10 values (the Tone array) into
    the on-board eeprom and read them back from eeprom to
    memory at power-up?

    --
    Sincerest regards,

    YZ7REA Vladimir M SKrbic
    4N7ATV Repeater Administrator
    YU7GHZ Radio Club President
    Last edited by atomski; - 24th June 2004 at 18:26.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Uggghhh... so perhaps you want me to write your whole program for you?

    > So, my numbers are WORD sized. Can my Tone array hold 10 word sized velues?

    Sure... try this...

    Tone var WORD [11]

    and suddenly like by magic they can hold values bigger than 8 bits.

    > How can I get them by using HSERIN command?

    I'm going to be cruel to be kind... do an experiment and display the result on an LCD or PC to see what happens. Since I don't know the format of the data being captured by HSERIN, I can't answer that anyway.

    > Also, how can I store these 10 values (the Tone array) into the on-board eeprom and read them back from eeprom to memory at power-up?

    Go back over answers I've posted (or Messaged) in the past to you over Reading and Writing from/to EEPROM. BYTE at a time, and use Highbyte/Lowbyte to re-assemble Words. I do vaguely recall exchanging on this topic about two/three months ago.

    Melanie

  6. #6
    atomski's Avatar
    atomski Guest


    Did you find this post helpful? Yes | No

    Default

    Mel, please don't get upset if I ask for advice. The whole
    trick about successful programming is in grasping the concept
    of "how the stuff works". When I ask for advice, I ask for an
    idea and want to understand how something works. When I
    post a code snippet and say I'm not sure if it's ok, I really
    need help. But if I come and say I need someone to write or
    give me the whole code, that's another thing. I'm not trying
    to argue with you here, it's just that the very idea of
    someone even thinking I'm a lazy butt who wants someone
    else to do all his work for him makes me feel bad. I spend
    countless hours programming, learning in the process,
    building stuff that works and doesn't work sometimes. If
    that's the case it's "back to the drawing board" for me. When
    I'm stuck I ask people for advice, cuz like you I also love
    helping people out whenever I can. You've helped me and
    many others in the past and your help proved to be
    invaluable, so I thank you for that. Please accept my apology
    if I made you upset.

    Vlad

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Far from being upset, that was posted with good humour... I must try to moderate it, perhaps it didnt come across in the spirit it was intended - for which I appologise. Saying that, I'm trying not to repeat answers I've already given you in the past.

  8. #8
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Also check this thread from July 2003...

    FYI - How to Access individual bytes in Word Arrays

    looks like a contender for the new FAQ category...

  9. #9
    atomski's Avatar
    atomski Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Mel, hey no prb about yr remarks. I'll be a good
    boy and try to behave in the future

    BTW I would have probably gotten the joke if there was a
    smiley attached at the end. Sorry, may bad

    Vlad

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 16:48
  2. Serin to Serin2 ??
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 03:56
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. Advice needed on 'neat' Project!
    By vacpress in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th February 2007, 06:21
  5. Newbie question:
    By Izone in forum mel PIC BASIC
    Replies: 2
    Last Post: - 26th February 2006, 16:24

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts